JackPortAudioDriver.cpp

00001 /*
00002 Copyright (C) 2004-2006 Grame
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2 of the License, or
00007 (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 
00018 */
00019 
00020 #ifdef WIN32 
00021 #pragma warning (disable : 4786)
00022 #endif
00023 
00024 #ifdef __APPLE__
00025 #include "JackMachThread.h"
00026 #endif
00027 
00028 #include "pa_asio.h"
00029 #include "JackDriverLoader.h"
00030 #include "driver_interface.h"
00031 #include "JackPortAudioDriver.h"
00032 #include "JackEngineControl.h"
00033 #include "JackGraphManager.h"
00034 #include "JackError.h"
00035 #include "JackClientControl.h"
00036 #include "JackGlobals.h"
00037 #include <iostream>
00038 
00039 namespace Jack
00040 {
00041 
00042 void JackPortAudioDriver::PrintSupportedStandardSampleRates(const PaStreamParameters* inputParameters, const PaStreamParameters* outputParameters)
00043 {
00044     static double standardSampleRates[] = {
00045                                               8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0,
00046                                               44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1 /* negative terminated  list */
00047                                           };
00048     int i, printCount;
00049     PaError err;
00050 
00051     printCount = 0;
00052     for (i = 0; standardSampleRates[i] > 0; i++) {
00053         err = Pa_IsFormatSupported(inputParameters, outputParameters, standardSampleRates[i]);
00054         if (err == paFormatIsSupported) {
00055             if (printCount == 0) {
00056                 printf("\t%8.2f", standardSampleRates[i]);
00057                 printCount = 1;
00058             } else if (printCount == 4) {
00059                 printf(",\n\t%8.2f", standardSampleRates[i]);
00060                 printCount = 1;
00061             } else {
00062                 printf(", %8.2f", standardSampleRates[i]);
00063                 ++printCount;
00064             }
00065         }
00066     }
00067     if (!printCount)
00068         printf("None\n");
00069     else
00070         printf("\n");
00071 }
00072 
00073 bool JackPortAudioDriver::GetInputDeviceFromName(const char* name, PaDeviceIndex* device, int* in_max)
00074 {
00075     const PaDeviceInfo* deviceInfo;
00076     PaDeviceIndex numDevices = Pa_GetDeviceCount();
00077 
00078     for (int i = 0; i < numDevices; i++) {
00079         deviceInfo = Pa_GetDeviceInfo(i);
00080         if (strcmp(name, deviceInfo->name) == 0) {
00081             *device = i;
00082             *in_max = deviceInfo->maxInputChannels;
00083             return true;
00084         }
00085         }
00086 
00087     return false;
00088 }
00089 
00090 bool JackPortAudioDriver::GetOutputDeviceFromName(const char* name, PaDeviceIndex* device, int* out_max)
00091 {
00092     const PaDeviceInfo* deviceInfo;
00093     PaDeviceIndex numDevices = Pa_GetDeviceCount();
00094 
00095     for (int i = 0; i < numDevices; i++) {
00096         deviceInfo = Pa_GetDeviceInfo(i);
00097         if (strcmp(name, deviceInfo->name) == 0) {
00098             *device = i;
00099             *out_max = deviceInfo->maxOutputChannels;
00100             return true;
00101         }
00102     }
00103 
00104     return false;
00105 }
00106 
00107 static void DisplayDeviceNames()
00108 {
00109     PaError err;
00110     const PaDeviceInfo* deviceInfo;
00111     PaStreamParameters inputParameters, outputParameters;
00112     int defaultDisplayed;
00113 
00114     err = Pa_Initialize();
00115     if (err != paNoError)
00116         return ;
00117 
00118     PaDeviceIndex numDevices = Pa_GetDeviceCount();
00119     printf("Number of devices = %d\n", numDevices);
00120 
00121     for (int i = 0; i < numDevices; i++) {
00122         deviceInfo = Pa_GetDeviceInfo(i);
00123         printf( "--------------------------------------- device #%d\n", i );
00124 
00125         /* Mark global and API specific default devices */
00126         defaultDisplayed = 0;
00127         if (i == Pa_GetDefaultInputDevice()) {
00128             printf("[ Default Input");
00129             defaultDisplayed = 1;
00130         } else if (i == Pa_GetHostApiInfo(deviceInfo->hostApi)->defaultInputDevice) {
00131             const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
00132             printf("[ Default %s Input", hostInfo->name);
00133             defaultDisplayed = 1;
00134         }
00135 
00136         if (i == Pa_GetDefaultOutputDevice()) {
00137             printf((defaultDisplayed ? "," : "["));
00138             printf(" Default Output");
00139             defaultDisplayed = 1;
00140         } else if (i == Pa_GetHostApiInfo(deviceInfo->hostApi)->defaultOutputDevice) {
00141             const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
00142             printf((defaultDisplayed ? "," : "["));
00143             printf(" Default %s Output", hostInfo->name);
00144             defaultDisplayed = 1;
00145         }
00146 
00147         if (defaultDisplayed)
00148             printf(" ]\n");
00149 
00150         /* print device info fields */
00151         printf("Name                        = %s\n", deviceInfo->name);
00152         printf("Host API                    = %s\n", Pa_GetHostApiInfo(deviceInfo->hostApi)->name);
00153         printf("Max inputs = %d", deviceInfo->maxInputChannels);
00154         printf(", Max outputs = %d\n", deviceInfo->maxOutputChannels);
00155         /*
00156               printf("Default low input latency   = %8.3f\n", deviceInfo->defaultLowInputLatency);
00157               printf("Default low output latency  = %8.3f\n", deviceInfo->defaultLowOutputLatency);
00158               printf("Default high input latency  = %8.3f\n", deviceInfo->defaultHighInputLatency);
00159               printf("Default high output latency = %8.3f\n", deviceInfo->defaultHighOutputLatency);
00160         */
00161 
00162 #ifdef WIN32
00163 #ifndef PA_NO_ASIO 
00164         /* ASIO specific latency information */
00165         if (Pa_GetHostApiInfo(deviceInfo->hostApi)->type == paASIO) {
00166             long minLatency, maxLatency, preferredLatency, granularity;
00167 
00168             err = PaAsio_GetAvailableLatencyValues(i, &minLatency, &maxLatency, &preferredLatency, &granularity);
00169 
00170             printf("ASIO minimum buffer size    = %ld\n", minLatency);
00171             printf("ASIO maximum buffer size    = %ld\n", maxLatency);
00172             printf("ASIO preferred buffer size  = %ld\n", preferredLatency);
00173 
00174             if (granularity == -1)
00175                 printf("ASIO buffer granularity     = power of 2\n");
00176             else
00177                 printf("ASIO buffer granularity     = %ld\n", granularity);
00178         }
00179 #endif /* !PA_NO_ASIO */
00180 #endif /* WIN32 */
00181 
00182         printf("Default sample rate         = %8.2f\n", deviceInfo->defaultSampleRate);
00183 
00184         /* poll for standard sample rates */
00185         inputParameters.device = i;
00186         inputParameters.channelCount = deviceInfo->maxInputChannels;
00187         inputParameters.sampleFormat = paInt16;
00188         inputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
00189         inputParameters.hostApiSpecificStreamInfo = NULL;
00190 
00191         outputParameters.device = i;
00192         outputParameters.channelCount = deviceInfo->maxOutputChannels;
00193         outputParameters.sampleFormat = paInt16;
00194         outputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
00195         outputParameters.hostApiSpecificStreamInfo = NULL;
00196 
00197         /*
00198               if (inputParameters.channelCount > 0) {
00199                   printf("Supported standard sample rates\n for half-duplex 16 bit %d channel input = \n", inputParameters.channelCount);
00200                   PrintSupportedStandardSampleRates(&inputParameters, NULL);
00201               }
00202 
00203               if (outputParameters.channelCount > 0) {
00204                   printf("Supported standard sample rates\n for half-duplex 16 bit %d channel output = \n", outputParameters.channelCount);
00205                   PrintSupportedStandardSampleRates(NULL, &outputParameters);
00206               }
00207 
00208               if (inputParameters.channelCount > 0 && outputParameters.channelCount > 0) {
00209                   printf("Supported standard sample rates\n for full-duplex 16 bit %d channel input, %d channel output = \n",
00210                           inputParameters.channelCount, outputParameters.channelCount );
00211                   PrintSupportedStandardSampleRates(&inputParameters, &outputParameters);
00212               }
00213         */
00214     }
00215 
00216     Pa_Terminate();
00217 }
00218 
00219 int JackPortAudioDriver::Render(const void* inputBuffer, void* outputBuffer,
00220                                 unsigned long framesPerBuffer,
00221                                 const PaStreamCallbackTimeInfo* timeInfo,
00222                                 PaStreamCallbackFlags statusFlags,
00223                                 void* userData)
00224 {
00225     JackPortAudioDriver* driver = (JackPortAudioDriver*)userData;
00226     driver->fLastWaitUst = GetMicroSeconds(); // Take callback date here
00227     driver->fInputBuffer = (float**)inputBuffer;
00228     driver->fOutputBuffer = (float**)outputBuffer;
00229     return (driver->Process() == 0) ? paContinue : paAbort;
00230 }
00231 
00232 int JackPortAudioDriver::Read()
00233 {
00234     for (int i = 0; i < fCaptureChannels; i++) {
00235         memcpy(GetInputBuffer(i), fInputBuffer[i], sizeof(float) * fEngineControl->fBufferSize);
00236     }
00237     return 0;
00238 }
00239 
00240 int JackPortAudioDriver::Write()
00241 {
00242     for (int i = 0; i < fPlaybackChannels; i++) {
00243         memcpy(fOutputBuffer[i], GetOutputBuffer(i), sizeof(float) * fEngineControl->fBufferSize);
00244     }
00245     return 0;
00246 }
00247 
00248 int JackPortAudioDriver::Open(jack_nframes_t nframes,
00249                               jack_nframes_t samplerate,
00250                               int capturing,
00251                               int playing,
00252                               int inchannels,
00253                               int outchannels,
00254                               bool monitor,
00255                               const char* capture_driver_uid,
00256                               const char* playback_driver_uid,
00257                               jack_nframes_t capture_latency,
00258                               jack_nframes_t playback_latency)
00259 {
00260     PaError err;
00261     PaStreamParameters inputParameters;
00262     PaStreamParameters outputParameters;
00263     const PaDeviceInfo* deviceInfo;
00264     int in_max = 0;
00265     int out_max = 0;
00266 
00267     JackLog("JackPortAudioDriver::Open nframes = %ld in = %ld out = %ld capture name = %s playback name = %s samplerate = %ld\n",
00268             nframes, inchannels, outchannels, capture_driver_uid, playback_driver_uid, samplerate);
00269 
00270     // Generic JackAudioDriver Open
00271     if (JackAudioDriver::Open(nframes, samplerate, capturing, playing, inchannels, outchannels, monitor, capture_driver_uid, playback_driver_uid, capture_latency, playback_latency) != 0) {
00272         return -1;
00273     }
00274 
00275     err = Pa_Initialize();
00276     if (err != paNoError) {
00277         jack_error("JackPortAudioDriver::Pa_Initialize error = %s\n", Pa_GetErrorText(err));
00278         goto error;
00279     }
00280 
00281     JackLog("JackPortAudioDriver::Pa_GetDefaultInputDevice %ld\n", Pa_GetDefaultInputDevice());
00282     JackLog("JackPortAudioDriver::Pa_GetDefaultOutputDevice %ld\n", Pa_GetDefaultOutputDevice());
00283 
00284     if (capturing) {
00285         if (!GetInputDeviceFromName(capture_driver_uid, &fInputDevice, &in_max)) {
00286                         JackLog("JackPortAudioDriver::GetInputDeviceFromName cannot open %s\n", capture_driver_uid);
00287             fInputDevice = Pa_GetDefaultInputDevice();
00288                         if (fInputDevice == paNoDevice)
00289                                 goto error;
00290             deviceInfo = Pa_GetDeviceInfo(fInputDevice);
00291             in_max = deviceInfo->maxInputChannels;
00292             capture_driver_uid = strdup(deviceInfo->name);
00293         }
00294     }
00295 
00296     if (inchannels > in_max) {
00297         jack_error("This device hasn't required input channels inchannels = %ld in_max = %ld", inchannels, in_max);
00298         goto error;
00299     }
00300 
00301     if (playing) {
00302         if (!GetOutputDeviceFromName(playback_driver_uid, &fOutputDevice, &out_max)) {
00303             JackLog("JackPortAudioDriver::GetOutputDeviceFromName cannot open %s\n", playback_driver_uid);
00304                         fOutputDevice = Pa_GetDefaultOutputDevice();
00305                         if (fOutputDevice == paNoDevice)
00306                                 goto error;
00307             deviceInfo = Pa_GetDeviceInfo(fOutputDevice);
00308             out_max = deviceInfo->maxOutputChannels;
00309             playback_driver_uid = strdup(deviceInfo->name);
00310         }
00311     }
00312 
00313     if (outchannels > out_max) {
00314         jack_error("This device hasn't required output channels outchannels = %ld out_max = %ld", outchannels, out_max);
00315         goto error;
00316     }
00317 
00318     if (inchannels == 0) {
00319         JackLog("JackPortAudioDriver::Open setup max in channels = %ld\n", in_max);
00320         inchannels = in_max;
00321     }
00322 
00323     if (outchannels == 0) {
00324         JackLog("JackPortAudioDriver::Open setup max out channels = %ld\n", out_max);
00325         outchannels = out_max;
00326     }
00327 
00328     inputParameters.device = fInputDevice;
00329     inputParameters.channelCount = inchannels;
00330     inputParameters.sampleFormat = paFloat32 | paNonInterleaved;                // 32 bit floating point output
00331     inputParameters.suggestedLatency = (fInputDevice != paNoDevice)             // TODO: check how to setup this on ASIO
00332                                        ? Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency
00333                                        : 0;
00334     inputParameters.hostApiSpecificStreamInfo = NULL;
00335 
00336     outputParameters.device = fOutputDevice;
00337     outputParameters.channelCount = outchannels;
00338     outputParameters.sampleFormat = paFloat32 | paNonInterleaved;               // 32 bit floating point output
00339     outputParameters.suggestedLatency = (fOutputDevice != paNoDevice)   // TODO: check how to setup this on ASIO
00340                                         ? Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency
00341                                         : 0;
00342     outputParameters.hostApiSpecificStreamInfo = NULL;
00343 
00344     err = Pa_OpenStream(&fStream,
00345                         (fInputDevice == paNoDevice) ? 0 : &inputParameters,
00346                         (fOutputDevice == paNoDevice) ? 0 : &outputParameters,
00347                         samplerate,
00348                         nframes,
00349                         paNoFlag,  // Clipping is on...
00350                         Render,
00351                         this);
00352     if (err != paNoError) {
00353         jack_error("Pa_OpenStream error = %s\n", Pa_GetErrorText(err));
00354         goto error;
00355     }
00356 
00357 #ifdef __APPLE__
00358     fEngineControl->fPeriod = fEngineControl->fPeriodUsecs * 1000;
00359     fEngineControl->fComputation = 500 * 1000;
00360     fEngineControl->fConstraint = fEngineControl->fPeriodUsecs * 1000;
00361 #endif
00362 
00363     // Core driver may have changed the in/out values
00364     fCaptureChannels = inchannels;
00365     fPlaybackChannels = outchannels;
00366 
00367     assert(strlen(capture_driver_uid) < JACK_CLIENT_NAME_SIZE);
00368     assert(strlen(playback_driver_uid) < JACK_CLIENT_NAME_SIZE);
00369 
00370     strcpy(fCaptureDriverName, capture_driver_uid);
00371     strcpy(fPlaybackDriverName, playback_driver_uid);
00372 
00373     return 0;
00374 
00375 error:
00376     Pa_Terminate();
00377     return -1;
00378 }
00379 
00380 int JackPortAudioDriver::Close()
00381 {
00382     JackAudioDriver::Close();
00383         JackLog("JackPortAudioDriver::Close\n");
00384     Pa_CloseStream(fStream);
00385     Pa_Terminate();
00386     return 0;
00387 }
00388 
00389 int JackPortAudioDriver::Start()
00390 {
00391     JackLog("JackPortAudioDriver::Start\n");
00392     JackAudioDriver::Start();
00393     PaError err = Pa_StartStream(fStream);
00394     return (err == paNoError) ? 0 : -1;
00395 }
00396 
00397 int JackPortAudioDriver::Stop()
00398 {
00399     JackLog("JackPortAudioDriver::Stop\n");
00400     PaError err = Pa_StopStream(fStream);
00401     return (err == paNoError) ? 0 : -1;
00402 }
00403 
00404 int JackPortAudioDriver::SetBufferSize(jack_nframes_t buffer_size)
00405 {
00406     PaError err;
00407     PaStreamParameters inputParameters;
00408     PaStreamParameters outputParameters;
00409 
00410     if ((err = Pa_CloseStream(fStream)) != paNoError) {
00411         jack_error("Pa_CloseStream error = %s\n", Pa_GetErrorText(err));
00412         return -1;
00413     }
00414 
00415     inputParameters.device = fInputDevice;
00416     inputParameters.channelCount = fCaptureChannels;
00417     inputParameters.sampleFormat = paFloat32 | paNonInterleaved;                // 32 bit floating point output
00418     inputParameters.suggestedLatency = (fInputDevice != paNoDevice)             // TODO: check how to setup this on ASIO
00419                                        ? Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency
00420                                        : 0;
00421     inputParameters.hostApiSpecificStreamInfo = NULL;
00422 
00423     outputParameters.device = fOutputDevice;
00424     outputParameters.channelCount = fPlaybackChannels;
00425     outputParameters.sampleFormat = paFloat32 | paNonInterleaved;               // 32 bit floating point output
00426     outputParameters.suggestedLatency = (fOutputDevice != paNoDevice)   // TODO: check how to setup this on ASIO
00427                                         ? Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency
00428                                         : 0;
00429     outputParameters.hostApiSpecificStreamInfo = NULL;
00430 
00431     err = Pa_OpenStream(&fStream,
00432                         (fInputDevice == paNoDevice) ? 0 : &inputParameters,
00433                         (fOutputDevice == paNoDevice) ? 0 : &outputParameters,
00434                         fEngineControl->fSampleRate,
00435                         buffer_size,
00436                         paNoFlag,  // Clipping is on...
00437                         Render,
00438                         this);
00439     if (err != paNoError) {
00440         jack_error("Pa_OpenStream error = %s\n", Pa_GetErrorText(err));
00441         return -1;
00442     } else {
00443         return JackAudioDriver::SetBufferSize(buffer_size); // never fails;
00444     }
00445 }
00446 
00447 } // end of namespace
00448 
00449 #ifdef __cplusplus
00450 extern "C"
00451 {
00452 #endif
00453 
00454 #include "JackExports.h"
00455 
00456     EXPORT jack_driver_desc_t* driver_get_descriptor() {
00457         jack_driver_desc_t *desc;
00458         unsigned int i;
00459         desc = (jack_driver_desc_t*)calloc(1, sizeof(jack_driver_desc_t));
00460 
00461         strcpy(desc->name, "portaudio");
00462 
00463         desc->nparams = 13;
00464         desc->params = (jack_driver_param_desc_t*)calloc(desc->nparams, sizeof(jack_driver_param_desc_t));
00465 
00466         i = 0;
00467         strcpy(desc->params[i].name, "channels");
00468         desc->params[i].character = 'c';
00469         desc->params[i].type = JackDriverParamInt;
00470         desc->params[i].value.ui = 0;
00471         strcpy(desc->params[i].short_desc, "Maximum number of channels");
00472         strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
00473 
00474         i++;
00475         strcpy(desc->params[i].name, "inchannels");
00476         desc->params[i].character = 'i';
00477         desc->params[i].type = JackDriverParamInt;
00478         desc->params[i].value.ui = 0;
00479         strcpy(desc->params[i].short_desc, "Maximum number of input channels");
00480         strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
00481 
00482         i++;
00483         strcpy(desc->params[i].name, "outchannels");
00484         desc->params[i].character = 'o';
00485         desc->params[i].type = JackDriverParamInt;
00486         desc->params[i].value.ui = 0;
00487         strcpy(desc->params[i].short_desc, "Maximum number of output channels");
00488         strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
00489 
00490         i++;
00491         strcpy(desc->params[i].name, "capture");
00492         desc->params[i].character = 'C';
00493         desc->params[i].type = JackDriverParamString;
00494         strcpy(desc->params[i].value.str, "will take default PortAudio input device");
00495         strcpy(desc->params[i].short_desc, "Provide capture ports. Optionally set PortAudio device name");
00496         strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
00497 
00498         i++;
00499         strcpy(desc->params[i].name, "playback");
00500         desc->params[i].character = 'P';
00501         desc->params[i].type = JackDriverParamString;
00502         strcpy(desc->params[i].value.str, "will take default PortAudio output device");
00503         strcpy(desc->params[i].short_desc, "Provide playback ports. Optionally set PortAudio device name");
00504         strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
00505 
00506         i++;
00507         strcpy (desc->params[i].name, "monitor");
00508         desc->params[i].character = 'm';
00509         desc->params[i].type = JackDriverParamBool;
00510         desc->params[i].value.i = 0;
00511         strcpy(desc->params[i].short_desc, "Provide monitor ports for the output");
00512         strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
00513 
00514         i++;
00515         strcpy(desc->params[i].name, "duplex");
00516         desc->params[i].character = 'D';
00517         desc->params[i].type = JackDriverParamBool;
00518         desc->params[i].value.i = TRUE;
00519         strcpy(desc->params[i].short_desc, "Provide both capture and playback ports");
00520         strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
00521 
00522         i++;
00523         strcpy(desc->params[i].name, "rate");
00524         desc->params[i].character = 'r';
00525         desc->params[i].type = JackDriverParamUInt;
00526         desc->params[i].value.ui = 44100U;
00527         strcpy(desc->params[i].short_desc, "Sample rate");
00528         strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
00529 
00530         i++;
00531         strcpy(desc->params[i].name, "period");
00532         desc->params[i].character = 'p';
00533         desc->params[i].type = JackDriverParamUInt;
00534         desc->params[i].value.ui = 128U;
00535         strcpy(desc->params[i].short_desc, "Frames per period");
00536         strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
00537 
00538         i++;
00539         strcpy(desc->params[i].name, "device");
00540         desc->params[i].character = 'd';
00541         desc->params[i].type = JackDriverParamString;
00542         desc->params[i].value.ui = 128U;
00543         strcpy(desc->params[i].value.str, "will take default PortAudio device name");
00544         strcpy(desc->params[i].short_desc, "PortAudio device name");
00545         strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
00546 
00547         i++;
00548         strcpy(desc->params[i].name, "input-latency");
00549         desc->params[i].character = 'I';
00550         desc->params[i].type = JackDriverParamUInt;
00551         desc->params[i].value.i = 0;
00552         strcpy(desc->params[i].short_desc, "Extra input latency");
00553         strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
00554 
00555         i++;
00556         strcpy(desc->params[i].name, "output-latency");
00557         desc->params[i].character = 'O';
00558         desc->params[i].type = JackDriverParamUInt;
00559         desc->params[i].value.i = 0;
00560         strcpy(desc->params[i].short_desc, "Extra output latency");
00561         strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
00562 
00563         i++;
00564         strcpy(desc->params[i].name, "list-devices");
00565         desc->params[i].character = 'l';
00566         desc->params[i].type = JackDriverParamBool;
00567         desc->params[i].value.i = TRUE;
00568         strcpy(desc->params[i].short_desc, "Display available PortAudio devices");
00569         strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
00570 
00571         return desc;
00572     }
00573 
00574     EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackEngine* engine, Jack::JackSynchro** table, const JSList* params) {
00575         jack_nframes_t srate = 44100;
00576         jack_nframes_t frames_per_interrupt = 512;
00577         int capture = FALSE;
00578         int playback = FALSE;
00579         int chan_in = 0;
00580         int chan_out = 0;
00581         bool monitor = false;
00582         char* capture_pcm_name = "winmme";
00583         char* playback_pcm_name = "winmme";
00584         const JSList *node;
00585         const jack_driver_param_t *param;
00586         jack_nframes_t systemic_input_latency = 0;
00587         jack_nframes_t systemic_output_latency = 0;
00588 
00589         for (node = params; node; node = jack_slist_next(node)) {
00590             param = (const jack_driver_param_t *) node->data;
00591 
00592             switch (param->character) {
00593 
00594                 case 'd':
00595                     capture_pcm_name = strdup(param->value.str);
00596                     playback_pcm_name = strdup(param->value.str);
00597                     break;
00598 
00599                 case 'D':
00600                     capture = TRUE;
00601                     playback = TRUE;
00602                     break;
00603 
00604                 case 'c':
00605                     chan_in = chan_out = (int) param->value.ui;
00606                     break;
00607 
00608                 case 'i':
00609                     chan_in = (int) param->value.ui;
00610                     break;
00611 
00612                 case 'o':
00613                     chan_out = (int) param->value.ui;
00614                     break;
00615 
00616                 case 'C':
00617                     capture = TRUE;
00618                     if (strcmp(param->value.str, "none") != 0) {
00619                         capture_pcm_name = strdup(param->value.str);
00620                     }
00621                     break;
00622 
00623                 case 'P':
00624                     playback = TRUE;
00625                     if (strcmp(param->value.str, "none") != 0) {
00626                         playback_pcm_name = strdup(param->value.str);
00627                     }
00628                     break;
00629 
00630                 case 'm':
00631                     monitor = param->value.i;
00632                     break;
00633 
00634                 case 'r':
00635                     srate = param->value.ui;
00636                     break;
00637 
00638                 case 'p':
00639                     frames_per_interrupt = (unsigned int) param->value.ui;
00640                     break;
00641 
00642                 case 'I':
00643                     systemic_input_latency = param->value.ui;
00644                     break;
00645 
00646                 case 'O':
00647                     systemic_output_latency = param->value.ui;
00648                     break;
00649 
00650                 case 'l':
00651                     Jack::DisplayDeviceNames();
00652                     break;
00653             }
00654         }
00655 
00656         // duplex is the default
00657         if (!capture && !playback) {
00658             capture = TRUE;
00659             playback = TRUE;
00660         }
00661 
00662         Jack::JackDriverClientInterface* driver = new Jack::JackPortAudioDriver("portaudio", engine, table);
00663         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) {
00664             return driver;
00665         } else {
00666             delete driver;
00667             return NULL;
00668         }
00669     }
00670 
00671 #ifdef __cplusplus
00672 }
00673 #endif

Generated on Mon Oct 15 17:11:14 2007 for Jackdmp by  doxygen 1.5.1