jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

671 lines
25KB

  1. /*
  2. Copyright (C) 2004-2008 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #ifdef WIN32
  16. #pragma warning (disable : 4786)
  17. #endif
  18. #include "pa_asio.h"
  19. #include "JackDriverLoader.h"
  20. #include "driver_interface.h"
  21. #include "JackPortAudioDriver.h"
  22. #include "JackEngineControl.h"
  23. #include "JackError.h"
  24. #include "JackTime.h"
  25. #include <iostream>
  26. #include <assert.h>
  27. namespace Jack
  28. {
  29. void JackPortAudioDriver::PrintSupportedStandardSampleRates(const PaStreamParameters* inputParameters, const PaStreamParameters* outputParameters)
  30. {
  31. static double standardSampleRates[] = {
  32. 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0,
  33. 44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1 /* negative terminated list */
  34. };
  35. int i, printCount;
  36. PaError err;
  37. printCount = 0;
  38. for (i = 0; standardSampleRates[i] > 0; i++) {
  39. err = Pa_IsFormatSupported(inputParameters, outputParameters, standardSampleRates[i]);
  40. if (err == paFormatIsSupported) {
  41. if (printCount == 0) {
  42. printf("\t%8.2f", standardSampleRates[i]);
  43. printCount = 1;
  44. } else if (printCount == 4) {
  45. printf(",\n\t%8.2f", standardSampleRates[i]);
  46. printCount = 1;
  47. } else {
  48. printf(", %8.2f", standardSampleRates[i]);
  49. ++printCount;
  50. }
  51. }
  52. }
  53. if (!printCount)
  54. printf("None\n");
  55. else
  56. printf("\n");
  57. }
  58. bool JackPortAudioDriver::GetInputDeviceFromName(const char* name, PaDeviceIndex* device, int* in_max)
  59. {
  60. const PaDeviceInfo* deviceInfo;
  61. PaDeviceIndex numDevices = Pa_GetDeviceCount();
  62. for (int i = 0; i < numDevices; i++) {
  63. deviceInfo = Pa_GetDeviceInfo(i);
  64. if (strcmp(name, deviceInfo->name) == 0) {
  65. *device = i;
  66. *in_max = deviceInfo->maxInputChannels;
  67. return true;
  68. }
  69. }
  70. return false;
  71. }
  72. bool JackPortAudioDriver::GetOutputDeviceFromName(const char* name, PaDeviceIndex* device, int* out_max)
  73. {
  74. const PaDeviceInfo* deviceInfo;
  75. PaDeviceIndex numDevices = Pa_GetDeviceCount();
  76. for (int i = 0; i < numDevices; i++) {
  77. deviceInfo = Pa_GetDeviceInfo(i);
  78. if (strcmp(name, deviceInfo->name) == 0) {
  79. *device = i;
  80. *out_max = deviceInfo->maxOutputChannels;
  81. return true;
  82. }
  83. }
  84. return false;
  85. }
  86. static void DisplayDeviceNames()
  87. {
  88. PaError err;
  89. const PaDeviceInfo* deviceInfo;
  90. PaStreamParameters inputParameters, outputParameters;
  91. int defaultDisplayed;
  92. err = Pa_Initialize();
  93. if (err != paNoError)
  94. return ;
  95. PaDeviceIndex numDevices = Pa_GetDeviceCount();
  96. printf("Number of devices = %d\n", numDevices);
  97. for (int i = 0; i < numDevices; i++) {
  98. deviceInfo = Pa_GetDeviceInfo(i);
  99. printf( "--------------------------------------- device #%d\n", i );
  100. /* Mark global and API specific default devices */
  101. defaultDisplayed = 0;
  102. if (i == Pa_GetDefaultInputDevice()) {
  103. printf("[ Default Input");
  104. defaultDisplayed = 1;
  105. } else if (i == Pa_GetHostApiInfo(deviceInfo->hostApi)->defaultInputDevice) {
  106. const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
  107. printf("[ Default %s Input", hostInfo->name);
  108. defaultDisplayed = 1;
  109. }
  110. if (i == Pa_GetDefaultOutputDevice()) {
  111. printf((defaultDisplayed ? "," : "["));
  112. printf(" Default Output");
  113. defaultDisplayed = 1;
  114. } else if (i == Pa_GetHostApiInfo(deviceInfo->hostApi)->defaultOutputDevice) {
  115. const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
  116. printf((defaultDisplayed ? "," : "["));
  117. printf(" Default %s Output", hostInfo->name);
  118. defaultDisplayed = 1;
  119. }
  120. if (defaultDisplayed)
  121. printf(" ]\n");
  122. /* print device info fields */
  123. printf("Name = %s\n", deviceInfo->name);
  124. printf("Host API = %s\n", Pa_GetHostApiInfo(deviceInfo->hostApi)->name);
  125. printf("Max inputs = %d", deviceInfo->maxInputChannels);
  126. printf(", Max outputs = %d\n", deviceInfo->maxOutputChannels);
  127. /*
  128. printf("Default low input latency = %8.3f\n", deviceInfo->defaultLowInputLatency);
  129. printf("Default low output latency = %8.3f\n", deviceInfo->defaultLowOutputLatency);
  130. printf("Default high input latency = %8.3f\n", deviceInfo->defaultHighInputLatency);
  131. printf("Default high output latency = %8.3f\n", deviceInfo->defaultHighOutputLatency);
  132. */
  133. #ifdef WIN32
  134. #ifndef PA_NO_ASIO
  135. /* ASIO specific latency information */
  136. if (Pa_GetHostApiInfo(deviceInfo->hostApi)->type == paASIO) {
  137. long minLatency, maxLatency, preferredLatency, granularity;
  138. err = PaAsio_GetAvailableLatencyValues(i, &minLatency, &maxLatency, &preferredLatency, &granularity);
  139. printf("ASIO minimum buffer size = %ld\n", minLatency);
  140. printf("ASIO maximum buffer size = %ld\n", maxLatency);
  141. printf("ASIO preferred buffer size = %ld\n", preferredLatency);
  142. if (granularity == -1)
  143. printf("ASIO buffer granularity = power of 2\n");
  144. else
  145. printf("ASIO buffer granularity = %ld\n", granularity);
  146. }
  147. #endif /* !PA_NO_ASIO */
  148. #endif /* WIN32 */
  149. printf("Default sample rate = %8.2f\n", deviceInfo->defaultSampleRate);
  150. /* poll for standard sample rates */
  151. inputParameters.device = i;
  152. inputParameters.channelCount = deviceInfo->maxInputChannels;
  153. inputParameters.sampleFormat = paInt16;
  154. inputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
  155. inputParameters.hostApiSpecificStreamInfo = NULL;
  156. outputParameters.device = i;
  157. outputParameters.channelCount = deviceInfo->maxOutputChannels;
  158. outputParameters.sampleFormat = paInt16;
  159. outputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
  160. outputParameters.hostApiSpecificStreamInfo = NULL;
  161. /*
  162. if (inputParameters.channelCount > 0) {
  163. printf("Supported standard sample rates\n for half-duplex 16 bit %d channel input = \n", inputParameters.channelCount);
  164. PrintSupportedStandardSampleRates(&inputParameters, NULL);
  165. }
  166. if (outputParameters.channelCount > 0) {
  167. printf("Supported standard sample rates\n for half-duplex 16 bit %d channel output = \n", outputParameters.channelCount);
  168. PrintSupportedStandardSampleRates(NULL, &outputParameters);
  169. }
  170. if (inputParameters.channelCount > 0 && outputParameters.channelCount > 0) {
  171. printf("Supported standard sample rates\n for full-duplex 16 bit %d channel input, %d channel output = \n",
  172. inputParameters.channelCount, outputParameters.channelCount );
  173. PrintSupportedStandardSampleRates(&inputParameters, &outputParameters);
  174. }
  175. */
  176. }
  177. Pa_Terminate();
  178. }
  179. int JackPortAudioDriver::Render(const void* inputBuffer, void* outputBuffer,
  180. unsigned long framesPerBuffer,
  181. const PaStreamCallbackTimeInfo* timeInfo,
  182. PaStreamCallbackFlags statusFlags,
  183. void* userData)
  184. {
  185. JackPortAudioDriver* driver = (JackPortAudioDriver*)userData;
  186. driver->fLastWaitUst = GetMicroSeconds(); // Take callback date here
  187. driver->fInputBuffer = (float**)inputBuffer;
  188. driver->fOutputBuffer = (float**)outputBuffer;
  189. return (driver->Process() == 0) ? paContinue : paAbort;
  190. }
  191. int JackPortAudioDriver::Read()
  192. {
  193. for (int i = 0; i < fCaptureChannels; i++) {
  194. memcpy(GetInputBuffer(i), fInputBuffer[i], sizeof(float) * fEngineControl->fBufferSize);
  195. }
  196. return 0;
  197. }
  198. int JackPortAudioDriver::Write()
  199. {
  200. for (int i = 0; i < fPlaybackChannels; i++) {
  201. memcpy(fOutputBuffer[i], GetOutputBuffer(i), sizeof(float) * fEngineControl->fBufferSize);
  202. }
  203. return 0;
  204. }
  205. int JackPortAudioDriver::Open(jack_nframes_t nframes,
  206. jack_nframes_t samplerate,
  207. bool capturing,
  208. bool playing,
  209. int inchannels,
  210. int outchannels,
  211. bool monitor,
  212. const char* capture_driver_uid,
  213. const char* playback_driver_uid,
  214. jack_nframes_t capture_latency,
  215. jack_nframes_t playback_latency)
  216. {
  217. PaError err;
  218. PaStreamParameters inputParameters;
  219. PaStreamParameters outputParameters;
  220. const PaDeviceInfo* deviceInfo;
  221. int in_max = 0;
  222. int out_max = 0;
  223. jack_log("JackPortAudioDriver::Open nframes = %ld in = %ld out = %ld capture name = %s playback name = %s samplerate = %ld",
  224. nframes, inchannels, outchannels, capture_driver_uid, playback_driver_uid, samplerate);
  225. // Generic JackAudioDriver Open
  226. if (JackAudioDriver::Open(nframes, samplerate, capturing, playing, inchannels, outchannels, monitor, capture_driver_uid, playback_driver_uid, capture_latency, playback_latency) != 0) {
  227. return -1;
  228. }
  229. err = Pa_Initialize();
  230. if (err != paNoError) {
  231. jack_error("JackPortAudioDriver::Pa_Initialize error = %s\n", Pa_GetErrorText(err));
  232. goto error;
  233. }
  234. jack_log("JackPortAudioDriver::Pa_GetDefaultInputDevice %ld", Pa_GetDefaultInputDevice());
  235. jack_log("JackPortAudioDriver::Pa_GetDefaultOutputDevice %ld", Pa_GetDefaultOutputDevice());
  236. if (capturing) {
  237. if (!GetInputDeviceFromName(capture_driver_uid, &fInputDevice, &in_max)) {
  238. jack_log("JackPortAudioDriver::GetInputDeviceFromName cannot open %s", capture_driver_uid);
  239. fInputDevice = Pa_GetDefaultInputDevice();
  240. if (fInputDevice == paNoDevice)
  241. goto error;
  242. deviceInfo = Pa_GetDeviceInfo(fInputDevice);
  243. in_max = deviceInfo->maxInputChannels;
  244. capture_driver_uid = strdup(deviceInfo->name);
  245. }
  246. }
  247. if (inchannels > in_max) {
  248. jack_error("This device hasn't required input channels inchannels = %ld in_max = %ld", inchannels, in_max);
  249. goto error;
  250. }
  251. if (playing) {
  252. if (!GetOutputDeviceFromName(playback_driver_uid, &fOutputDevice, &out_max)) {
  253. jack_log("JackPortAudioDriver::GetOutputDeviceFromName cannot open %s", playback_driver_uid);
  254. fOutputDevice = Pa_GetDefaultOutputDevice();
  255. if (fOutputDevice == paNoDevice)
  256. goto error;
  257. deviceInfo = Pa_GetDeviceInfo(fOutputDevice);
  258. out_max = deviceInfo->maxOutputChannels;
  259. playback_driver_uid = strdup(deviceInfo->name);
  260. }
  261. }
  262. if (outchannels > out_max) {
  263. jack_error("This device hasn't required output channels outchannels = %ld out_max = %ld", outchannels, out_max);
  264. goto error;
  265. }
  266. if (inchannels == 0) {
  267. jack_log("JackPortAudioDriver::Open setup max in channels = %ld", in_max);
  268. inchannels = in_max;
  269. }
  270. if (outchannels == 0) {
  271. jack_log("JackPortAudioDriver::Open setup max out channels = %ld", out_max);
  272. outchannels = out_max;
  273. }
  274. inputParameters.device = fInputDevice;
  275. inputParameters.channelCount = inchannels;
  276. inputParameters.sampleFormat = paFloat32 | paNonInterleaved; // 32 bit floating point output
  277. inputParameters.suggestedLatency = (fInputDevice != paNoDevice) // TODO: check how to setup this on ASIO
  278. ? Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency
  279. : 0;
  280. inputParameters.hostApiSpecificStreamInfo = NULL;
  281. outputParameters.device = fOutputDevice;
  282. outputParameters.channelCount = outchannels;
  283. outputParameters.sampleFormat = paFloat32 | paNonInterleaved; // 32 bit floating point output
  284. outputParameters.suggestedLatency = (fOutputDevice != paNoDevice) // TODO: check how to setup this on ASIO
  285. ? Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency
  286. : 0;
  287. outputParameters.hostApiSpecificStreamInfo = NULL;
  288. err = Pa_OpenStream(&fStream,
  289. (fInputDevice == paNoDevice) ? 0 : &inputParameters,
  290. (fOutputDevice == paNoDevice) ? 0 : &outputParameters,
  291. samplerate,
  292. nframes,
  293. paNoFlag, // Clipping is on...
  294. Render,
  295. this);
  296. if (err != paNoError) {
  297. jack_error("Pa_OpenStream error = %s\n", Pa_GetErrorText(err));
  298. goto error;
  299. }
  300. #ifdef __APPLE__
  301. fEngineControl->fPeriod = fEngineControl->fPeriodUsecs * 1000;
  302. fEngineControl->fComputation = 500 * 1000;
  303. fEngineControl->fConstraint = fEngineControl->fPeriodUsecs * 1000;
  304. #endif
  305. // Core driver may have changed the in/out values
  306. fCaptureChannels = inchannels;
  307. fPlaybackChannels = outchannels;
  308. assert(strlen(capture_driver_uid) < JACK_CLIENT_NAME_SIZE);
  309. assert(strlen(playback_driver_uid) < JACK_CLIENT_NAME_SIZE);
  310. strcpy(fCaptureDriverName, capture_driver_uid);
  311. strcpy(fPlaybackDriverName, playback_driver_uid);
  312. return 0;
  313. error:
  314. Pa_Terminate();
  315. return -1;
  316. }
  317. int JackPortAudioDriver::Close()
  318. {
  319. JackAudioDriver::Close();
  320. jack_log("JackPortAudioDriver::Close");
  321. Pa_CloseStream(fStream);
  322. Pa_Terminate();
  323. return 0;
  324. }
  325. int JackPortAudioDriver::Start()
  326. {
  327. jack_log("JackPortAudioDriver::Start");
  328. JackAudioDriver::Start();
  329. PaError err = Pa_StartStream(fStream);
  330. return (err == paNoError) ? 0 : -1;
  331. }
  332. int JackPortAudioDriver::Stop()
  333. {
  334. jack_log("JackPortAudioDriver::Stop");
  335. PaError err = Pa_StopStream(fStream);
  336. return (err == paNoError) ? 0 : -1;
  337. }
  338. int JackPortAudioDriver::SetBufferSize(jack_nframes_t buffer_size)
  339. {
  340. PaError err;
  341. PaStreamParameters inputParameters;
  342. PaStreamParameters outputParameters;
  343. if ((err = Pa_CloseStream(fStream)) != paNoError) {
  344. jack_error("Pa_CloseStream error = %s\n", Pa_GetErrorText(err));
  345. return -1;
  346. }
  347. inputParameters.device = fInputDevice;
  348. inputParameters.channelCount = fCaptureChannels;
  349. inputParameters.sampleFormat = paFloat32 | paNonInterleaved; // 32 bit floating point output
  350. inputParameters.suggestedLatency = (fInputDevice != paNoDevice) // TODO: check how to setup this on ASIO
  351. ? Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency
  352. : 0;
  353. inputParameters.hostApiSpecificStreamInfo = NULL;
  354. outputParameters.device = fOutputDevice;
  355. outputParameters.channelCount = fPlaybackChannels;
  356. outputParameters.sampleFormat = paFloat32 | paNonInterleaved; // 32 bit floating point output
  357. outputParameters.suggestedLatency = (fOutputDevice != paNoDevice) // TODO: check how to setup this on ASIO
  358. ? Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency
  359. : 0;
  360. outputParameters.hostApiSpecificStreamInfo = NULL;
  361. err = Pa_OpenStream(&fStream,
  362. (fInputDevice == paNoDevice) ? 0 : &inputParameters,
  363. (fOutputDevice == paNoDevice) ? 0 : &outputParameters,
  364. fEngineControl->fSampleRate,
  365. buffer_size,
  366. paNoFlag, // Clipping is on...
  367. Render,
  368. this);
  369. if (err != paNoError) {
  370. jack_error("Pa_OpenStream error = %s\n", Pa_GetErrorText(err));
  371. return -1;
  372. } else {
  373. // Only done when success
  374. return JackAudioDriver::SetBufferSize(buffer_size); // never fails
  375. }
  376. }
  377. } // end of namespace
  378. #ifdef __cplusplus
  379. extern "C"
  380. {
  381. #endif
  382. #include "JackExports.h"
  383. EXPORT jack_driver_desc_t* driver_get_descriptor() {
  384. jack_driver_desc_t *desc;
  385. unsigned int i;
  386. desc = (jack_driver_desc_t*)calloc(1, sizeof(jack_driver_desc_t));
  387. strcpy(desc->name, "portaudio");
  388. desc->nparams = 13;
  389. desc->params = (jack_driver_param_desc_t*)calloc(desc->nparams, sizeof(jack_driver_param_desc_t));
  390. i = 0;
  391. strcpy(desc->params[i].name, "channels");
  392. desc->params[i].character = 'c';
  393. desc->params[i].type = JackDriverParamInt;
  394. desc->params[i].value.ui = 0;
  395. strcpy(desc->params[i].short_desc, "Maximum number of channels");
  396. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  397. i++;
  398. strcpy(desc->params[i].name, "inchannels");
  399. desc->params[i].character = 'i';
  400. desc->params[i].type = JackDriverParamInt;
  401. desc->params[i].value.ui = 0;
  402. strcpy(desc->params[i].short_desc, "Maximum number of input channels");
  403. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  404. i++;
  405. strcpy(desc->params[i].name, "outchannels");
  406. desc->params[i].character = 'o';
  407. desc->params[i].type = JackDriverParamInt;
  408. desc->params[i].value.ui = 0;
  409. strcpy(desc->params[i].short_desc, "Maximum number of output channels");
  410. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  411. i++;
  412. strcpy(desc->params[i].name, "capture");
  413. desc->params[i].character = 'C';
  414. desc->params[i].type = JackDriverParamString;
  415. strcpy(desc->params[i].value.str, "will take default PortAudio input device");
  416. strcpy(desc->params[i].short_desc, "Provide capture ports. Optionally set PortAudio device name");
  417. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  418. i++;
  419. strcpy(desc->params[i].name, "playback");
  420. desc->params[i].character = 'P';
  421. desc->params[i].type = JackDriverParamString;
  422. strcpy(desc->params[i].value.str, "will take default PortAudio output device");
  423. strcpy(desc->params[i].short_desc, "Provide playback ports. Optionally set PortAudio device name");
  424. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  425. i++;
  426. strcpy (desc->params[i].name, "monitor");
  427. desc->params[i].character = 'm';
  428. desc->params[i].type = JackDriverParamBool;
  429. desc->params[i].value.i = 0;
  430. strcpy(desc->params[i].short_desc, "Provide monitor ports for the output");
  431. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  432. i++;
  433. strcpy(desc->params[i].name, "duplex");
  434. desc->params[i].character = 'D';
  435. desc->params[i].type = JackDriverParamBool;
  436. desc->params[i].value.i = TRUE;
  437. strcpy(desc->params[i].short_desc, "Provide both capture and playback ports");
  438. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  439. i++;
  440. strcpy(desc->params[i].name, "rate");
  441. desc->params[i].character = 'r';
  442. desc->params[i].type = JackDriverParamUInt;
  443. desc->params[i].value.ui = 44100U;
  444. strcpy(desc->params[i].short_desc, "Sample rate");
  445. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  446. i++;
  447. strcpy(desc->params[i].name, "period");
  448. desc->params[i].character = 'p';
  449. desc->params[i].type = JackDriverParamUInt;
  450. desc->params[i].value.ui = 128U;
  451. strcpy(desc->params[i].short_desc, "Frames per period");
  452. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  453. i++;
  454. strcpy(desc->params[i].name, "device");
  455. desc->params[i].character = 'd';
  456. desc->params[i].type = JackDriverParamString;
  457. desc->params[i].value.ui = 128U;
  458. strcpy(desc->params[i].value.str, "will take default PortAudio device name");
  459. strcpy(desc->params[i].short_desc, "PortAudio device name");
  460. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  461. i++;
  462. strcpy(desc->params[i].name, "input-latency");
  463. desc->params[i].character = 'I';
  464. desc->params[i].type = JackDriverParamUInt;
  465. desc->params[i].value.i = 0;
  466. strcpy(desc->params[i].short_desc, "Extra input latency");
  467. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  468. i++;
  469. strcpy(desc->params[i].name, "output-latency");
  470. desc->params[i].character = 'O';
  471. desc->params[i].type = JackDriverParamUInt;
  472. desc->params[i].value.i = 0;
  473. strcpy(desc->params[i].short_desc, "Extra output latency");
  474. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  475. i++;
  476. strcpy(desc->params[i].name, "list-devices");
  477. desc->params[i].character = 'l';
  478. desc->params[i].type = JackDriverParamBool;
  479. desc->params[i].value.i = TRUE;
  480. strcpy(desc->params[i].short_desc, "Display available PortAudio devices");
  481. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  482. return desc;
  483. }
  484. EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackEngine* engine, Jack::JackSynchro** table, const JSList* params) {
  485. jack_nframes_t srate = 44100;
  486. jack_nframes_t frames_per_interrupt = 512;
  487. int capture = FALSE;
  488. int playback = FALSE;
  489. int chan_in = 0;
  490. int chan_out = 0;
  491. bool monitor = false;
  492. char* capture_pcm_name = "winmme";
  493. char* playback_pcm_name = "winmme";
  494. const JSList *node;
  495. const jack_driver_param_t *param;
  496. jack_nframes_t systemic_input_latency = 0;
  497. jack_nframes_t systemic_output_latency = 0;
  498. for (node = params; node; node = jack_slist_next(node)) {
  499. param = (const jack_driver_param_t *) node->data;
  500. switch (param->character) {
  501. case 'd':
  502. capture_pcm_name = strdup(param->value.str);
  503. playback_pcm_name = strdup(param->value.str);
  504. break;
  505. case 'D':
  506. capture = TRUE;
  507. playback = TRUE;
  508. break;
  509. case 'c':
  510. chan_in = chan_out = (int) param->value.ui;
  511. break;
  512. case 'i':
  513. chan_in = (int) param->value.ui;
  514. break;
  515. case 'o':
  516. chan_out = (int) param->value.ui;
  517. break;
  518. case 'C':
  519. capture = TRUE;
  520. if (strcmp(param->value.str, "none") != 0) {
  521. capture_pcm_name = strdup(param->value.str);
  522. }
  523. break;
  524. case 'P':
  525. playback = TRUE;
  526. if (strcmp(param->value.str, "none") != 0) {
  527. playback_pcm_name = strdup(param->value.str);
  528. }
  529. break;
  530. case 'm':
  531. monitor = param->value.i;
  532. break;
  533. case 'r':
  534. srate = param->value.ui;
  535. break;
  536. case 'p':
  537. frames_per_interrupt = (unsigned int) param->value.ui;
  538. break;
  539. case 'I':
  540. systemic_input_latency = param->value.ui;
  541. break;
  542. case 'O':
  543. systemic_output_latency = param->value.ui;
  544. break;
  545. case 'l':
  546. Jack::DisplayDeviceNames();
  547. break;
  548. }
  549. }
  550. // duplex is the default
  551. if (!capture && !playback) {
  552. capture = TRUE;
  553. playback = TRUE;
  554. }
  555. Jack::JackDriverClientInterface* driver = new Jack::JackPortAudioDriver("system", "portaudio", engine, table);
  556. 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) {
  557. return driver;
  558. } else {
  559. delete driver;
  560. return NULL;
  561. }
  562. }
  563. #ifdef __cplusplus
  564. }
  565. #endif