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.

676 lines
25KB

  1. /*
  2. Copyright (C) 2004-2006 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. #ifdef __APPLE__
  19. #include "JackMachThread.h"
  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 "JackGraphManager.h"
  27. #include "JackError.h"
  28. #include "JackClientControl.h"
  29. #include "JackGlobals.h"
  30. #include <iostream>
  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->fLastWaitUst = GetMicroSeconds(); // Take callback date here
  191. driver->fInputBuffer = (float**)inputBuffer;
  192. driver->fOutputBuffer = (float**)outputBuffer;
  193. return (driver->Process() == 0) ? paContinue : paAbort;
  194. }
  195. int JackPortAudioDriver::Read()
  196. {
  197. for (int i = 0; i < fCaptureChannels; i++) {
  198. memcpy(GetInputBuffer(i), fInputBuffer[i], sizeof(float) * fEngineControl->fBufferSize);
  199. }
  200. return 0;
  201. }
  202. int JackPortAudioDriver::Write()
  203. {
  204. for (int i = 0; i < fPlaybackChannels; i++) {
  205. memcpy(fOutputBuffer[i], GetOutputBuffer(i), sizeof(float) * fEngineControl->fBufferSize);
  206. }
  207. return 0;
  208. }
  209. int JackPortAudioDriver::Open(jack_nframes_t nframes,
  210. jack_nframes_t samplerate,
  211. bool capturing,
  212. bool playing,
  213. int inchannels,
  214. int outchannels,
  215. bool monitor,
  216. const char* capture_driver_uid,
  217. const char* playback_driver_uid,
  218. jack_nframes_t capture_latency,
  219. jack_nframes_t playback_latency)
  220. {
  221. PaError err;
  222. PaStreamParameters inputParameters;
  223. PaStreamParameters outputParameters;
  224. const PaDeviceInfo* deviceInfo;
  225. int in_max = 0;
  226. int out_max = 0;
  227. JackLog("JackPortAudioDriver::Open nframes = %ld in = %ld out = %ld capture name = %s playback name = %s samplerate = %ld\n",
  228. nframes, inchannels, outchannels, capture_driver_uid, playback_driver_uid, samplerate);
  229. // Generic JackAudioDriver Open
  230. if (JackAudioDriver::Open(nframes, samplerate, capturing, playing, inchannels, outchannels, monitor, capture_driver_uid, playback_driver_uid, capture_latency, playback_latency) != 0) {
  231. return -1;
  232. }
  233. err = Pa_Initialize();
  234. if (err != paNoError) {
  235. jack_error("JackPortAudioDriver::Pa_Initialize error = %s\n", Pa_GetErrorText(err));
  236. goto error;
  237. }
  238. JackLog("JackPortAudioDriver::Pa_GetDefaultInputDevice %ld\n", Pa_GetDefaultInputDevice());
  239. JackLog("JackPortAudioDriver::Pa_GetDefaultOutputDevice %ld\n", Pa_GetDefaultOutputDevice());
  240. if (capturing) {
  241. if (!GetInputDeviceFromName(capture_driver_uid, &fInputDevice, &in_max)) {
  242. JackLog("JackPortAudioDriver::GetInputDeviceFromName cannot open %s\n", capture_driver_uid);
  243. fInputDevice = Pa_GetDefaultInputDevice();
  244. if (fInputDevice == paNoDevice)
  245. goto error;
  246. deviceInfo = Pa_GetDeviceInfo(fInputDevice);
  247. in_max = deviceInfo->maxInputChannels;
  248. capture_driver_uid = strdup(deviceInfo->name);
  249. }
  250. }
  251. if (inchannels > in_max) {
  252. jack_error("This device hasn't required input channels inchannels = %ld in_max = %ld", inchannels, in_max);
  253. goto error;
  254. }
  255. if (playing) {
  256. if (!GetOutputDeviceFromName(playback_driver_uid, &fOutputDevice, &out_max)) {
  257. JackLog("JackPortAudioDriver::GetOutputDeviceFromName cannot open %s\n", playback_driver_uid);
  258. fOutputDevice = Pa_GetDefaultOutputDevice();
  259. if (fOutputDevice == paNoDevice)
  260. goto error;
  261. deviceInfo = Pa_GetDeviceInfo(fOutputDevice);
  262. out_max = deviceInfo->maxOutputChannels;
  263. playback_driver_uid = strdup(deviceInfo->name);
  264. }
  265. }
  266. if (outchannels > out_max) {
  267. jack_error("This device hasn't required output channels outchannels = %ld out_max = %ld", outchannels, out_max);
  268. goto error;
  269. }
  270. if (inchannels == 0) {
  271. JackLog("JackPortAudioDriver::Open setup max in channels = %ld\n", in_max);
  272. inchannels = in_max;
  273. }
  274. if (outchannels == 0) {
  275. JackLog("JackPortAudioDriver::Open setup max out channels = %ld\n", out_max);
  276. outchannels = out_max;
  277. }
  278. inputParameters.device = fInputDevice;
  279. inputParameters.channelCount = inchannels;
  280. inputParameters.sampleFormat = paFloat32 | paNonInterleaved; // 32 bit floating point output
  281. inputParameters.suggestedLatency = (fInputDevice != paNoDevice) // TODO: check how to setup this on ASIO
  282. ? Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency
  283. : 0;
  284. inputParameters.hostApiSpecificStreamInfo = NULL;
  285. outputParameters.device = fOutputDevice;
  286. outputParameters.channelCount = outchannels;
  287. outputParameters.sampleFormat = paFloat32 | paNonInterleaved; // 32 bit floating point output
  288. outputParameters.suggestedLatency = (fOutputDevice != paNoDevice) // TODO: check how to setup this on ASIO
  289. ? Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency
  290. : 0;
  291. outputParameters.hostApiSpecificStreamInfo = NULL;
  292. err = Pa_OpenStream(&fStream,
  293. (fInputDevice == paNoDevice) ? 0 : &inputParameters,
  294. (fOutputDevice == paNoDevice) ? 0 : &outputParameters,
  295. samplerate,
  296. nframes,
  297. paNoFlag, // Clipping is on...
  298. Render,
  299. this);
  300. if (err != paNoError) {
  301. jack_error("Pa_OpenStream error = %s\n", Pa_GetErrorText(err));
  302. goto error;
  303. }
  304. #ifdef __APPLE__
  305. fEngineControl->fPeriod = fEngineControl->fPeriodUsecs * 1000;
  306. fEngineControl->fComputation = 500 * 1000;
  307. fEngineControl->fConstraint = fEngineControl->fPeriodUsecs * 1000;
  308. #endif
  309. // Core driver may have changed the in/out values
  310. fCaptureChannels = inchannels;
  311. fPlaybackChannels = outchannels;
  312. assert(strlen(capture_driver_uid) < JACK_CLIENT_NAME_SIZE);
  313. assert(strlen(playback_driver_uid) < JACK_CLIENT_NAME_SIZE);
  314. strcpy(fCaptureDriverName, capture_driver_uid);
  315. strcpy(fPlaybackDriverName, playback_driver_uid);
  316. return 0;
  317. error:
  318. Pa_Terminate();
  319. return -1;
  320. }
  321. int JackPortAudioDriver::Close()
  322. {
  323. JackAudioDriver::Close();
  324. JackLog("JackPortAudioDriver::Close\n");
  325. Pa_CloseStream(fStream);
  326. Pa_Terminate();
  327. return 0;
  328. }
  329. int JackPortAudioDriver::Start()
  330. {
  331. JackLog("JackPortAudioDriver::Start\n");
  332. JackAudioDriver::Start();
  333. PaError err = Pa_StartStream(fStream);
  334. return (err == paNoError) ? 0 : -1;
  335. }
  336. int JackPortAudioDriver::Stop()
  337. {
  338. JackLog("JackPortAudioDriver::Stop\n");
  339. PaError err = Pa_StopStream(fStream);
  340. return (err == paNoError) ? 0 : -1;
  341. }
  342. int JackPortAudioDriver::SetBufferSize(jack_nframes_t buffer_size)
  343. {
  344. PaError err;
  345. PaStreamParameters inputParameters;
  346. PaStreamParameters outputParameters;
  347. if ((err = Pa_CloseStream(fStream)) != paNoError) {
  348. jack_error("Pa_CloseStream error = %s\n", Pa_GetErrorText(err));
  349. return -1;
  350. }
  351. inputParameters.device = fInputDevice;
  352. inputParameters.channelCount = fCaptureChannels;
  353. inputParameters.sampleFormat = paFloat32 | paNonInterleaved; // 32 bit floating point output
  354. inputParameters.suggestedLatency = (fInputDevice != paNoDevice) // TODO: check how to setup this on ASIO
  355. ? Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency
  356. : 0;
  357. inputParameters.hostApiSpecificStreamInfo = NULL;
  358. outputParameters.device = fOutputDevice;
  359. outputParameters.channelCount = fPlaybackChannels;
  360. outputParameters.sampleFormat = paFloat32 | paNonInterleaved; // 32 bit floating point output
  361. outputParameters.suggestedLatency = (fOutputDevice != paNoDevice) // TODO: check how to setup this on ASIO
  362. ? Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency
  363. : 0;
  364. outputParameters.hostApiSpecificStreamInfo = NULL;
  365. err = Pa_OpenStream(&fStream,
  366. (fInputDevice == paNoDevice) ? 0 : &inputParameters,
  367. (fOutputDevice == paNoDevice) ? 0 : &outputParameters,
  368. fEngineControl->fSampleRate,
  369. buffer_size,
  370. paNoFlag, // Clipping is on...
  371. Render,
  372. this);
  373. if (err != paNoError) {
  374. jack_error("Pa_OpenStream error = %s\n", Pa_GetErrorText(err));
  375. return -1;
  376. } else {
  377. // Only done when success
  378. return JackAudioDriver::SetBufferSize(buffer_size); // never fails
  379. }
  380. }
  381. } // end of namespace
  382. #ifdef __cplusplus
  383. extern "C"
  384. {
  385. #endif
  386. #include "JackExports.h"
  387. EXPORT jack_driver_desc_t* driver_get_descriptor() {
  388. jack_driver_desc_t *desc;
  389. unsigned int i;
  390. desc = (jack_driver_desc_t*)calloc(1, sizeof(jack_driver_desc_t));
  391. strcpy(desc->name, "portaudio");
  392. desc->nparams = 13;
  393. desc->params = (jack_driver_param_desc_t*)calloc(desc->nparams, sizeof(jack_driver_param_desc_t));
  394. i = 0;
  395. strcpy(desc->params[i].name, "channels");
  396. desc->params[i].character = 'c';
  397. desc->params[i].type = JackDriverParamInt;
  398. desc->params[i].value.ui = 0;
  399. strcpy(desc->params[i].short_desc, "Maximum number of channels");
  400. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  401. i++;
  402. strcpy(desc->params[i].name, "inchannels");
  403. desc->params[i].character = 'i';
  404. desc->params[i].type = JackDriverParamInt;
  405. desc->params[i].value.ui = 0;
  406. strcpy(desc->params[i].short_desc, "Maximum number of input channels");
  407. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  408. i++;
  409. strcpy(desc->params[i].name, "outchannels");
  410. desc->params[i].character = 'o';
  411. desc->params[i].type = JackDriverParamInt;
  412. desc->params[i].value.ui = 0;
  413. strcpy(desc->params[i].short_desc, "Maximum number of output channels");
  414. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  415. i++;
  416. strcpy(desc->params[i].name, "capture");
  417. desc->params[i].character = 'C';
  418. desc->params[i].type = JackDriverParamString;
  419. strcpy(desc->params[i].value.str, "will take default PortAudio input device");
  420. strcpy(desc->params[i].short_desc, "Provide capture ports. Optionally set PortAudio device name");
  421. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  422. i++;
  423. strcpy(desc->params[i].name, "playback");
  424. desc->params[i].character = 'P';
  425. desc->params[i].type = JackDriverParamString;
  426. strcpy(desc->params[i].value.str, "will take default PortAudio output device");
  427. strcpy(desc->params[i].short_desc, "Provide playback ports. Optionally set PortAudio device name");
  428. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  429. i++;
  430. strcpy (desc->params[i].name, "monitor");
  431. desc->params[i].character = 'm';
  432. desc->params[i].type = JackDriverParamBool;
  433. desc->params[i].value.i = 0;
  434. strcpy(desc->params[i].short_desc, "Provide monitor ports for the output");
  435. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  436. i++;
  437. strcpy(desc->params[i].name, "duplex");
  438. desc->params[i].character = 'D';
  439. desc->params[i].type = JackDriverParamBool;
  440. desc->params[i].value.i = TRUE;
  441. strcpy(desc->params[i].short_desc, "Provide both capture and playback ports");
  442. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  443. i++;
  444. strcpy(desc->params[i].name, "rate");
  445. desc->params[i].character = 'r';
  446. desc->params[i].type = JackDriverParamUInt;
  447. desc->params[i].value.ui = 44100U;
  448. strcpy(desc->params[i].short_desc, "Sample rate");
  449. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  450. i++;
  451. strcpy(desc->params[i].name, "period");
  452. desc->params[i].character = 'p';
  453. desc->params[i].type = JackDriverParamUInt;
  454. desc->params[i].value.ui = 128U;
  455. strcpy(desc->params[i].short_desc, "Frames per period");
  456. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  457. i++;
  458. strcpy(desc->params[i].name, "device");
  459. desc->params[i].character = 'd';
  460. desc->params[i].type = JackDriverParamString;
  461. desc->params[i].value.ui = 128U;
  462. strcpy(desc->params[i].value.str, "will take default PortAudio device name");
  463. strcpy(desc->params[i].short_desc, "PortAudio device name");
  464. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  465. i++;
  466. strcpy(desc->params[i].name, "input-latency");
  467. desc->params[i].character = 'I';
  468. desc->params[i].type = JackDriverParamUInt;
  469. desc->params[i].value.i = 0;
  470. strcpy(desc->params[i].short_desc, "Extra input latency");
  471. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  472. i++;
  473. strcpy(desc->params[i].name, "output-latency");
  474. desc->params[i].character = 'O';
  475. desc->params[i].type = JackDriverParamUInt;
  476. desc->params[i].value.i = 0;
  477. strcpy(desc->params[i].short_desc, "Extra output latency");
  478. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  479. i++;
  480. strcpy(desc->params[i].name, "list-devices");
  481. desc->params[i].character = 'l';
  482. desc->params[i].type = JackDriverParamBool;
  483. desc->params[i].value.i = TRUE;
  484. strcpy(desc->params[i].short_desc, "Display available PortAudio devices");
  485. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  486. return desc;
  487. }
  488. EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackEngine* engine, Jack::JackSynchro** table, const JSList* params) {
  489. jack_nframes_t srate = 44100;
  490. jack_nframes_t frames_per_interrupt = 512;
  491. int capture = FALSE;
  492. int playback = FALSE;
  493. int chan_in = 0;
  494. int chan_out = 0;
  495. bool monitor = false;
  496. char* capture_pcm_name = "winmme";
  497. char* playback_pcm_name = "winmme";
  498. const JSList *node;
  499. const jack_driver_param_t *param;
  500. jack_nframes_t systemic_input_latency = 0;
  501. jack_nframes_t systemic_output_latency = 0;
  502. for (node = params; node; node = jack_slist_next(node)) {
  503. param = (const jack_driver_param_t *) node->data;
  504. switch (param->character) {
  505. case 'd':
  506. capture_pcm_name = strdup(param->value.str);
  507. playback_pcm_name = strdup(param->value.str);
  508. break;
  509. case 'D':
  510. capture = TRUE;
  511. playback = TRUE;
  512. break;
  513. case 'c':
  514. chan_in = chan_out = (int) param->value.ui;
  515. break;
  516. case 'i':
  517. chan_in = (int) param->value.ui;
  518. break;
  519. case 'o':
  520. chan_out = (int) param->value.ui;
  521. break;
  522. case 'C':
  523. capture = TRUE;
  524. if (strcmp(param->value.str, "none") != 0) {
  525. capture_pcm_name = strdup(param->value.str);
  526. }
  527. break;
  528. case 'P':
  529. playback = TRUE;
  530. if (strcmp(param->value.str, "none") != 0) {
  531. playback_pcm_name = strdup(param->value.str);
  532. }
  533. break;
  534. case 'm':
  535. monitor = param->value.i;
  536. break;
  537. case 'r':
  538. srate = param->value.ui;
  539. break;
  540. case 'p':
  541. frames_per_interrupt = (unsigned int) param->value.ui;
  542. break;
  543. case 'I':
  544. systemic_input_latency = param->value.ui;
  545. break;
  546. case 'O':
  547. systemic_output_latency = param->value.ui;
  548. break;
  549. case 'l':
  550. Jack::DisplayDeviceNames();
  551. break;
  552. }
  553. }
  554. // duplex is the default
  555. if (!capture && !playback) {
  556. capture = TRUE;
  557. playback = TRUE;
  558. }
  559. Jack::JackDriverClientInterface* driver = new Jack::JackPortAudioDriver("portaudio", engine, table);
  560. 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) {
  561. return driver;
  562. } else {
  563. delete driver;
  564. return NULL;
  565. }
  566. }
  567. #ifdef __cplusplus
  568. }
  569. #endif