diff --git a/lib/audiodev/AudioMatrix.hpp b/lib/audiodev/AudioMatrix.hpp index 9cd4dc3..90a559d 100644 --- a/lib/audiodev/AudioMatrix.hpp +++ b/lib/audiodev/AudioMatrix.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #if __SSE__ #include @@ -74,6 +75,18 @@ public: const int32_t* dataIn, int32_t* dataOut, size_t samples); float* mixMonoSampleData(const AudioVoiceEngineMixInfo& info, const float* dataIn, float* dataOut, size_t samples); + + bool isSilent() const + { + if (m_curSlewFrame < m_slewFrames) + for (int i=0 ; i<8 ; ++i) + if (m_oldCoefs.v[i] > FLT_EPSILON) + return false; + for (int i=0 ; i<8 ; ++i) + if (m_coefs.v[i] > FLT_EPSILON) + return false; + return true; + } }; class AudioMatrixStereo @@ -124,6 +137,18 @@ public: const int32_t* dataIn, int32_t* dataOut, size_t frames); float* mixStereoSampleData(const AudioVoiceEngineMixInfo& info, const float* dataIn, float* dataOut, size_t frames); + + bool isSilent() const + { + if (m_curSlewFrame < m_slewFrames) + for (int i=0 ; i<8 ; ++i) + if (m_oldCoefs.v[i][0] > FLT_EPSILON || m_oldCoefs.v[i][1] > FLT_EPSILON) + return false; + for (int i=0 ; i<8 ; ++i) + if (m_coefs.v[i][0] > FLT_EPSILON || m_coefs.v[i][1] > FLT_EPSILON) + return false; + return true; + } }; } diff --git a/lib/audiodev/AudioVoice.cpp b/lib/audiodev/AudioVoice.cpp index de7a5c4..7d2e5c2 100644 --- a/lib/audiodev/AudioVoice.cpp +++ b/lib/audiodev/AudioVoice.cpp @@ -125,6 +125,18 @@ size_t AudioVoiceMono::SRCCallback(AudioVoiceMono* ctx, int16_t** data, size_t f size_t AudioVoiceMono::pumpAndMix16(size_t frames) { + if (m_sendMatrices.size()) + { + for (auto& mtx : m_sendMatrices) + if (mtx.second.isSilent()) + return 0; + } + else + { + if (DefaultMonoMtx.isSilent()) + return 0; + } + std::vector& scratch16Pre = m_root.m_scratch16Pre; if (scratch16Pre.size() < frames) scratch16Pre.resize(frames); @@ -162,6 +174,18 @@ 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; + } + std::vector& scratch32Pre = m_root.m_scratch32Pre; if (scratch32Pre.size() < frames) scratch32Pre.resize(frames); @@ -199,6 +223,18 @@ 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; + } + std::vector& scratchFltPre = m_root.m_scratchFltPre; if (scratchFltPre.size() < frames) scratchFltPre.resize(frames + 2); @@ -326,6 +362,18 @@ size_t AudioVoiceStereo::SRCCallback(AudioVoiceStereo* ctx, int16_t** data, size size_t AudioVoiceStereo::pumpAndMix16(size_t frames) { + if (m_sendMatrices.size()) + { + for (auto& mtx : m_sendMatrices) + if (mtx.second.isSilent()) + return 0; + } + else + { + if (DefaultMonoMtx.isSilent()) + return 0; + } + size_t samples = frames * 2; std::vector& scratch16Pre = m_root.m_scratch16Pre; @@ -365,6 +413,18 @@ 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; + } + size_t samples = frames * 2; std::vector& scratch32Pre = m_root.m_scratch32Pre; @@ -404,6 +464,18 @@ 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; + } + size_t samples = frames * 2; std::vector& scratchFltPre = m_root.m_scratchFltPre;