From e8daec426ee9dd47dc83b03e9b217e7920443d76 Mon Sep 17 00:00:00 2001 From: CorvusPrudens Date: Fri, 30 Sep 2022 10:46:57 -0600 Subject: [PATCH 1/2] Update audio.cpp to swap dual codec callback selection --- src/hid/audio.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/hid/audio.cpp b/src/hid/audio.cpp index 211e83cf2..a45842fb8 100644 --- a/src/hid/audio.cpp +++ b/src/hid/audio.cpp @@ -174,12 +174,20 @@ AudioHandle::Impl::Start(AudioHandle::AudioCallback callback) { // Start stream with no callback. Data will be filled externally. sai2_.StartDma( - buff_rx_[1], buff_tx_[1], config_.blocksize * 2 * 2, nullptr); + buff_rx_[0], buff_tx_[0], config_.blocksize * 2 * 2, audio_handle.InternalCallback); + + sai1_.StartDma(buff_rx_[1], + buff_tx_[1], + config_.blocksize * 2 * 2, + nullptr); } - sai1_.StartDma(buff_rx_[0], + else + { + sai1_.StartDma(buff_rx_[0], buff_tx_[0], config_.blocksize * 2 * 2, audio_handle.InternalCallback); + } callback_ = (void*)callback; interleaved_callback_ = nullptr; return Result::OK; @@ -424,7 +432,23 @@ void AudioHandle::Impl::InternalCallback(int32_t* in, int32_t* out, size_t size) break; default: break; } + if (chns > 2) + { + // swap inputs + fin[2] = fin[0]; + fin[3] = fin[1]; + fin[0] = fin[1] + (buff_size / chns); + fin[1] = fin[0] + (buff_size / chns); + } cb(fin, fout, size / 2); + if(chns > 2) + { + // swap outputs + fout[2] = fout[0]; + fout[3] = fout[1]; + fout[0] = fout[1] + (buff_size / chns); + fout[1] = fout[0] + (buff_size / chns); + } // Reinterleave and scale switch(bd) { From d56be6916ecbb82ab129e1d1939582a2a2bfedcd Mon Sep 17 00:00:00 2001 From: CorvusPrudens Date: Fri, 30 Sep 2022 10:50:50 -0600 Subject: [PATCH 2/2] Fixed style --- src/hid/audio.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/hid/audio.cpp b/src/hid/audio.cpp index a45842fb8..ded75f6de 100644 --- a/src/hid/audio.cpp +++ b/src/hid/audio.cpp @@ -173,20 +173,20 @@ AudioHandle::Impl::Start(AudioHandle::AudioCallback callback) if(sai2_.IsInitialized()) { // Start stream with no callback. Data will be filled externally. - sai2_.StartDma( - buff_rx_[0], buff_tx_[0], config_.blocksize * 2 * 2, audio_handle.InternalCallback); + sai2_.StartDma(buff_rx_[0], + buff_tx_[0], + config_.blocksize * 2 * 2, + audio_handle.InternalCallback); - sai1_.StartDma(buff_rx_[1], - buff_tx_[1], - config_.blocksize * 2 * 2, - nullptr); + sai1_.StartDma( + buff_rx_[1], buff_tx_[1], config_.blocksize * 2 * 2, nullptr); } else { sai1_.StartDma(buff_rx_[0], - buff_tx_[0], - config_.blocksize * 2 * 2, - audio_handle.InternalCallback); + buff_tx_[0], + config_.blocksize * 2 * 2, + audio_handle.InternalCallback); } callback_ = (void*)callback; interleaved_callback_ = nullptr; @@ -432,7 +432,7 @@ void AudioHandle::Impl::InternalCallback(int32_t* in, int32_t* out, size_t size) break; default: break; } - if (chns > 2) + if(chns > 2) { // swap inputs fin[2] = fin[0];