mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-01 11:49:58 +00:00
Respect user volume input.
Basic tones are now present. Neato!
This commit is contained in:
parent
1a97cc8a91
commit
c2d093fa3c
@ -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) {
|
void Dave::get_samples(std::size_t number_of_samples, int16_t *target) {
|
||||||
// Step 1: divide input clock to 125,000 Hz (?)
|
// Step 1: divide input clock to 125,000 Hz (?)
|
||||||
for(size_t c = 0; c < number_of_samples; c++) {
|
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.
|
// Dumbest ever first attempt: sum channels.
|
||||||
target[(c << 1) + 0] =
|
target[(c << 1) + 0] =
|
||||||
channels_[0].amplitude[0] * channels_[0].output +
|
volume_ * (
|
||||||
channels_[1].amplitude[0] * channels_[1].output +
|
channels_[0].amplitude[0] * channels_[0].output +
|
||||||
channels_[2].amplitude[0] * channels_[2].output;
|
channels_[1].amplitude[0] * channels_[1].output +
|
||||||
|
channels_[2].amplitude[0] * channels_[2].output
|
||||||
|
);
|
||||||
|
|
||||||
target[(c << 1) + 1] =
|
target[(c << 1) + 1] =
|
||||||
channels_[0].amplitude[1] * channels_[0].output +
|
volume_ * (
|
||||||
channels_[1].amplitude[1] * channels_[1].output +
|
channels_[0].amplitude[1] * channels_[0].output +
|
||||||
channels_[2].amplitude[1] * channels_[2].output;
|
channels_[1].amplitude[1] * channels_[1].output +
|
||||||
|
channels_[2].amplitude[1] * channels_[2].output
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class Dave: public Outputs::Speaker::SampleSource {
|
|||||||
void write(uint16_t address, uint8_t value);
|
void write(uint16_t address, uint8_t value);
|
||||||
|
|
||||||
// MARK: - SampleSource.
|
// 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.
|
static constexpr bool get_is_stereo() { return true; } // Dave produces stereo sound.
|
||||||
void get_samples(std::size_t number_of_samples, int16_t *target);
|
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;
|
uint16_t count = 0;
|
||||||
bool output = true;
|
bool output = true;
|
||||||
} channels_[3];
|
} channels_[3];
|
||||||
|
int16_t volume_ = 0;
|
||||||
|
|
||||||
// Various polynomials that contribute to audio generation.
|
// Various polynomials that contribute to audio generation.
|
||||||
Numeric::LFSRv<0xc> poly4_;
|
Numeric::LFSRv<0xc> poly4_;
|
||||||
|
Loading…
Reference in New Issue
Block a user