diff --git a/src/lasp/device/lasp_rtaudiodaq.cpp b/src/lasp/device/lasp_rtaudiodaq.cpp index 7c0742c..f2fef80 100644 --- a/src/lasp/device/lasp_rtaudiodaq.cpp +++ b/src/lasp/device/lasp_rtaudiodaq.cpp @@ -1,5 +1,5 @@ -#include /* #define DEBUGTRACE_ENABLED */ +#include #include "debugtrace.hpp" #include "lasp_mathtypes.h" @@ -177,23 +177,22 @@ public: inParams = std::make_unique(); - // +1 to get the count. - inParams->nChannels = getHighestEnabledInChannel() + 1; - if (inParams->nChannels < 1) { - throw rte("Invalid input number of channels"); - } + /// RtAudio lacks good bookkeeping when the first channel is not equal to + /// 0. For now, our fix is to shift out the channels we want, and let + /// RtAudio pass on all channels. inParams->firstChannel = 0; + inParams->nChannels = devinfo_gen.ninchannels; inParams->deviceId = devinfo._api_devindex; } else { outParams = std::make_unique(); - outParams->nChannels = getHighestEnabledOutChannel() + 1; - if (outParams->nChannels < 1) { - throw rte("Invalid output number of channels"); - } + /// RtAudio lacks good bookkeeping when the first channel is not equal to + /// 0. For now, our fix is to shift out the channels we want, and let + /// RtAudio pass on all channels. outParams->firstChannel = 0; + outParams->nChannels = devinfo_gen.noutchannels; outParams->deviceId = devinfo._api_devindex; } @@ -355,15 +354,16 @@ public: const us ch_min = getLowestEnabledInChannel(); const us ch_max = getHighestEnabledInChannel(); - us i = 0; + assert(ch_min < ninchannels); + assert(ch_max < ninchannels); + + /// Only pass on the pointers of the channels we want for (us ch = ch_min; ch <= ch_max; ch++) { if (inchannel_config.at(ch).enabled) { byte_t *ptr = - static_cast(inputBuffer) + sw * i * nFramesPerBlock; - DEBUGTRACE_PRINT((us)ptr); + static_cast(inputBuffer) + sw * ch * nFramesPerBlock; ptrs.push_back(ptr); } - i++; } DaqData d{nFramesPerBlock, neninchannels, dtype}; d.copyInFromRaw(ptrs); @@ -384,14 +384,14 @@ public: const us ch_min = getLowestEnabledOutChannel(); const us ch_max = getHighestEnabledOutChannel(); - us i = 0; + assert(ch_min < noutchannels); + assert(ch_max < noutchannels); + /// Only pass on the pointers of the channels we want for (us ch = ch_min; ch <= ch_max; ch++) { if (outchannel_config.at(ch).enabled) { - ptrs.push_back(static_cast(outputBuffer) + - sw * i * nFramesPerBlock); + sw * ch * nFramesPerBlock); } - i++; } DaqData d{nFramesPerBlock, nenoutchannels, dtype};