2016-12-03 18:39:46 +00:00
|
|
|
//
|
2017-12-18 02:26:06 +00:00
|
|
|
// TIASound.hpp
|
2016-12-03 18:39:46 +00:00
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 03/12/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-12-03 18:39:46 +00:00
|
|
|
//
|
|
|
|
|
2017-12-18 02:26:06 +00:00
|
|
|
#ifndef Atari2600_TIASound_hpp
|
|
|
|
#define Atari2600_TIASound_hpp
|
2016-12-03 18:39:46 +00:00
|
|
|
|
2019-11-09 20:31:41 +00:00
|
|
|
#include "../../../Outputs/Speaker/Implementation/SampleSource.hpp"
|
|
|
|
#include "../../../Concurrency/AsyncTaskQueue.hpp"
|
2016-12-03 18:39:46 +00:00
|
|
|
|
|
|
|
namespace Atari2600 {
|
|
|
|
|
2018-05-13 19:34:31 +00:00
|
|
|
// This should be a divisor of 38; audio counters are updated every 38 cycles, though lesser dividers
|
2017-04-16 01:18:00 +00:00
|
|
|
// will give greater resolution to changes in audio state. 1, 2 and 19 are the only divisors of 38.
|
2019-12-22 05:22:17 +00:00
|
|
|
constexpr int CPUTicksPerAudioTick = 2;
|
2017-04-04 01:16:39 +00:00
|
|
|
|
2017-12-18 02:26:06 +00:00
|
|
|
class TIASound: public Outputs::Speaker::SampleSource {
|
2016-12-03 18:39:46 +00:00
|
|
|
public:
|
2017-12-18 02:26:06 +00:00
|
|
|
TIASound(Concurrency::DeferringAsyncTaskQueue &audio_queue);
|
2016-12-03 18:39:46 +00:00
|
|
|
|
|
|
|
void set_volume(int channel, uint8_t volume);
|
|
|
|
void set_divider(int channel, uint8_t divider);
|
|
|
|
void set_control(int channel, uint8_t control);
|
|
|
|
|
2018-03-09 18:23:18 +00:00
|
|
|
// To satisfy ::SampleSource.
|
2017-12-18 02:26:06 +00:00
|
|
|
void get_samples(std::size_t number_of_samples, int16_t *target);
|
2018-03-09 18:23:18 +00:00
|
|
|
void set_sample_volume_range(std::int16_t range);
|
2016-12-03 18:39:46 +00:00
|
|
|
|
|
|
|
private:
|
2017-12-18 02:26:06 +00:00
|
|
|
Concurrency::DeferringAsyncTaskQueue &audio_queue_;
|
|
|
|
|
2016-12-03 18:39:46 +00:00
|
|
|
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];
|
2018-03-09 18:23:18 +00:00
|
|
|
int16_t per_channel_volume_ = 0;
|
2016-12-03 18:39:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Speaker_hpp */
|