Skip to content

Commit

Permalink
codal_app/microbithal_audio: Set audio channel sample rate on init.
Browse files Browse the repository at this point in the history
Fixes the case of using `speech.say(..., mode=mode)` when the mode changes
and selects a different output sample rate.

Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Feb 26, 2024
1 parent 9db217a commit 8dfe395
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/codal_app/microbithal_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AudioSource : public DataSource {
DataSink *sink;
ManagedBuffer buf;
void (*callback)(void);
MixerChannel *channel;

AudioSource()
: started(false) {
Expand Down Expand Up @@ -109,7 +110,9 @@ void microbit_hal_audio_init(uint32_t sample_rate) {
MicroBitAudio::requestActivation();
data_source.started = true;
data_source.callback = microbit_hal_audio_ready_callback;
uBit.audio.mixer.addChannel(data_source, sample_rate, 255);
data_source.channel = uBit.audio.mixer.addChannel(data_source, sample_rate, 255);
} else {
data_source.channel->setSampleRate(sample_rate);
}
}

Expand All @@ -126,7 +129,9 @@ void microbit_hal_audio_speech_init(uint32_t sample_rate) {
MicroBitAudio::requestActivation();
speech_source.started = true;
speech_source.callback = microbit_hal_audio_speech_ready_callback;
uBit.audio.mixer.addChannel(speech_source, sample_rate, 255);
speech_source.channel = uBit.audio.mixer.addChannel(speech_source, sample_rate, 255);
} else {
speech_source.channel->setSampleRate(sample_rate);
}
}

Expand Down

0 comments on commit 8dfe395

Please sign in to comment.