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.

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