From 7463426fe615625e5964de9c2a04ae708689235d Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Tue, 13 Dec 2016 15:08:42 -1000 Subject: [PATCH] Default audio mixing to main output --- include/boo/audiodev/IAudioVoice.hpp | 12 +-- lib/audiodev/AudioVoice.cpp | 105 +++++++++++++++++++++------ 2 files changed, 87 insertions(+), 30 deletions(-) diff --git a/include/boo/audiodev/IAudioVoice.hpp b/include/boo/audiodev/IAudioVoice.hpp index 1f992c3..c0dd9b0 100644 --- a/include/boo/audiodev/IAudioVoice.hpp +++ b/include/boo/audiodev/IAudioVoice.hpp @@ -95,19 +95,19 @@ struct IAudioVoiceCallback /** after resampling, boo calls this for each submix that this voice targets; * client performs volume processing and bus-routing this way */ - virtual void routeAudio(size_t frames, double dt, int busId, int16_t* in, int16_t* out) + virtual void routeAudio(size_t frames, size_t channels, double dt, int busId, int16_t* in, int16_t* out) { - memmove(out, in, frames * 2); + memmove(out, in, frames * channels * 2); } - virtual void routeAudio(size_t frames, double dt, int busId, int32_t* in, int32_t* out) + virtual void routeAudio(size_t frames, size_t channels, double dt, int busId, int32_t* in, int32_t* out) { - memmove(out, in, frames * 4); + memmove(out, in, frames * channels * 4); } - virtual void routeAudio(size_t frames, double dt, int busId, float* in, float* out) + virtual void routeAudio(size_t frames, size_t channels, double dt, int busId, float* in, float* out) { - memmove(out, in, frames * 4); + memmove(out, in, frames * channels * 4); } }; diff --git a/lib/audiodev/AudioVoice.cpp b/lib/audiodev/AudioVoice.cpp index adc170b..fd3364d 100644 --- a/lib/audiodev/AudioVoice.cpp +++ b/lib/audiodev/AudioVoice.cpp @@ -6,6 +6,9 @@ namespace boo { static logvisor::Module Log("boo::AudioVoice"); +static AudioMatrixMono DefaultMonoMtx; +static AudioMatrixStereo DefaultStereoMtx; + AudioVoice::AudioVoice(BaseAudioVoiceEngine& root, IAudioVoiceCallback* cb, bool dynamicRate) : m_root(root), m_cb(cb), m_dynamicRate(dynamicRate) {} @@ -137,11 +140,20 @@ size_t AudioVoiceMono::pumpAndMix16(size_t frames) if (oDone) { - for (auto& mtx : m_sendMatrices) + if (m_sendMatrices.size()) { - AudioSubmix& smx = *reinterpret_cast(mtx.first); - m_cb->routeAudio(oDone, dt, smx.m_busId, scratch16Pre.data(), scratch16Post.data()); - mtx.second.mixMonoSampleData(m_root.m_mixInfo, scratch16Post.data(), smx._getMergeBuf16(oDone), oDone); + for (auto& mtx : m_sendMatrices) + { + AudioSubmix& smx = *reinterpret_cast(mtx.first); + m_cb->routeAudio(oDone, 1, dt, smx.m_busId, scratch16Pre.data(), scratch16Post.data()); + mtx.second.mixMonoSampleData(m_root.m_mixInfo, scratch16Post.data(), smx._getMergeBuf16(oDone), oDone); + } + } + else + { + AudioSubmix& smx = reinterpret_cast(m_root.m_mainSubmix); + m_cb->routeAudio(oDone, 1, dt, m_root.m_mainSubmix.m_busId, scratch16Pre.data(), scratch16Post.data()); + DefaultMonoMtx.mixMonoSampleData(m_root.m_mixInfo, scratch16Post.data(), smx._getMergeBuf16(oDone), oDone); } } @@ -165,11 +177,20 @@ size_t AudioVoiceMono::pumpAndMix32(size_t frames) if (oDone) { - for (auto& mtx : m_sendMatrices) + if (m_sendMatrices.size()) { - AudioSubmix& smx = *reinterpret_cast(mtx.first); - m_cb->routeAudio(oDone, dt, smx.m_busId, scratch32Pre.data(), scratch32Post.data()); - mtx.second.mixMonoSampleData(m_root.m_mixInfo, scratch32Post.data(), smx._getMergeBuf32(oDone), oDone); + for (auto& mtx : m_sendMatrices) + { + AudioSubmix& smx = *reinterpret_cast(mtx.first); + m_cb->routeAudio(oDone, 1, dt, smx.m_busId, scratch32Pre.data(), scratch32Post.data()); + mtx.second.mixMonoSampleData(m_root.m_mixInfo, scratch32Post.data(), smx._getMergeBuf32(oDone), oDone); + } + } + else + { + AudioSubmix& smx = reinterpret_cast(m_root.m_mainSubmix); + m_cb->routeAudio(oDone, 1, dt, m_root.m_mainSubmix.m_busId, scratch32Pre.data(), scratch32Post.data()); + DefaultMonoMtx.mixMonoSampleData(m_root.m_mixInfo, scratch32Post.data(), smx._getMergeBuf32(oDone), oDone); } } @@ -193,11 +214,20 @@ size_t AudioVoiceMono::pumpAndMixFlt(size_t frames) if (oDone) { - for (auto& mtx : m_sendMatrices) + if (m_sendMatrices.size()) { - AudioSubmix& smx = *reinterpret_cast(mtx.first); - m_cb->routeAudio(oDone, dt, smx.m_busId, scratchFltPre.data(), scratchFltPost.data()); - mtx.second.mixMonoSampleData(m_root.m_mixInfo, scratchFltPost.data(), smx._getMergeBufFlt(oDone), oDone); + for (auto& mtx : m_sendMatrices) + { + AudioSubmix& smx = *reinterpret_cast(mtx.first); + m_cb->routeAudio(oDone, 1, dt, smx.m_busId, scratchFltPre.data(), scratchFltPost.data()); + mtx.second.mixMonoSampleData(m_root.m_mixInfo, scratchFltPost.data(), smx._getMergeBufFlt(oDone), oDone); + } + } + else + { + AudioSubmix& smx = reinterpret_cast(m_root.m_mainSubmix); + m_cb->routeAudio(oDone, 1, dt, m_root.m_mainSubmix.m_busId, scratchFltPre.data(), scratchFltPost.data()); + DefaultMonoMtx.mixMonoSampleData(m_root.m_mixInfo, scratchFltPost.data(), smx._getMergeBufFlt(oDone), oDone); } } @@ -307,11 +337,20 @@ size_t AudioVoiceStereo::pumpAndMix16(size_t frames) if (oDone) { - for (auto& mtx : m_sendMatrices) + if (m_sendMatrices.size()) { - AudioSubmix& smx = *reinterpret_cast(mtx.first); - m_cb->routeAudio(oDone, dt, smx.m_busId, scratch16Pre.data(), scratch16Post.data()); - mtx.second.mixStereoSampleData(m_root.m_mixInfo, scratch16Post.data(), smx._getMergeBuf16(oDone), oDone); + for (auto& mtx : m_sendMatrices) + { + AudioSubmix& smx = *reinterpret_cast(mtx.first); + m_cb->routeAudio(oDone, 2, dt, smx.m_busId, scratch16Pre.data(), scratch16Post.data()); + mtx.second.mixStereoSampleData(m_root.m_mixInfo, scratch16Post.data(), smx._getMergeBuf16(oDone), oDone); + } + } + else + { + AudioSubmix& smx = reinterpret_cast(m_root.m_mainSubmix); + m_cb->routeAudio(oDone, 2, dt, m_root.m_mainSubmix.m_busId, scratch16Pre.data(), scratch16Post.data()); + DefaultStereoMtx.mixStereoSampleData(m_root.m_mixInfo, scratch16Post.data(), smx._getMergeBuf16(oDone), oDone); } } @@ -337,11 +376,20 @@ size_t AudioVoiceStereo::pumpAndMix32(size_t frames) if (oDone) { - for (auto& mtx : m_sendMatrices) + if (m_sendMatrices.size()) { - AudioSubmix& smx = *reinterpret_cast(mtx.first); - m_cb->routeAudio(oDone, dt, smx.m_busId, scratch32Pre.data(), scratch32Post.data()); - mtx.second.mixStereoSampleData(m_root.m_mixInfo, scratch32Post.data(), smx._getMergeBuf32(oDone), oDone); + for (auto& mtx : m_sendMatrices) + { + AudioSubmix& smx = *reinterpret_cast(mtx.first); + m_cb->routeAudio(oDone, 2, dt, smx.m_busId, scratch32Pre.data(), scratch32Post.data()); + mtx.second.mixStereoSampleData(m_root.m_mixInfo, scratch32Post.data(), smx._getMergeBuf32(oDone), oDone); + } + } + else + { + AudioSubmix& smx = reinterpret_cast(m_root.m_mainSubmix); + m_cb->routeAudio(oDone, 2, dt, m_root.m_mainSubmix.m_busId, scratch32Pre.data(), scratch32Post.data()); + DefaultStereoMtx.mixStereoSampleData(m_root.m_mixInfo, scratch32Post.data(), smx._getMergeBuf32(oDone), oDone); } } @@ -367,11 +415,20 @@ size_t AudioVoiceStereo::pumpAndMixFlt(size_t frames) if (oDone) { - for (auto& mtx : m_sendMatrices) + if (m_sendMatrices.size()) { - AudioSubmix& smx = *reinterpret_cast(mtx.first); - m_cb->routeAudio(oDone, dt, smx.m_busId, scratchFltPre.data(), scratchFltPost.data()); - mtx.second.mixStereoSampleData(m_root.m_mixInfo, scratchFltPost.data(), smx._getMergeBufFlt(oDone), oDone); + for (auto& mtx : m_sendMatrices) + { + AudioSubmix& smx = *reinterpret_cast(mtx.first); + m_cb->routeAudio(oDone, 2, dt, smx.m_busId, scratchFltPre.data(), scratchFltPost.data()); + mtx.second.mixStereoSampleData(m_root.m_mixInfo, scratchFltPost.data(), smx._getMergeBufFlt(oDone), oDone); + } + } + else + { + AudioSubmix& smx = reinterpret_cast(m_root.m_mainSubmix); + m_cb->routeAudio(oDone, 2, dt, m_root.m_mainSubmix.m_busId, scratchFltPre.data(), scratchFltPost.data()); + DefaultStereoMtx.mixStereoSampleData(m_root.m_mixInfo, scratchFltPost.data(), smx._getMergeBufFlt(oDone), oDone); } }