Workaround for bug in RtAudio when first channel not equal to 0
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Anne de Jong 2023-05-25 16:52:55 +02:00
parent 9ec2abeced
commit 43cf2427ea

View File

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