diff --git a/Machines/Enterprise/Dave.cpp b/Machines/Enterprise/Dave.cpp index 157d10451..a030edb0f 100644 --- a/Machines/Enterprise/Dave.cpp +++ b/Machines/Enterprise/Dave.cpp @@ -43,6 +43,12 @@ void Dave::write(uint16_t address, uint8_t value) { }); } +void Dave::set_sample_volume_range(int16_t range) { + audio_queue_.defer([range, this] { + volume_ = range / (63*3); + }); +} + void Dave::get_samples(std::size_t number_of_samples, int16_t *target) { // Step 1: divide input clock to 125,000 Hz (?) for(size_t c = 0; c < number_of_samples; c++) { @@ -61,13 +67,17 @@ void Dave::get_samples(std::size_t number_of_samples, int16_t *target) { // Dumbest ever first attempt: sum channels. target[(c << 1) + 0] = - channels_[0].amplitude[0] * channels_[0].output + - channels_[1].amplitude[0] * channels_[1].output + - channels_[2].amplitude[0] * channels_[2].output; + volume_ * ( + channels_[0].amplitude[0] * channels_[0].output + + channels_[1].amplitude[0] * channels_[1].output + + channels_[2].amplitude[0] * channels_[2].output + ); target[(c << 1) + 1] = - channels_[0].amplitude[1] * channels_[0].output + - channels_[1].amplitude[1] * channels_[1].output + - channels_[2].amplitude[1] * channels_[2].output; + volume_ * ( + channels_[0].amplitude[1] * channels_[0].output + + channels_[1].amplitude[1] * channels_[1].output + + channels_[2].amplitude[1] * channels_[2].output + ); } } diff --git a/Machines/Enterprise/Dave.hpp b/Machines/Enterprise/Dave.hpp index b38f1b79d..911707431 100644 --- a/Machines/Enterprise/Dave.hpp +++ b/Machines/Enterprise/Dave.hpp @@ -28,7 +28,7 @@ class Dave: public Outputs::Speaker::SampleSource { void write(uint16_t address, uint8_t value); // MARK: - SampleSource. - void set_sample_volume_range([[maybe_unused]] int16_t range) {} + void set_sample_volume_range(int16_t range); static constexpr bool get_is_stereo() { return true; } // Dave produces stereo sound. void get_samples(std::size_t number_of_samples, int16_t *target); @@ -52,6 +52,7 @@ class Dave: public Outputs::Speaker::SampleSource { uint16_t count = 0; bool output = true; } channels_[3]; + int16_t volume_ = 0; // Various polynomials that contribute to audio generation. Numeric::LFSRv<0xc> poly4_;