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.

1254 lines
46KB

  1. /*
  2. Copyright (C) 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. #include "JackCoreAudioAdapter.h"
  16. #include "JackError.h"
  17. #include <unistd.h>
  18. #include <CoreServices/CoreServices.h>
  19. namespace Jack
  20. {
  21. static OSStatus DisplayDeviceNames()
  22. {
  23. UInt32 size;
  24. Boolean isWritable;
  25. int i, deviceNum;
  26. OSStatus err;
  27. CFStringRef UIname;
  28. err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &size, &isWritable);
  29. if (err != noErr)
  30. return err;
  31. deviceNum = size / sizeof(AudioDeviceID);
  32. AudioDeviceID devices[deviceNum];
  33. err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &size, devices);
  34. if (err != noErr)
  35. return err;
  36. for (i = 0; i < deviceNum; i++) {
  37. char device_name[256];
  38. char internal_name[256];
  39. size = sizeof(CFStringRef);
  40. UIname = NULL;
  41. err = AudioDeviceGetProperty(devices[i], 0, false, kAudioDevicePropertyDeviceUID, &size, &UIname);
  42. if (err == noErr) {
  43. CFStringGetCString(UIname, internal_name, 256, CFStringGetSystemEncoding());
  44. } else {
  45. goto error;
  46. }
  47. size = 256;
  48. err = AudioDeviceGetProperty(devices[i], 0, false, kAudioDevicePropertyDeviceName, &size, device_name);
  49. if (err != noErr)
  50. return err;
  51. jack_info("Device name = \'%s\', internal_name = \'%s\' (to be used as -C, -P, or -d parameter)", device_name, internal_name);
  52. }
  53. return noErr;
  54. error:
  55. if (UIname != NULL)
  56. CFRelease(UIname);
  57. return err;
  58. }
  59. static void printError(OSStatus err)
  60. {
  61. switch (err) {
  62. case kAudioHardwareNoError:
  63. jack_log("error code : kAudioHardwareNoError");
  64. break;
  65. case kAudioConverterErr_FormatNotSupported:
  66. jack_log("error code : kAudioConverterErr_FormatNotSupported");
  67. break;
  68. case kAudioConverterErr_OperationNotSupported:
  69. jack_log("error code : kAudioConverterErr_OperationNotSupported");
  70. break;
  71. case kAudioConverterErr_PropertyNotSupported:
  72. jack_log("error code : kAudioConverterErr_PropertyNotSupported");
  73. break;
  74. case kAudioConverterErr_InvalidInputSize:
  75. jack_log("error code : kAudioConverterErr_InvalidInputSize");
  76. break;
  77. case kAudioConverterErr_InvalidOutputSize:
  78. jack_log("error code : kAudioConverterErr_InvalidOutputSize");
  79. break;
  80. case kAudioConverterErr_UnspecifiedError:
  81. jack_log("error code : kAudioConverterErr_UnspecifiedError");
  82. break;
  83. case kAudioConverterErr_BadPropertySizeError:
  84. jack_log("error code : kAudioConverterErr_BadPropertySizeError");
  85. break;
  86. case kAudioConverterErr_RequiresPacketDescriptionsError:
  87. jack_log("error code : kAudioConverterErr_RequiresPacketDescriptionsError");
  88. break;
  89. case kAudioConverterErr_InputSampleRateOutOfRange:
  90. jack_log("error code : kAudioConverterErr_InputSampleRateOutOfRange");
  91. break;
  92. case kAudioConverterErr_OutputSampleRateOutOfRange:
  93. jack_log("error code : kAudioConverterErr_OutputSampleRateOutOfRange");
  94. break;
  95. case kAudioHardwareNotRunningError:
  96. jack_log("error code : kAudioHardwareNotRunningError");
  97. break;
  98. case kAudioHardwareUnknownPropertyError:
  99. jack_log("error code : kAudioHardwareUnknownPropertyError");
  100. break;
  101. case kAudioHardwareIllegalOperationError:
  102. jack_log("error code : kAudioHardwareIllegalOperationError");
  103. break;
  104. case kAudioHardwareBadDeviceError:
  105. jack_log("error code : kAudioHardwareBadDeviceError");
  106. break;
  107. case kAudioHardwareBadStreamError:
  108. jack_log("error code : kAudioHardwareBadStreamError");
  109. break;
  110. case kAudioDeviceUnsupportedFormatError:
  111. jack_log("error code : kAudioDeviceUnsupportedFormatError");
  112. break;
  113. case kAudioDevicePermissionsError:
  114. jack_log("error code : kAudioDevicePermissionsError");
  115. break;
  116. case kAudioHardwareBadObjectError:
  117. jack_log("error code : kAudioHardwareBadObjectError");
  118. break;
  119. case kAudioHardwareUnsupportedOperationError:
  120. jack_log("error code : kAudioHardwareUnsupportedOperationError");
  121. break;
  122. default:
  123. jack_log("error code : unknown");
  124. break;
  125. }
  126. }
  127. OSStatus JackCoreAudioAdapter::SRNotificationCallback(AudioDeviceID inDevice,
  128. UInt32 inChannel,
  129. Boolean isInput,
  130. AudioDevicePropertyID inPropertyID,
  131. void* inClientData)
  132. {
  133. JackCoreAudioAdapter* driver = static_cast<JackCoreAudioAdapter*>(inClientData);
  134. switch (inPropertyID) {
  135. case kAudioDevicePropertyNominalSampleRate: {
  136. jack_log("JackCoreAudioDriver::SRNotificationCallback kAudioDevicePropertyNominalSampleRate");
  137. driver->fState = true;
  138. break;
  139. }
  140. }
  141. return noErr;
  142. }
  143. // A better implementation would try to recover in case of hardware device change (see HALLAB HLFilePlayerWindowControllerAudioDevicePropertyListenerProc code)
  144. OSStatus JackCoreAudioAdapter::DeviceNotificationCallback(AudioDeviceID inDevice,
  145. UInt32 inChannel,
  146. Boolean isInput,
  147. AudioDevicePropertyID inPropertyID,
  148. void* inClientData)
  149. {
  150. switch (inPropertyID) {
  151. case kAudioDeviceProcessorOverload: {
  152. jack_error("JackCoreAudioAdapter::DeviceNotificationCallback kAudioDeviceProcessorOverload");
  153. break;
  154. }
  155. case kAudioDevicePropertyStreamConfiguration: {
  156. jack_error("Cannot handle kAudioDevicePropertyStreamConfiguration");
  157. return kAudioHardwareUnsupportedOperationError;
  158. }
  159. case kAudioDevicePropertyNominalSampleRate: {
  160. jack_error("Cannot handle kAudioDevicePropertyNominalSampleRate");
  161. return kAudioHardwareUnsupportedOperationError;
  162. }
  163. }
  164. return noErr;
  165. }
  166. int JackCoreAudioAdapter::AddListeners()
  167. {
  168. OSStatus err = noErr;
  169. // Add listeners
  170. err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDeviceProcessorOverload, DeviceNotificationCallback, this);
  171. if (err != noErr) {
  172. jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDeviceProcessorOverload");
  173. printError(err);
  174. return -1;
  175. }
  176. err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioHardwarePropertyDevices, DeviceNotificationCallback, this);
  177. if (err != noErr) {
  178. jack_error("Error calling AudioDeviceAddPropertyListener with kAudioHardwarePropertyDevices");
  179. printError(err);
  180. return -1;
  181. }
  182. err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, DeviceNotificationCallback, this);
  183. if (err != noErr) {
  184. jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyNominalSampleRate");
  185. printError(err);
  186. return -1;
  187. }
  188. err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDevicePropertyDeviceIsRunning, DeviceNotificationCallback, this);
  189. if (err != noErr) {
  190. jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyDeviceIsRunning");
  191. printError(err);
  192. return -1;
  193. }
  194. err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDevicePropertyStreamConfiguration, DeviceNotificationCallback, this);
  195. if (err != noErr) {
  196. jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyStreamConfiguration");
  197. printError(err);
  198. return -1;
  199. }
  200. err = AudioDeviceAddPropertyListener(fDeviceID, 0, false, kAudioDevicePropertyStreamConfiguration, DeviceNotificationCallback, this);
  201. if (err != noErr) {
  202. jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyStreamConfiguration");
  203. printError(err);
  204. return -1;
  205. }
  206. return 0;
  207. }
  208. void JackCoreAudioAdapter::RemoveListeners()
  209. {
  210. AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDeviceProcessorOverload, DeviceNotificationCallback);
  211. AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioHardwarePropertyDevices, DeviceNotificationCallback);
  212. AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, DeviceNotificationCallback);
  213. AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDevicePropertyDeviceIsRunning, DeviceNotificationCallback);
  214. AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDevicePropertyStreamConfiguration, DeviceNotificationCallback);
  215. AudioDeviceRemovePropertyListener(fDeviceID, 0, false, kAudioDevicePropertyStreamConfiguration, DeviceNotificationCallback);
  216. }
  217. OSStatus JackCoreAudioAdapter::Render(void *inRefCon,
  218. AudioUnitRenderActionFlags *ioActionFlags,
  219. const AudioTimeStamp *inTimeStamp,
  220. UInt32 inBusNumber,
  221. UInt32 inNumberFrames,
  222. AudioBufferList *ioData)
  223. {
  224. JackCoreAudioAdapter* adapter = static_cast<JackCoreAudioAdapter*>(inRefCon);
  225. AudioUnitRender(adapter->fAUHAL, ioActionFlags, inTimeStamp, 1, inNumberFrames, adapter->fInputData);
  226. float* inputBuffer[adapter->fCaptureChannels];
  227. float* outputBuffer[adapter->fPlaybackChannels];
  228. for (int i = 0; i < adapter->fCaptureChannels; i++) {
  229. inputBuffer[i] = (float*)adapter->fInputData->mBuffers[i].mData;
  230. }
  231. for (int i = 0; i < adapter->fPlaybackChannels; i++) {
  232. outputBuffer[i] = (float*)ioData->mBuffers[i].mData;
  233. }
  234. adapter->PushAndPull((float**)inputBuffer, (float**)outputBuffer, inNumberFrames);
  235. return noErr;
  236. }
  237. JackCoreAudioAdapter::JackCoreAudioAdapter(jack_nframes_t buffer_size, jack_nframes_t sample_rate, const JSList* params)
  238. :JackAudioAdapterInterface(buffer_size, sample_rate), fInputData(0), fCapturing(false), fPlaying(false), fState(false)
  239. {
  240. const JSList* node;
  241. const jack_driver_param_t* param;
  242. char captureName[256];
  243. char playbackName[256];
  244. fCaptureUID[0] = 0;
  245. fPlaybackUID[0] = 0;
  246. // Default values
  247. fCaptureChannels = 0;
  248. fPlaybackChannels = 0;
  249. for (node = params; node; node = jack_slist_next(node)) {
  250. param = (const jack_driver_param_t*) node->data;
  251. switch (param->character) {
  252. case 'c' :
  253. fCaptureChannels = fPlaybackChannels = param->value.ui;
  254. break;
  255. case 'i':
  256. fCaptureChannels = param->value.ui;
  257. break;
  258. case 'o':
  259. fPlaybackChannels = param->value.ui;
  260. break;
  261. case 'C':
  262. fCapturing = true;
  263. strncpy(fCaptureUID, param->value.str, 256);
  264. break;
  265. case 'P':
  266. fPlaying = true;
  267. strncpy(fPlaybackUID, param->value.str, 256);
  268. break;
  269. case 'd':
  270. strncpy(fCaptureUID, param->value.str, 256);
  271. strncpy(fPlaybackUID, param->value.str, 256);
  272. break;
  273. case 'D':
  274. fCapturing = fPlaying = true;
  275. break;
  276. case 'r':
  277. SetAdaptedSampleRate(param->value.ui);
  278. break;
  279. case 'p':
  280. SetAdaptedBufferSize(param->value.ui);
  281. break;
  282. case 'l':
  283. DisplayDeviceNames();
  284. break;
  285. case 'q':
  286. fQuality = param->value.ui;
  287. break;
  288. case 'g':
  289. fRingbufferCurSize = param->value.ui;
  290. fAdaptative = false;
  291. break;
  292. }
  293. }
  294. /* duplex is the default */
  295. if (!fCapturing && !fPlaying) {
  296. fCapturing = true;
  297. fPlaying = true;
  298. }
  299. int in_nChannels = 0;
  300. int out_nChannels = 0;
  301. if (SetupDevices(fCaptureUID, fPlaybackUID, captureName, playbackName) < 0)
  302. throw -1;
  303. if (SetupChannels(fCapturing, fPlaying, fCaptureChannels, fPlaybackChannels, in_nChannels, out_nChannels, true) < 0)
  304. throw -1;
  305. if (SetupBufferSizeAndSampleRate(fAdaptedBufferSize, fAdaptedSampleRate) < 0)
  306. throw -1;
  307. if (fCapturing && fCaptureChannels > 0)
  308. if (SetupBuffers(fCaptureChannels) < 0)
  309. throw -1;
  310. if (OpenAUHAL(fCapturing, fPlaying, fCaptureChannels, fPlaybackChannels, in_nChannels, out_nChannels, fAdaptedBufferSize, fAdaptedSampleRate, true) < 0)
  311. throw -1;
  312. if (AddListeners() < 0)
  313. throw -1;
  314. }
  315. OSStatus JackCoreAudioAdapter::GetDefaultDevice(AudioDeviceID* id)
  316. {
  317. OSStatus res;
  318. UInt32 theSize = sizeof(UInt32);
  319. AudioDeviceID inDefault;
  320. AudioDeviceID outDefault;
  321. if ((res = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice, &theSize, &inDefault)) != noErr)
  322. return res;
  323. if ((res = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &theSize, &outDefault)) != noErr)
  324. return res;
  325. jack_log("GetDefaultDevice: input = %ld output = %ld", inDefault, outDefault);
  326. // Get the device only if default input and ouput are the same
  327. if (inDefault == outDefault) {
  328. *id = inDefault;
  329. return noErr;
  330. } else {
  331. jack_error("Default input and output devices are not the same !!");
  332. return kAudioHardwareBadDeviceError;
  333. }
  334. }
  335. OSStatus JackCoreAudioAdapter::GetTotalChannels(AudioDeviceID device, int& channelCount, bool isInput)
  336. {
  337. OSStatus err = noErr;
  338. UInt32 outSize;
  339. Boolean outWritable;
  340. AudioBufferList* bufferList = 0;
  341. channelCount = 0;
  342. err = AudioDeviceGetPropertyInfo(device, 0, isInput, kAudioDevicePropertyStreamConfiguration, &outSize, &outWritable);
  343. if (err == noErr) {
  344. bufferList = (AudioBufferList*)malloc(outSize);
  345. err = AudioDeviceGetProperty(device, 0, isInput, kAudioDevicePropertyStreamConfiguration, &outSize, bufferList);
  346. if (err == noErr) {
  347. for (unsigned int i = 0; i < bufferList->mNumberBuffers; i++)
  348. channelCount += bufferList->mBuffers[i].mNumberChannels;
  349. }
  350. if (bufferList)
  351. free(bufferList);
  352. }
  353. return err;
  354. }
  355. OSStatus JackCoreAudioAdapter::GetDeviceIDFromUID(const char* UID, AudioDeviceID* id)
  356. {
  357. UInt32 size = sizeof(AudioValueTranslation);
  358. CFStringRef inIUD = CFStringCreateWithCString(NULL, UID, CFStringGetSystemEncoding());
  359. AudioValueTranslation value = { &inIUD, sizeof(CFStringRef), id, sizeof(AudioDeviceID) };
  360. if (inIUD == NULL) {
  361. return kAudioHardwareUnspecifiedError;
  362. } else {
  363. OSStatus res = AudioHardwareGetProperty(kAudioHardwarePropertyDeviceForUID, &size, &value);
  364. CFRelease(inIUD);
  365. jack_log("GetDeviceIDFromUID %s %ld", UID, *id);
  366. return (*id == kAudioDeviceUnknown) ? kAudioHardwareBadDeviceError : res;
  367. }
  368. }
  369. OSStatus JackCoreAudioAdapter::GetDefaultInputDevice(AudioDeviceID* id)
  370. {
  371. OSStatus res;
  372. UInt32 theSize = sizeof(UInt32);
  373. AudioDeviceID inDefault;
  374. if ((res = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice, &theSize, &inDefault)) != noErr)
  375. return res;
  376. jack_log("GetDefaultInputDevice: input = %ld ", inDefault);
  377. *id = inDefault;
  378. return noErr;
  379. }
  380. OSStatus JackCoreAudioAdapter::GetDefaultOutputDevice(AudioDeviceID* id)
  381. {
  382. OSStatus res;
  383. UInt32 theSize = sizeof(UInt32);
  384. AudioDeviceID outDefault;
  385. if ((res = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &theSize, &outDefault)) != noErr)
  386. return res;
  387. jack_log("GetDefaultOutputDevice: output = %ld", outDefault);
  388. *id = outDefault;
  389. return noErr;
  390. }
  391. OSStatus JackCoreAudioAdapter::GetDeviceNameFromID(AudioDeviceID id, char* name)
  392. {
  393. UInt32 size = 256;
  394. return AudioDeviceGetProperty(id, 0, false, kAudioDevicePropertyDeviceName, &size, name);
  395. }
  396. // Setup
  397. int JackCoreAudioAdapter::SetupDevices(const char* capture_driver_uid,
  398. const char* playback_driver_uid,
  399. char* capture_driver_name,
  400. char* playback_driver_name)
  401. {
  402. capture_driver_name[0] = 0;
  403. playback_driver_name[0] = 0;
  404. // Duplex
  405. if (strcmp(capture_driver_uid, "") != 0 && strcmp(playback_driver_uid, "") != 0) {
  406. // Same device for capture and playback...
  407. if (strcmp(capture_driver_uid, playback_driver_uid) == 0) {
  408. if (GetDeviceIDFromUID(playback_driver_uid, &fDeviceID) != noErr) {
  409. jack_log("Will take default in/out");
  410. if (GetDefaultDevice(&fDeviceID) != noErr) {
  411. jack_error("Cannot open default device");
  412. return -1;
  413. }
  414. }
  415. if (GetDeviceNameFromID(fDeviceID, capture_driver_name) != noErr || GetDeviceNameFromID(fDeviceID, playback_driver_name) != noErr) {
  416. jack_error("Cannot get device name from device ID");
  417. return -1;
  418. }
  419. } else {
  420. // Creates aggregate device
  421. AudioDeviceID captureID, playbackID;
  422. if (GetDeviceIDFromUID(capture_driver_uid, &captureID) != noErr)
  423. return -1;
  424. if (GetDeviceIDFromUID(playback_driver_uid, &playbackID) != noErr)
  425. return -1;
  426. if (CreateAggregateDevice(captureID, playbackID, &fDeviceID) != noErr)
  427. return -1;
  428. }
  429. // Capture only
  430. } else if (strcmp(capture_driver_uid, "") != 0) {
  431. jack_log("JackCoreAudioAdapter::Open capture only");
  432. if (GetDeviceIDFromUID(capture_driver_uid, &fDeviceID) != noErr) {
  433. if (GetDefaultInputDevice(&fDeviceID) != noErr) {
  434. jack_error("Cannot open default device");
  435. return -1;
  436. }
  437. }
  438. if (GetDeviceNameFromID(fDeviceID, capture_driver_name) != noErr) {
  439. jack_error("Cannot get device name from device ID");
  440. return -1;
  441. }
  442. // Playback only
  443. } else if (strcmp(playback_driver_uid, "") != 0) {
  444. jack_log("JackCoreAudioAdapter::Open playback only");
  445. if (GetDeviceIDFromUID(playback_driver_uid, &fDeviceID) != noErr) {
  446. if (GetDefaultOutputDevice(&fDeviceID) != noErr) {
  447. jack_error("Cannot open default device");
  448. return -1;
  449. }
  450. }
  451. if (GetDeviceNameFromID(fDeviceID, playback_driver_name) != noErr) {
  452. jack_error("Cannot get device name from device ID");
  453. return -1;
  454. }
  455. // Use default driver in duplex mode
  456. } else {
  457. jack_log("JackCoreAudioAdapter::Open default driver");
  458. if (GetDefaultDevice(&fDeviceID) != noErr) {
  459. jack_error("Cannot open default device");
  460. return -1;
  461. }
  462. if (GetDeviceNameFromID(fDeviceID, capture_driver_name) != noErr || GetDeviceNameFromID(fDeviceID, playback_driver_name) != noErr) {
  463. jack_error("Cannot get device name from device ID");
  464. return -1;
  465. }
  466. }
  467. return 0;
  468. }
  469. int JackCoreAudioAdapter::SetupChannels(bool capturing,
  470. bool playing,
  471. int& inchannels,
  472. int& outchannels,
  473. int& in_nChannels,
  474. int& out_nChannels,
  475. bool strict)
  476. {
  477. OSStatus err = noErr;
  478. if (capturing) {
  479. err = GetTotalChannels(fDeviceID, in_nChannels, true);
  480. if (err != noErr) {
  481. jack_error("Cannot get input channel number");
  482. printError(err);
  483. return -1;
  484. } else {
  485. jack_log("Max input channels : %d", in_nChannels);
  486. }
  487. }
  488. if (playing) {
  489. err = GetTotalChannels(fDeviceID, out_nChannels, false);
  490. if (err != noErr) {
  491. jack_error("Cannot get output channel number");
  492. printError(err);
  493. return -1;
  494. } else {
  495. jack_log("Max output channels : %d", out_nChannels);
  496. }
  497. }
  498. if (inchannels > in_nChannels) {
  499. jack_error("This device hasn't required input channels inchannels = %ld in_nChannels = %ld", inchannels, in_nChannels);
  500. if (strict)
  501. return -1;
  502. }
  503. if (outchannels > out_nChannels) {
  504. jack_error("This device hasn't required output channels outchannels = %ld out_nChannels = %ld", outchannels, out_nChannels);
  505. if (strict)
  506. return -1;
  507. }
  508. if (inchannels == 0) {
  509. jack_log("Setup max in channels = %ld", in_nChannels);
  510. inchannels = in_nChannels;
  511. }
  512. if (outchannels == 0) {
  513. jack_log("Setup max out channels = %ld", out_nChannels);
  514. outchannels = out_nChannels;
  515. }
  516. return 0;
  517. }
  518. int JackCoreAudioAdapter::SetupBufferSizeAndSampleRate(jack_nframes_t nframes, jack_nframes_t samplerate)
  519. {
  520. OSStatus err = noErr;
  521. UInt32 outSize;
  522. Float64 sampleRate;
  523. // Setting buffer size
  524. outSize = sizeof(UInt32);
  525. err = AudioDeviceSetProperty(fDeviceID, NULL, 0, false, kAudioDevicePropertyBufferFrameSize, outSize, &nframes);
  526. if (err != noErr) {
  527. jack_error("Cannot set buffer size %ld", nframes);
  528. printError(err);
  529. return -1;
  530. }
  531. // Get sample rate
  532. outSize = sizeof(Float64);
  533. err = AudioDeviceGetProperty(fDeviceID, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, &outSize, &sampleRate);
  534. if (err != noErr) {
  535. jack_error("Cannot get current sample rate");
  536. printError(err);
  537. return -1;
  538. }
  539. // If needed, set new sample rate
  540. if (samplerate != (jack_nframes_t)sampleRate) {
  541. sampleRate = (Float64)samplerate;
  542. // To get SR change notification
  543. err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, SRNotificationCallback, this);
  544. if (err != noErr) {
  545. jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyNominalSampleRate");
  546. printError(err);
  547. return -1;
  548. }
  549. err = AudioDeviceSetProperty(fDeviceID, NULL, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, outSize, &sampleRate);
  550. if (err != noErr) {
  551. jack_error("Cannot set sample rate = %ld", samplerate);
  552. printError(err);
  553. return -1;
  554. }
  555. // Waiting for SR change notification
  556. int count = 0;
  557. while (!fState && count++ < 100) {
  558. usleep(100000);
  559. jack_log("Wait count = %ld", count);
  560. }
  561. // Remove SR change notification
  562. AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, SRNotificationCallback);
  563. }
  564. return 0;
  565. }
  566. int JackCoreAudioAdapter::SetupBuffers(int inchannels)
  567. {
  568. jack_log("JackCoreAudioAdapter::SetupBuffers: input = %ld", inchannels);
  569. // Prepare buffers
  570. fInputData = (AudioBufferList*)malloc(sizeof(UInt32) + inchannels * sizeof(AudioBuffer));
  571. if (fInputData == 0) {
  572. jack_error("Cannot allocate memory for input buffers");
  573. return -1;
  574. }
  575. fInputData->mNumberBuffers = inchannels;
  576. for (int i = 0; i < fCaptureChannels; i++) {
  577. fInputData->mBuffers[i].mNumberChannels = 1;
  578. fInputData->mBuffers[i].mDataByteSize = fAdaptedBufferSize * sizeof(float);
  579. fInputData->mBuffers[i].mData = malloc(fAdaptedBufferSize * sizeof(float));
  580. }
  581. return 0;
  582. }
  583. void JackCoreAudioAdapter::DisposeBuffers()
  584. {
  585. if (fInputData) {
  586. for (int i = 0; i < fCaptureChannels; i++)
  587. free(fInputData->mBuffers[i].mData);
  588. free(fInputData);
  589. fInputData = 0;
  590. }
  591. }
  592. int JackCoreAudioAdapter::OpenAUHAL(bool capturing,
  593. bool playing,
  594. int inchannels,
  595. int outchannels,
  596. int in_nChannels,
  597. int out_nChannels,
  598. jack_nframes_t buffer_size,
  599. jack_nframes_t samplerate,
  600. bool strict)
  601. {
  602. ComponentResult err1;
  603. UInt32 enableIO;
  604. AudioStreamBasicDescription srcFormat, dstFormat;
  605. jack_log("OpenAUHAL capturing = %ld playing = %ld inchannels = %ld outchannels = %ld in_nChannels = %ld out_nChannels = %ld ", capturing, playing, inchannels, outchannels, in_nChannels, out_nChannels);
  606. if (inchannels == 0 && outchannels == 0) {
  607. jack_error("No input and output channels...");
  608. return -1;
  609. }
  610. // AUHAL
  611. ComponentDescription cd = {kAudioUnitType_Output, kAudioUnitSubType_HALOutput, kAudioUnitManufacturer_Apple, 0, 0};
  612. Component HALOutput = FindNextComponent(NULL, &cd);
  613. err1 = OpenAComponent(HALOutput, &fAUHAL);
  614. if (err1 != noErr) {
  615. jack_error("Error calling OpenAComponent");
  616. printError(err1);
  617. return -1;
  618. }
  619. err1 = AudioUnitInitialize(fAUHAL);
  620. if (err1 != noErr) {
  621. jack_error("Cannot initialize AUHAL unit");
  622. printError(err1);
  623. return -1;
  624. }
  625. // Start I/O
  626. if (capturing && inchannels > 0) {
  627. enableIO = 1;
  628. jack_log("Setup AUHAL input on");
  629. } else {
  630. enableIO = 0;
  631. jack_log("Setup AUHAL input off");
  632. }
  633. err1 = AudioUnitSetProperty(fAUHAL, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &enableIO, sizeof(enableIO));
  634. if (err1 != noErr) {
  635. jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input");
  636. printError(err1);
  637. if (strict)
  638. return -1;
  639. }
  640. if (playing && outchannels > 0) {
  641. enableIO = 1;
  642. jack_log("Setup AUHAL output on");
  643. } else {
  644. enableIO = 0;
  645. jack_log("Setup AUHAL output off");
  646. }
  647. err1 = AudioUnitSetProperty(fAUHAL, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, &enableIO, sizeof(enableIO));
  648. if (err1 != noErr) {
  649. jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_EnableIO,kAudioUnitScope_Output");
  650. printError(err1);
  651. if (strict)
  652. return -1;
  653. }
  654. AudioDeviceID currAudioDeviceID;
  655. UInt32 size = sizeof(AudioDeviceID);
  656. err1 = AudioUnitGetProperty(fAUHAL, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &currAudioDeviceID, &size);
  657. if (err1 != noErr) {
  658. jack_error("Error calling AudioUnitGetProperty - kAudioOutputUnitProperty_CurrentDevice");
  659. printError(err1);
  660. if (strict)
  661. return -1;
  662. } else {
  663. jack_log("AudioUnitGetPropertyCurrentDevice = %d", currAudioDeviceID);
  664. }
  665. // Setup up choosen device, in both input and output cases
  666. err1 = AudioUnitSetProperty(fAUHAL, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &fDeviceID, sizeof(AudioDeviceID));
  667. if (err1 != noErr) {
  668. jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_CurrentDevice");
  669. printError(err1);
  670. if (strict)
  671. return -1;
  672. }
  673. err1 = AudioUnitGetProperty(fAUHAL, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &currAudioDeviceID, &size);
  674. if (err1 != noErr) {
  675. jack_error("Error calling AudioUnitGetProperty - kAudioOutputUnitProperty_CurrentDevice");
  676. printError(err1);
  677. if (strict)
  678. return -1;
  679. } else {
  680. jack_log("AudioUnitGetPropertyCurrentDevice = %d", currAudioDeviceID);
  681. }
  682. // Set buffer size
  683. if (capturing && inchannels > 0) {
  684. err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 1, (UInt32*)&buffer_size, sizeof(UInt32));
  685. if (err1 != noErr) {
  686. jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_MaximumFramesPerSlice");
  687. printError(err1);
  688. if (strict)
  689. return -1;
  690. }
  691. }
  692. if (playing && outchannels > 0) {
  693. err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, (UInt32*)&buffer_size, sizeof(UInt32));
  694. if (err1 != noErr) {
  695. jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_MaximumFramesPerSlice");
  696. printError(err1);
  697. if (strict)
  698. return -1;
  699. }
  700. }
  701. // Setup channel map
  702. if (capturing && inchannels > 0 && inchannels < in_nChannels) {
  703. SInt32 chanArr[in_nChannels];
  704. for (int i = 0; i < in_nChannels; i++) {
  705. chanArr[i] = -1;
  706. }
  707. for (int i = 0; i < inchannels; i++) {
  708. chanArr[i] = i;
  709. }
  710. AudioUnitSetProperty(fAUHAL, kAudioOutputUnitProperty_ChannelMap , kAudioUnitScope_Input, 1, chanArr, sizeof(SInt32) * in_nChannels);
  711. if (err1 != noErr) {
  712. jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_ChannelMap 1");
  713. printError(err1);
  714. }
  715. }
  716. if (playing && outchannels > 0 && outchannels < out_nChannels) {
  717. SInt32 chanArr[out_nChannels];
  718. for (int i = 0; i < out_nChannels; i++) {
  719. chanArr[i] = -1;
  720. }
  721. for (int i = 0; i < outchannels; i++) {
  722. chanArr[i] = i;
  723. }
  724. err1 = AudioUnitSetProperty(fAUHAL, kAudioOutputUnitProperty_ChannelMap, kAudioUnitScope_Output, 0, chanArr, sizeof(SInt32) * out_nChannels);
  725. if (err1 != noErr) {
  726. jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_ChannelMap 0");
  727. printError(err1);
  728. }
  729. }
  730. // Setup stream converters
  731. jack_log("Setup AUHAL input stream converter SR = %ld", samplerate);
  732. srcFormat.mSampleRate = samplerate;
  733. srcFormat.mFormatID = kAudioFormatLinearPCM;
  734. srcFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kLinearPCMFormatFlagIsNonInterleaved;
  735. srcFormat.mBytesPerPacket = sizeof(float);
  736. srcFormat.mFramesPerPacket = 1;
  737. srcFormat.mBytesPerFrame = sizeof(float);
  738. srcFormat.mChannelsPerFrame = outchannels;
  739. srcFormat.mBitsPerChannel = 32;
  740. err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &srcFormat, sizeof(AudioStreamBasicDescription));
  741. if (err1 != noErr) {
  742. jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Input");
  743. printError(err1);
  744. }
  745. jack_log("Setup AUHAL output stream converter SR = %ld", samplerate);
  746. dstFormat.mSampleRate = samplerate;
  747. dstFormat.mFormatID = kAudioFormatLinearPCM;
  748. dstFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kLinearPCMFormatFlagIsNonInterleaved;
  749. dstFormat.mBytesPerPacket = sizeof(float);
  750. dstFormat.mFramesPerPacket = 1;
  751. dstFormat.mBytesPerFrame = sizeof(float);
  752. dstFormat.mChannelsPerFrame = inchannels;
  753. dstFormat.mBitsPerChannel = 32;
  754. err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &dstFormat, sizeof(AudioStreamBasicDescription));
  755. if (err1 != noErr) {
  756. jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Output");
  757. printError(err1);
  758. }
  759. // Setup callbacks
  760. if (inchannels > 0 && outchannels == 0) {
  761. AURenderCallbackStruct output;
  762. output.inputProc = Render;
  763. output.inputProcRefCon = this;
  764. err1 = AudioUnitSetProperty(fAUHAL, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &output, sizeof(output));
  765. if (err1 != noErr) {
  766. jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_SetRenderCallback 1");
  767. printError(err1);
  768. return -1;
  769. }
  770. } else {
  771. AURenderCallbackStruct output;
  772. output.inputProc = Render;
  773. output.inputProcRefCon = this;
  774. err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &output, sizeof(output));
  775. if (err1 != noErr) {
  776. jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_SetRenderCallback 0");
  777. printError(err1);
  778. return -1;
  779. }
  780. }
  781. return 0;
  782. }
  783. OSStatus JackCoreAudioAdapter::DestroyAggregateDevice()
  784. {
  785. OSStatus osErr = noErr;
  786. AudioObjectPropertyAddress pluginAOPA;
  787. pluginAOPA.mSelector = kAudioPlugInDestroyAggregateDevice;
  788. pluginAOPA.mScope = kAudioObjectPropertyScopeGlobal;
  789. pluginAOPA.mElement = kAudioObjectPropertyElementMaster;
  790. UInt32 outDataSize;
  791. osErr = AudioObjectGetPropertyDataSize(fPluginID, &pluginAOPA, 0, NULL, &outDataSize);
  792. if (osErr != noErr) {
  793. jack_error("JackCoreAudioDriver::DestroyAggregateDevice : AudioObjectGetPropertyDataSize error");
  794. printError(osErr);
  795. return osErr;
  796. }
  797. osErr = AudioObjectGetPropertyData(fPluginID, &pluginAOPA, 0, NULL, &outDataSize, &fDeviceID);
  798. if (osErr != noErr) {
  799. jack_error("JackCoreAudioDriver::DestroyAggregateDevice : AudioObjectGetPropertyData error");
  800. printError(osErr);
  801. return osErr;
  802. }
  803. return noErr;
  804. }
  805. static CFStringRef GetDeviceName(AudioDeviceID id)
  806. {
  807. UInt32 size = sizeof(CFStringRef);
  808. CFStringRef UIname;
  809. OSStatus err = AudioDeviceGetProperty(id, 0, false, kAudioDevicePropertyDeviceUID, &size, &UIname);
  810. return (err == noErr) ? UIname : NULL;
  811. }
  812. OSStatus JackCoreAudioAdapter::CreateAggregateDevice(AudioDeviceID captureDeviceID, AudioDeviceID playbackDeviceID, AudioDeviceID* outAggregateDevice)
  813. {
  814. OSStatus osErr = noErr;
  815. UInt32 outSize;
  816. Boolean outWritable;
  817. //---------------------------------------------------------------------------
  818. // Start to create a new aggregate by getting the base audio hardware plugin
  819. //---------------------------------------------------------------------------
  820. jack_info("Separated input and output devices, so create a private aggregate device to handle them...");
  821. osErr = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyPlugInForBundleID, &outSize, &outWritable);
  822. if (osErr != noErr)
  823. return osErr;
  824. AudioValueTranslation pluginAVT;
  825. CFStringRef inBundleRef = CFSTR("com.apple.audio.CoreAudio");
  826. pluginAVT.mInputData = &inBundleRef;
  827. pluginAVT.mInputDataSize = sizeof(inBundleRef);
  828. pluginAVT.mOutputData = &fPluginID;
  829. pluginAVT.mOutputDataSize = sizeof(fPluginID);
  830. osErr = AudioHardwareGetProperty(kAudioHardwarePropertyPlugInForBundleID, &outSize, &pluginAVT);
  831. if (osErr != noErr)
  832. return osErr;
  833. //-------------------------------------------------
  834. // Create a CFDictionary for our aggregate device
  835. //-------------------------------------------------
  836. CFMutableDictionaryRef aggDeviceDict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
  837. CFStringRef AggregateDeviceNameRef = CFSTR("JackDuplex");
  838. CFStringRef AggregateDeviceUIDRef = CFSTR("com.grame.JackDuplex");
  839. // add the name of the device to the dictionary
  840. CFDictionaryAddValue(aggDeviceDict, CFSTR(kAudioAggregateDeviceNameKey), AggregateDeviceNameRef);
  841. // add our choice of UID for the aggregate device to the dictionary
  842. CFDictionaryAddValue(aggDeviceDict, CFSTR(kAudioAggregateDeviceUIDKey), AggregateDeviceUIDRef);
  843. // add a "private aggregate key" to the dictionary
  844. int value = 1;
  845. CFNumberRef AggregateDeviceNumberRef = CFNumberCreate(NULL, kCFNumberIntType, &value);
  846. CFDictionaryAddValue(aggDeviceDict, CFSTR(kAudioAggregateDeviceIsPrivateKey), AggregateDeviceNumberRef);
  847. //-------------------------------------------------
  848. // Create a CFMutableArray for our sub-device list
  849. //-------------------------------------------------
  850. CFStringRef captureDeviceUID = GetDeviceName(captureDeviceID);
  851. CFStringRef playbackDeviceUID = GetDeviceName(playbackDeviceID);
  852. if (captureDeviceUID == NULL || playbackDeviceUID == NULL)
  853. return -1;
  854. // we need to append the UID for each device to a CFMutableArray, so create one here
  855. CFMutableArrayRef subDevicesArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
  856. // two sub-devices in this example, so append the sub-device's UID to the CFArray
  857. CFArrayAppendValue(subDevicesArray, captureDeviceUID);
  858. CFArrayAppendValue(subDevicesArray, playbackDeviceUID);
  859. //-----------------------------------------------------------------------
  860. // Feed the dictionary to the plugin, to create a blank aggregate device
  861. //-----------------------------------------------------------------------
  862. AudioObjectPropertyAddress pluginAOPA;
  863. pluginAOPA.mSelector = kAudioPlugInCreateAggregateDevice;
  864. pluginAOPA.mScope = kAudioObjectPropertyScopeGlobal;
  865. pluginAOPA.mElement = kAudioObjectPropertyElementMaster;
  866. UInt32 outDataSize;
  867. osErr = AudioObjectGetPropertyDataSize(fPluginID, &pluginAOPA, 0, NULL, &outDataSize);
  868. if (osErr != noErr)
  869. return osErr;
  870. osErr = AudioObjectGetPropertyData(fPluginID, &pluginAOPA, sizeof(aggDeviceDict), &aggDeviceDict, &outDataSize, outAggregateDevice);
  871. if (osErr != noErr)
  872. return osErr;
  873. // pause for a bit to make sure that everything completed correctly
  874. // this is to work around a bug in the HAL where a new aggregate device seems to disappear briefly after it is created
  875. CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, false);
  876. //-------------------------
  877. // Set the sub-device list
  878. //-------------------------
  879. pluginAOPA.mSelector = kAudioAggregateDevicePropertyFullSubDeviceList;
  880. pluginAOPA.mScope = kAudioObjectPropertyScopeGlobal;
  881. pluginAOPA.mElement = kAudioObjectPropertyElementMaster;
  882. outDataSize = sizeof(CFMutableArrayRef);
  883. osErr = AudioObjectSetPropertyData(*outAggregateDevice, &pluginAOPA, 0, NULL, outDataSize, &subDevicesArray);
  884. if (osErr != noErr)
  885. return osErr;
  886. // pause again to give the changes time to take effect
  887. CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, false);
  888. //-----------------------
  889. // Set the master device
  890. //-----------------------
  891. // set the master device manually (this is the device which will act as the master clock for the aggregate device)
  892. // pass in the UID of the device you want to use
  893. pluginAOPA.mSelector = kAudioAggregateDevicePropertyMasterSubDevice;
  894. pluginAOPA.mScope = kAudioObjectPropertyScopeGlobal;
  895. pluginAOPA.mElement = kAudioObjectPropertyElementMaster;
  896. outDataSize = sizeof(CFStringRef);
  897. osErr = AudioObjectSetPropertyData(*outAggregateDevice, &pluginAOPA, 0, NULL, outDataSize, &captureDeviceUID); // capture is master...
  898. if (osErr != noErr)
  899. return osErr;
  900. // pause again to give the changes time to take effect
  901. CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, false);
  902. //----------
  903. // Clean up
  904. //----------
  905. CFRelease(AggregateDeviceNumberRef);
  906. // release the CF objects we have created - we don't need them any more
  907. CFRelease(aggDeviceDict);
  908. CFRelease(subDevicesArray);
  909. // release the device UID
  910. CFRelease(captureDeviceUID);
  911. CFRelease(playbackDeviceUID);
  912. jack_log("New aggregate device %ld", *outAggregateDevice);
  913. return noErr;
  914. }
  915. void JackCoreAudioAdapter::CloseAUHAL()
  916. {
  917. AudioUnitUninitialize(fAUHAL);
  918. CloseComponent(fAUHAL);
  919. }
  920. int JackCoreAudioAdapter::Open()
  921. {
  922. return (AudioOutputUnitStart(fAUHAL) != noErr) ? -1 : 0;
  923. }
  924. int JackCoreAudioAdapter::Close()
  925. {
  926. #ifdef JACK_MONITOR
  927. fTable.Save(fHostBufferSize, fHostSampleRate, fAdaptedSampleRate, fAdaptedBufferSize);
  928. #endif
  929. AudioOutputUnitStop(fAUHAL);
  930. DisposeBuffers();
  931. CloseAUHAL();
  932. RemoveListeners();
  933. if (fPluginID > 0)
  934. DestroyAggregateDevice();
  935. return 0;
  936. }
  937. int JackCoreAudioAdapter::SetSampleRate ( jack_nframes_t sample_rate ) {
  938. JackAudioAdapterInterface::SetHostSampleRate ( sample_rate );
  939. Close();
  940. return Open();
  941. }
  942. int JackCoreAudioAdapter::SetBufferSize ( jack_nframes_t buffer_size ) {
  943. JackAudioAdapterInterface::SetHostBufferSize ( buffer_size );
  944. Close();
  945. return Open();
  946. }
  947. } // namespace
  948. #ifdef __cplusplus
  949. extern "C"
  950. {
  951. #endif
  952. SERVER_EXPORT jack_driver_desc_t* jack_get_descriptor()
  953. {
  954. jack_driver_desc_t *desc;
  955. unsigned int i;
  956. desc = (jack_driver_desc_t*)calloc(1, sizeof(jack_driver_desc_t));
  957. strcpy(desc->name, "audioadapter"); // size MUST be less then JACK_DRIVER_NAME_MAX + 1
  958. strcpy(desc->desc, "netjack audio <==> net backend adapter"); // size MUST be less then JACK_DRIVER_PARAM_DESC + 1
  959. desc->nparams = 12;
  960. desc->params = (jack_driver_param_desc_t*)calloc(desc->nparams, sizeof(jack_driver_param_desc_t));
  961. i = 0;
  962. strcpy(desc->params[i].name, "channels");
  963. desc->params[i].character = 'c';
  964. desc->params[i].type = JackDriverParamInt;
  965. desc->params[i].value.ui = 0;
  966. strcpy(desc->params[i].short_desc, "Maximum number of channels");
  967. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  968. i++;
  969. strcpy(desc->params[i].name, "inchannels");
  970. desc->params[i].character = 'i';
  971. desc->params[i].type = JackDriverParamInt;
  972. desc->params[i].value.ui = 0;
  973. strcpy(desc->params[i].short_desc, "Maximum number of input channels");
  974. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  975. i++;
  976. strcpy(desc->params[i].name, "outchannels");
  977. desc->params[i].character = 'o';
  978. desc->params[i].type = JackDriverParamInt;
  979. desc->params[i].value.ui = 0;
  980. strcpy(desc->params[i].short_desc, "Maximum number of output channels");
  981. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  982. i++;
  983. strcpy(desc->params[i].name, "capture");
  984. desc->params[i].character = 'C';
  985. desc->params[i].type = JackDriverParamString;
  986. strcpy(desc->params[i].value.str, "will take default CoreAudio input device");
  987. strcpy(desc->params[i].short_desc, "Provide capture ports. Optionally set CoreAudio device name");
  988. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  989. i++;
  990. strcpy(desc->params[i].name, "playback");
  991. desc->params[i].character = 'P';
  992. desc->params[i].type = JackDriverParamString;
  993. strcpy(desc->params[i].value.str, "will take default CoreAudio output device");
  994. strcpy(desc->params[i].short_desc, "Provide playback ports. Optionally set CoreAudio device name");
  995. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  996. i++;
  997. strcpy(desc->params[i].name, "rate");
  998. desc->params[i].character = 'r';
  999. desc->params[i].type = JackDriverParamUInt;
  1000. desc->params[i].value.ui = 44100U;
  1001. strcpy(desc->params[i].short_desc, "Sample rate");
  1002. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  1003. i++;
  1004. strcpy(desc->params[i].name, "periodsize");
  1005. desc->params[i].character = 'p';
  1006. desc->params[i].type = JackDriverParamUInt;
  1007. desc->params[i].value.ui = 512U;
  1008. strcpy(desc->params[i].short_desc, "Period size");
  1009. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  1010. i++;
  1011. strcpy(desc->params[i].name, "duplex");
  1012. desc->params[i].character = 'D';
  1013. desc->params[i].type = JackDriverParamBool;
  1014. desc->params[i].value.i = TRUE;
  1015. strcpy(desc->params[i].short_desc, "Provide both capture and playback ports");
  1016. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  1017. i++;
  1018. strcpy(desc->params[i].name, "device");
  1019. desc->params[i].character = 'd';
  1020. desc->params[i].type = JackDriverParamString;
  1021. strcpy(desc->params[i].value.str, "will take default CoreAudio device name");
  1022. strcpy(desc->params[i].short_desc, "CoreAudio device name");
  1023. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  1024. i++;
  1025. strcpy(desc->params[i].name, "list-devices");
  1026. desc->params[i].character = 'l';
  1027. desc->params[i].type = JackDriverParamBool;
  1028. desc->params[i].value.i = TRUE;
  1029. strcpy(desc->params[i].short_desc, "Display available CoreAudio devices");
  1030. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  1031. i++;
  1032. strcpy(desc->params[i].name, "quality");
  1033. desc->params[i].character = 'q';
  1034. desc->params[i].type = JackDriverParamInt;
  1035. desc->params[i].value.ui = 0;
  1036. strcpy(desc->params[i].short_desc, "Resample algorithm quality (0 - 4)");
  1037. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  1038. i++;
  1039. strcpy(desc->params[i].name, "ring-buffer");
  1040. desc->params[i].character = 'g';
  1041. desc->params[i].type = JackDriverParamInt;
  1042. desc->params[i].value.ui = 32768;
  1043. strcpy(desc->params[i].short_desc, "Fixed ringbuffer size");
  1044. strcpy(desc->params[i].long_desc, "Fixed ringbuffer size (if not set => automatic adaptative)");
  1045. return desc;
  1046. }
  1047. #ifdef __cplusplus
  1048. }
  1049. #endif