diff --git a/lib/audiodev/AudioVoice.cpp b/lib/audiodev/AudioVoice.cpp index 7d2e5c2..0c810e7 100644 --- a/lib/audiodev/AudioVoice.cpp +++ b/lib/audiodev/AudioVoice.cpp @@ -123,19 +123,25 @@ size_t AudioVoiceMono::SRCCallback(AudioVoiceMono* ctx, int16_t** data, size_t f return ctx->m_cb->supplyAudio(*ctx, frames, scratchIn.data()); } -size_t AudioVoiceMono::pumpAndMix16(size_t frames) +bool AudioVoiceMono::isSilent() const { if (m_sendMatrices.size()) { for (auto& mtx : m_sendMatrices) - if (mtx.second.isSilent()) - return 0; + if (!mtx.second.isSilent()) + return false; + return true; } else { - if (DefaultMonoMtx.isSilent()) - return 0; + return DefaultMonoMtx.isSilent(); } +} + +size_t AudioVoiceMono::pumpAndMix16(size_t frames) +{ + if (isSilent()) + return 0; std::vector& scratch16Pre = m_root.m_scratch16Pre; if (scratch16Pre.size() < frames) @@ -174,17 +180,8 @@ size_t AudioVoiceMono::pumpAndMix16(size_t frames) size_t AudioVoiceMono::pumpAndMix32(size_t frames) { - if (m_sendMatrices.size()) - { - for (auto& mtx : m_sendMatrices) - if (mtx.second.isSilent()) - return 0; - } - else - { - if (DefaultMonoMtx.isSilent()) - return 0; - } + if (isSilent()) + return 0; std::vector& scratch32Pre = m_root.m_scratch32Pre; if (scratch32Pre.size() < frames) @@ -223,17 +220,8 @@ size_t AudioVoiceMono::pumpAndMix32(size_t frames) size_t AudioVoiceMono::pumpAndMixFlt(size_t frames) { - if (m_sendMatrices.size()) - { - for (auto& mtx : m_sendMatrices) - if (mtx.second.isSilent()) - return 0; - } - else - { - if (DefaultMonoMtx.isSilent()) - return 0; - } + if (isSilent()) + return 0; std::vector& scratchFltPre = m_root.m_scratchFltPre; if (scratchFltPre.size() < frames) @@ -360,19 +348,25 @@ size_t AudioVoiceStereo::SRCCallback(AudioVoiceStereo* ctx, int16_t** data, size return ctx->m_cb->supplyAudio(*ctx, frames, scratchIn.data()); } -size_t AudioVoiceStereo::pumpAndMix16(size_t frames) +bool AudioVoiceStereo::isSilent() const { if (m_sendMatrices.size()) { for (auto& mtx : m_sendMatrices) - if (mtx.second.isSilent()) - return 0; + if (!mtx.second.isSilent()) + return false; + return true; } else { - if (DefaultMonoMtx.isSilent()) - return 0; + return DefaultStereoMtx.isSilent(); } +} + +size_t AudioVoiceStereo::pumpAndMix16(size_t frames) +{ + if (isSilent()) + return 0; size_t samples = frames * 2; @@ -413,17 +407,8 @@ size_t AudioVoiceStereo::pumpAndMix16(size_t frames) size_t AudioVoiceStereo::pumpAndMix32(size_t frames) { - if (m_sendMatrices.size()) - { - for (auto& mtx : m_sendMatrices) - if (mtx.second.isSilent()) - return 0; - } - else - { - if (DefaultMonoMtx.isSilent()) - return 0; - } + if (isSilent()) + return 0; size_t samples = frames * 2; @@ -464,17 +449,8 @@ size_t AudioVoiceStereo::pumpAndMix32(size_t frames) size_t AudioVoiceStereo::pumpAndMixFlt(size_t frames) { - if (m_sendMatrices.size()) - { - for (auto& mtx : m_sendMatrices) - if (mtx.second.isSilent()) - return 0; - } - else - { - if (DefaultMonoMtx.isSilent()) - return 0; - } + if (isSilent()) + return 0; size_t samples = frames * 2; diff --git a/lib/audiodev/AudioVoice.hpp b/lib/audiodev/AudioVoice.hpp index 63deef7..9686291 100644 --- a/lib/audiodev/AudioVoice.hpp +++ b/lib/audiodev/AudioVoice.hpp @@ -89,6 +89,8 @@ class AudioVoiceMono : public AudioVoice static size_t SRCCallback(AudioVoiceMono* ctx, int16_t** data, size_t requestedLen); + bool isSilent() const; + size_t pumpAndMix16(size_t frames); size_t pumpAndMix32(size_t frames); size_t pumpAndMixFlt(size_t frames); @@ -110,6 +112,8 @@ class AudioVoiceStereo : public AudioVoice static size_t SRCCallback(AudioVoiceStereo* ctx, int16_t** data, size_t requestedLen); + bool isSilent() const; + size_t pumpAndMix16(size_t frames); size_t pumpAndMix32(size_t frames); size_t pumpAndMixFlt(size_t frames);