Opens a specific audio device.
The device struct may be altered to match the actual hardware. (sampleRate, bufferSize and channel count)
69 const PaDeviceInfo* deviceInfo = Pa_GetDeviceInfo(device.id);
71 if (deviceInfo ==
nullptr) {
79 PaStreamParameters inputParameters;
80 inputParameters.device = device.
id;
81 inputParameters.sampleFormat = paFloat32;
82 inputParameters.suggestedLatency = deviceInfo->defaultLowInputLatency;
83 inputParameters.hostApiSpecificStreamInfo = NULL;
84 VAE_ASSERT(device.channelsIn <=
Uint(deviceInfo->maxInputChannels))
85 inputParameters.channelCount = device.channelsIn;
87 PaStreamParameters outputParameters;
88 outputParameters.device = device.
id;
89 outputParameters.sampleFormat = paFloat32;
90 outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency;
91 outputParameters.hostApiSpecificStreamInfo = NULL;
92 VAE_ASSERT(device.channelsOut <=
Uint(deviceInfo->maxOutputChannels))
93 outputParameters.channelCount = device.channelsOut;
95 if (device.bufferSize == 0) {
104 0 < inputParameters.channelCount ? &inputParameters : NULL,
105 0 < outputParameters.channelCount ? &outputParameters : NULL,
115 if (err != paNoError) {
121 err = Pa_SetStreamFinishedCallback(
125 if (err != paNoError) {
132 const PaStreamInfo* streamInfo = Pa_GetStreamInfo(
mStream);
134 Uint(streamInfo->sampleRate),
135 device.channelsIn, device.channelsOut,
144 if (err != paNoError) {
AudioThreadWorker mWorker
const EngineConfig & mConfig
void init(Size sampleRate, Uchar channelsIn, Uchar channelsOut, Size bufferSize)
initializes buffers, queues and resamplers if needed Has to be called in openDevice once the samplera...
static void StreamFinished(void *data)
static int AudioCallback(const void *in, void *out, unsigned long frames, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *data)
Function called from the PortAudio thread.
Using template interfaces isn't an option so this simply defines a default Convolver type.
T clamp(const T &v, const T &_min, const T &_max)
constexpr unsigned char MaxChannels
Maximum channel count used to pre allocate buffers.
Size preferredBufferSize
Buffer size that will be requested from device.