1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 23:52:26 +00:00
CLK/Machines/Atari/2600/TIASound.hpp

50 lines
1.3 KiB
C++
Raw Normal View History

//
// TIASound.hpp
// Clock Signal
//
// Created by Thomas Harte on 03/12/2016.
// Copyright 2016 Thomas Harte. All rights reserved.
//
#pragma once
#include "../../../Outputs/Speaker/Implementation/SampleSource.hpp"
#include "../../../Concurrency/AsyncTaskQueue.hpp"
namespace Atari2600 {
// This should be a divisor of 38; audio counters are updated every 38 cycles, though lesser dividers
// will give greater resolution to changes in audio state. 1, 2 and 19 are the only divisors of 38.
constexpr int CPUTicksPerAudioTick = 2;
2017-04-04 01:16:39 +00:00
2024-02-02 02:47:44 +00:00
class TIASound: public Outputs::Speaker::SampleSource<TIASound> {
public:
2022-07-16 18:41:04 +00:00
TIASound(Concurrency::AsyncTaskQueue<false> &audio_queue);
void set_volume(int channel, uint8_t volume);
void set_divider(int channel, uint8_t divider);
void set_control(int channel, uint8_t control);
// To satisfy ::SampleSource.
void get_samples(std::size_t number_of_samples, int16_t *target);
void set_sample_volume_range(std::int16_t range);
2024-02-02 02:29:00 +00:00
static constexpr bool is_stereo = false;
private:
2022-07-16 18:41:04 +00:00
Concurrency::AsyncTaskQueue<false> &audio_queue_;
uint8_t volume_[2];
uint8_t divider_[2];
uint8_t control_[2];
int poly4_counter_[2];
int poly5_counter_[2];
int poly9_counter_[2];
int output_state_[2];
int divider_counter_[2];
int16_t per_channel_volume_ = 0;
};
}