From 38fbcf2de4723fec4d1e11a2339bc6aeb717f028 Mon Sep 17 00:00:00 2001 From: sletz Date: Sat, 2 Apr 2011 07:39:18 +0000 Subject: [PATCH] Code factorization on JackPortAudioDriver. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4251 0c269be4-1314-0410-8aa9-9f06e86f4224 --- common/JackWaitThreadedDriver.h | 2 +- windows/portaudio/JackPortAudioDevices.cpp | 11 +-- windows/portaudio/JackPortAudioDriver.cpp | 107 ++++++++------------- windows/portaudio/JackPortAudioDriver.h | 1 + 4 files changed, 49 insertions(+), 72 deletions(-) diff --git a/common/JackWaitThreadedDriver.h b/common/JackWaitThreadedDriver.h index 990065f4..32263123 100644 --- a/common/JackWaitThreadedDriver.h +++ b/common/JackWaitThreadedDriver.h @@ -22,7 +22,7 @@ #define __JackWaitThreadedDriver__ #include "JackThreadedDriver.h" -#include "JackAudioDriver.h" +#include "JackDriver.h" namespace Jack { diff --git a/windows/portaudio/JackPortAudioDevices.cpp b/windows/portaudio/JackPortAudioDevices.cpp index d12cfca3..786fb939 100644 --- a/windows/portaudio/JackPortAudioDevices.cpp +++ b/windows/portaudio/JackPortAudioDevices.cpp @@ -27,19 +27,18 @@ PortAudioDevices::PortAudioDevices() PaError err; PaDeviceIndex id; jack_log("Initializing PortAudio..."); - if ( ( err = Pa_Initialize() ) == paNoError ) - { + if ((err = Pa_Initialize() ) == paNoError) { fNumHostApi = Pa_GetHostApiCount(); fNumDevice = Pa_GetDeviceCount(); fDeviceInfo = new PaDeviceInfo*[fNumDevice]; - for ( id = 0; id < fNumDevice; id++ ) + for (id = 0; id < fNumDevice; id++) fDeviceInfo[id] = const_cast(Pa_GetDeviceInfo(id)); fHostName = new string[fNumHostApi]; - for ( id = 0; id < fNumHostApi; id++ ) + for (id = 0; id < fNumHostApi; id++) fHostName[id] = string ( Pa_GetHostApiInfo(id)->name ); - } - else + } else { jack_error("JackPortAudioDriver::Pa_Initialize error = %s", Pa_GetErrorText(err)); + } } PortAudioDevices::~PortAudioDevices() diff --git a/windows/portaudio/JackPortAudioDriver.cpp b/windows/portaudio/JackPortAudioDriver.cpp index f7611add..d0b23a02 100644 --- a/windows/portaudio/JackPortAudioDriver.cpp +++ b/windows/portaudio/JackPortAudioDriver.cpp @@ -60,6 +60,40 @@ namespace Jack return 0; } + int JackPortAudioDriver::OpenStream() + { + PaStreamParameters inputParameters; + PaStreamParameters outputParameters; + + // Update parameters + inputParameters.device = fInputDevice; + inputParameters.channelCount = fCaptureChannels; + inputParameters.sampleFormat = paFloat32 | paNonInterleaved; // 32 bit floating point output + inputParameters.suggestedLatency = (fInputDevice != paNoDevice) // TODO: check how to setup this on ASIO + ? Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency + : 0; + inputParameters.hostApiSpecificStreamInfo = NULL; + + outputParameters.device = fOutputDevice; + outputParameters.channelCount = fPlaybackChannels; + outputParameters.sampleFormat = paFloat32 | paNonInterleaved; // 32 bit floating point output + outputParameters.suggestedLatency = (fOutputDevice != paNoDevice) // TODO: check how to setup this on ASIO + ? Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency + : 0; + outputParameters.hostApiSpecificStreamInfo = NULL; + + PaError err = Pa_OpenStream(&fStream, + (fInputDevice == paNoDevice) ? 0 : &inputParameters, + (fOutputDevice == paNoDevice) ? 0 : &outputParameters, + fEngineControl->fSampleRate, + buffer_size, + paNoFlag, // Clipping is on... + Render, + this); + + return (err == paNoError) ? 0: -1; + } + int JackPortAudioDriver::Open(jack_nframes_t buffer_size, jack_nframes_t samplerate, bool capturing, @@ -72,9 +106,6 @@ namespace Jack jack_nframes_t capture_latency, jack_nframes_t playback_latency) { - PaError err = paNoError; - PaStreamParameters inputParameters; - PaStreamParameters outputParameters; int in_max = 0; int out_max = 0; @@ -117,32 +148,7 @@ namespace Jack outchannels = out_max; } - //in/out streams parametering - inputParameters.device = fInputDevice; - inputParameters.channelCount = inchannels; - inputParameters.sampleFormat = paFloat32 | paNonInterleaved; // 32 bit floating point output - inputParameters.suggestedLatency = (fInputDevice != paNoDevice) // TODO: check how to setup this on ASIO - ? fPaDevices->GetDeviceInfo(fInputDevice)->defaultLowInputLatency - : 0; - inputParameters.hostApiSpecificStreamInfo = NULL; - - outputParameters.device = fOutputDevice; - outputParameters.channelCount = outchannels; - outputParameters.sampleFormat = paFloat32 | paNonInterleaved; // 32 bit floating point output - outputParameters.suggestedLatency = (fOutputDevice != paNoDevice) // TODO: check how to setup this on ASIO - ? fPaDevices->GetDeviceInfo(fOutputDevice)->defaultLowOutputLatency - : 0; - outputParameters.hostApiSpecificStreamInfo = NULL; - - err = Pa_OpenStream(&fStream, - (fInputDevice == paNoDevice) ? 0 : &inputParameters, - (fOutputDevice == paNoDevice) ? 0 : &outputParameters, - samplerate, - buffer_size, - paNoFlag, // Clipping is on... - Render, - this); - if (err != paNoError) { + if (OpenStream() < 0) { jack_error("Pa_OpenStream error = %s", Pa_GetErrorText(err)); goto error; } @@ -208,41 +214,13 @@ error: int JackPortAudioDriver::SetBufferSize(jack_nframes_t buffer_size) { PaError err; - PaStreamParameters inputParameters; - PaStreamParameters outputParameters; if ((err = Pa_CloseStream(fStream)) != paNoError) { jack_error("Pa_CloseStream error = %s", Pa_GetErrorText(err)); return -1; } - // Update parameters - inputParameters.device = fInputDevice; - inputParameters.channelCount = fCaptureChannels; - inputParameters.sampleFormat = paFloat32 | paNonInterleaved; // 32 bit floating point output - inputParameters.suggestedLatency = (fInputDevice != paNoDevice) // TODO: check how to setup this on ASIO - ? Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency - : 0; - inputParameters.hostApiSpecificStreamInfo = NULL; - - outputParameters.device = fOutputDevice; - outputParameters.channelCount = fPlaybackChannels; - outputParameters.sampleFormat = paFloat32 | paNonInterleaved; // 32 bit floating point output - outputParameters.suggestedLatency = (fOutputDevice != paNoDevice) // TODO: check how to setup this on ASIO - ? Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency - : 0; - outputParameters.hostApiSpecificStreamInfo = NULL; - - err = Pa_OpenStream(&fStream, - (fInputDevice == paNoDevice) ? 0 : &inputParameters, - (fOutputDevice == paNoDevice) ? 0 : &outputParameters, - fEngineControl->fSampleRate, - buffer_size, - paNoFlag, // Clipping is on... - Render, - this); - - if (err != paNoError) { + if (OpenStream() < 0) { jack_error("Pa_OpenStream error = %s", Pa_GetErrorText(err)); return -1; } else { @@ -402,8 +380,7 @@ extern "C" { param = (const jack_driver_param_t *) node->data; - switch (param->character) - { + switch (param->character) { case 'd': capture_pcm_name = param->value.str; @@ -474,12 +451,12 @@ extern "C" } Jack::JackDriverClientInterface* driver = new Jack::JackPortAudioDriver("system", "portaudio", engine, table, pa_devices); - if (driver->Open(frames_per_interrupt, srate, capture, playback, chan_in, chan_out, monitor, capture_pcm_name, playback_pcm_name, systemic_input_latency, systemic_output_latency) == 0) - { + if (driver->Open(frames_per_interrupt, srate, capture, playback, + chan_in, chan_out, monitor, capture_pcm_name, + playback_pcm_name, systemic_input_latency, + systemic_output_latency) == 0) { return driver; - } - else - { + } else { delete driver; return NULL; } diff --git a/windows/portaudio/JackPortAudioDriver.h b/windows/portaudio/JackPortAudioDriver.h index 564d5a4e..c49d391d 100644 --- a/windows/portaudio/JackPortAudioDriver.h +++ b/windows/portaudio/JackPortAudioDriver.h @@ -49,6 +49,7 @@ class JackPortAudioDriver : public JackAudioDriver void* userData); void UpdateLatencies(); + int OpenStream(); public: