Skip to content

Commit 8dfe395

Browse files
committed
codal_app/microbithal_audio: Set audio channel sample rate on init.
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 <damien@micropython.org>
1 parent 9db217a commit 8dfe395

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/codal_app/microbithal_audio.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class AudioSource : public DataSource {
3333
DataSink *sink;
3434
ManagedBuffer buf;
3535
void (*callback)(void);
36+
MixerChannel *channel;
3637

3738
AudioSource()
3839
: started(false) {
@@ -109,7 +110,9 @@ void microbit_hal_audio_init(uint32_t sample_rate) {
109110
MicroBitAudio::requestActivation();
110111
data_source.started = true;
111112
data_source.callback = microbit_hal_audio_ready_callback;
112-
uBit.audio.mixer.addChannel(data_source, sample_rate, 255);
113+
data_source.channel = uBit.audio.mixer.addChannel(data_source, sample_rate, 255);
114+
} else {
115+
data_source.channel->setSampleRate(sample_rate);
113116
}
114117
}
115118

@@ -126,7 +129,9 @@ void microbit_hal_audio_speech_init(uint32_t sample_rate) {
126129
MicroBitAudio::requestActivation();
127130
speech_source.started = true;
128131
speech_source.callback = microbit_hal_audio_speech_ready_callback;
129-
uBit.audio.mixer.addChannel(speech_source, sample_rate, 255);
132+
speech_source.channel = uBit.audio.mixer.addChannel(speech_source, sample_rate, 255);
133+
} else {
134+
speech_source.channel->setSampleRate(sample_rate);
130135
}
131136
}
132137

0 commit comments

Comments
 (0)