From f69384525acf4c77fb1f050dc47775c56d56f1b0 Mon Sep 17 00:00:00 2001 From: Hubert Chrzaniuk Date: Thu, 26 Nov 2020 09:46:30 +0100 Subject: [PATCH] [EGD-4332][EGD-4482] Fix playback of mono sound in headphones (#1080) Addressed problem - when playing files containing only one audio channel the sound could be heard in only one speaker. --- changelog.md | 4 ++++ module-audio/Audio/Operation/PlaybackOperation.cpp | 13 ++++++++++--- module-audio/Audio/decoder/decoder.hpp | 5 +++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 70b14f5efb6c04d86701586359c52163fb80a664..df751e9c4695b5dfa0c674c71d4819b89c90a73b 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,10 @@ * `[cellular]` Integration with basic flow for SIM card (cellular<>GUI) +### Fixed + +* `[audio]` Fix playback of mono sound using headphones + ## [0.48.1 2020-11-23] ### Added diff --git a/module-audio/Audio/Operation/PlaybackOperation.cpp b/module-audio/Audio/Operation/PlaybackOperation.cpp index 2aee8aa21789114dca692720692fb748e5fe285c..0f871f3a6f262b273c61e22e0a467d0de8647c0c 100644 --- a/module-audio/Audio/Operation/PlaybackOperation.cpp +++ b/module-audio/Audio/Operation/PlaybackOperation.cpp @@ -90,9 +90,16 @@ namespace audio eventCallback = callback; state = State::Active; - currentProfile->SetInOutFlags(tags->num_channel == 2 - ? static_cast(bsp::AudioDevice::Flags::OutputStereo) - : static_cast(bsp::AudioDevice::Flags::OutputMono)); + if (tags->num_channel == channel::stereoSound) { + currentProfile->SetInOutFlags(static_cast(bsp::AudioDevice::Flags::OutputStereo)); + } + else { + currentProfile->SetInOutFlags(static_cast(bsp::AudioDevice::Flags::OutputMono)); + if (currentProfile->GetOutputPath() == bsp::AudioDevice::OutputPath::Headphones) { + currentProfile->SetOutputPath(bsp::AudioDevice::OutputPath::HeadphonesMono); + } + } + currentProfile->SetSampleRate(tags->sample_rate); auto ret = audioDevice->Start(currentProfile->GetAudioFormat()); diff --git a/module-audio/Audio/decoder/decoder.hpp b/module-audio/Audio/decoder/decoder.hpp index 949495c38ec42ba163b506af58daf976d8c1920c..ac8107383e45535069cb344fb953ff7230d70a6e 100644 --- a/module-audio/Audio/decoder/decoder.hpp +++ b/module-audio/Audio/decoder/decoder.hpp @@ -12,6 +12,11 @@ namespace audio { + namespace channel + { + constexpr inline auto monoSound = 1; + constexpr inline auto stereoSound = 2; + } // namespace channel struct Tags {