summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorailurux <ailuruxx@gmail.com>2025-02-11 12:43:01 +1100
committerailurux <ailuruxx@gmail.com>2025-02-11 12:43:01 +1100
commit285c4928af79c1f5844277464832f060ded77f85 (patch)
treeb937a8e3f9ee67b4342f8459debc122587dd3291
parent4f08a0838aeea3022ea915bebb34e42ac7f2b47c (diff)
downloadtangara-fw-285c4928af79c1f5844277464832f060ded77f85.tar.gz
Only change output mode if the new output mode is different
-rw-r--r--src/tangara/audio/audio_fsm.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/tangara/audio/audio_fsm.cpp b/src/tangara/audio/audio_fsm.cpp
index d479542a..7854818d 100644
--- a/src/tangara/audio/audio_fsm.cpp
+++ b/src/tangara/audio/audio_fsm.cpp
@@ -390,16 +390,20 @@ void AudioState::react(const OutputModeChanged& ev) {
if (ev.set_to) {
new_mode = *ev.set_to;
}
+ std::shared_ptr<IAudioOutput> new_output;
switch (new_mode) {
case drivers::NvsStorage::Output::kBluetooth:
- sOutput = sBtOutput;
- sI2SOutput->mode(IAudioOutput::Modes::kOff);
+ new_output = sBtOutput;
break;
case drivers::NvsStorage::Output::kHeadphones:
- sOutput = sI2SOutput;
- sBtOutput->mode(IAudioOutput::Modes::kOff);
+ new_output = sI2SOutput;
break;
}
+ if (new_output == sOutput) {
+ return;
+ }
+ sOutput->mode(IAudioOutput::Modes::kOff);
+ sOutput = new_output;
sSampleProcessor->SetOutput(sOutput);
updateOutputMode();