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.

710 lines
25KB

  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. #if defined(HAVE_CONFIG_H)
  16. #include "config.h"
  17. #endif
  18. #include "JackCoreAudioAdapter.h"
  19. #include "JackError.h"
  20. #include <unistd.h>
  21. namespace Jack
  22. {
  23. static void printError(OSStatus err)
  24. {
  25. switch (err) {
  26. case kAudioHardwareNoError:
  27. jack_log("error code : kAudioHardwareNoError");
  28. break;
  29. case kAudioConverterErr_FormatNotSupported:
  30. jack_log("error code : kAudioConverterErr_FormatNotSupported");
  31. break;
  32. case kAudioConverterErr_OperationNotSupported:
  33. jack_log("error code : kAudioConverterErr_OperationNotSupported");
  34. break;
  35. case kAudioConverterErr_PropertyNotSupported:
  36. jack_log("error code : kAudioConverterErr_PropertyNotSupported");
  37. break;
  38. case kAudioConverterErr_InvalidInputSize:
  39. jack_log("error code : kAudioConverterErr_InvalidInputSize");
  40. break;
  41. case kAudioConverterErr_InvalidOutputSize:
  42. jack_log("error code : kAudioConverterErr_InvalidOutputSize");
  43. break;
  44. case kAudioConverterErr_UnspecifiedError:
  45. jack_log("error code : kAudioConverterErr_UnspecifiedError");
  46. break;
  47. case kAudioConverterErr_BadPropertySizeError:
  48. jack_log("error code : kAudioConverterErr_BadPropertySizeError");
  49. break;
  50. case kAudioConverterErr_RequiresPacketDescriptionsError:
  51. jack_log("error code : kAudioConverterErr_RequiresPacketDescriptionsError");
  52. break;
  53. case kAudioConverterErr_InputSampleRateOutOfRange:
  54. jack_log("error code : kAudioConverterErr_InputSampleRateOutOfRange");
  55. break;
  56. case kAudioConverterErr_OutputSampleRateOutOfRange:
  57. jack_log("error code : kAudioConverterErr_OutputSampleRateOutOfRange");
  58. break;
  59. case kAudioHardwareNotRunningError:
  60. jack_log("error code : kAudioHardwareNotRunningError");
  61. break;
  62. case kAudioHardwareUnknownPropertyError:
  63. jack_log("error code : kAudioHardwareUnknownPropertyError");
  64. break;
  65. case kAudioHardwareIllegalOperationError:
  66. jack_log("error code : kAudioHardwareIllegalOperationError");
  67. break;
  68. case kAudioHardwareBadDeviceError:
  69. jack_log("error code : kAudioHardwareBadDeviceError");
  70. break;
  71. case kAudioHardwareBadStreamError:
  72. jack_log("error code : kAudioHardwareBadStreamError");
  73. break;
  74. case kAudioDeviceUnsupportedFormatError:
  75. jack_log("error code : kAudioDeviceUnsupportedFormatError");
  76. break;
  77. case kAudioDevicePermissionsError:
  78. jack_log("error code : kAudioDevicePermissionsError");
  79. break;
  80. case kAudioHardwareBadObjectError:
  81. jack_log("error code : kAudioHardwareBadObjectError");
  82. break;
  83. case kAudioHardwareUnsupportedOperationError:
  84. jack_log("error code : kAudioHardwareUnsupportedOperationError");
  85. break;
  86. default:
  87. jack_log("error code : unknown");
  88. break;
  89. }
  90. }
  91. OSStatus JackCoreAudioAdapter::SRNotificationCallback(AudioDeviceID inDevice,
  92. UInt32 inChannel,
  93. Boolean isInput,
  94. AudioDevicePropertyID inPropertyID,
  95. void* inClientData)
  96. {
  97. JackCoreAudioAdapter* driver = static_cast<JackCoreAudioAdapter*>(inClientData);
  98. switch (inPropertyID) {
  99. case kAudioDevicePropertyNominalSampleRate: {
  100. jack_log("JackCoreAudioDriver::SRNotificationCallback kAudioDevicePropertyNominalSampleRate");
  101. driver->fState = true;
  102. break;
  103. }
  104. }
  105. return noErr;
  106. }
  107. OSStatus JackCoreAudioAdapter::Render(void *inRefCon,
  108. AudioUnitRenderActionFlags *ioActionFlags,
  109. const AudioTimeStamp *inTimeStamp,
  110. UInt32 inBusNumber,
  111. UInt32 inNumberFrames,
  112. AudioBufferList *ioData)
  113. {
  114. JackCoreAudioAdapter* adapter = static_cast<JackCoreAudioAdapter*>(inRefCon);
  115. AudioUnitRender(adapter->fAUHAL, ioActionFlags, inTimeStamp, 1, inNumberFrames, adapter->fInputData);
  116. bool failure = false;
  117. jack_nframes_t time1, time2;
  118. adapter->ResampleFactor(time1, time2);
  119. for (int i = 0; i < adapter->fCaptureChannels; i++) {
  120. adapter->fCaptureRingBuffer[i]->SetRatio(time1, time2);
  121. if (adapter->fCaptureRingBuffer[i]->WriteResample((float*)adapter->fInputData->mBuffers[i].mData, inNumberFrames) < inNumberFrames)
  122. failure = true;
  123. }
  124. for (int i = 0; i < adapter->fPlaybackChannels; i++) {
  125. adapter->fPlaybackRingBuffer[i]->SetRatio(time2, time1);
  126. if (adapter->fPlaybackRingBuffer[i]->ReadResample((float*)ioData->mBuffers[i].mData, inNumberFrames) < inNumberFrames)
  127. failure = true;
  128. }
  129. #ifdef JACK_MONITOR
  130. adapter->fTable.Write(time1, time2, double(time1) / double(time2), double(time2) / double(time1),
  131. adapter->fCaptureRingBuffer[0]->ReadSpace(), adapter->fPlaybackRingBuffer[0]->WriteSpace());
  132. #endif
  133. // Reset all ringbuffers in case of failure
  134. if (failure) {
  135. jack_error("JackCoreAudioAdapter::Render ringbuffer failure... reset");
  136. adapter->ResetRingBuffers();
  137. }
  138. return noErr;
  139. }
  140. JackCoreAudioAdapter::JackCoreAudioAdapter(jack_nframes_t buffer_size, jack_nframes_t sample_rate, const JSList* params)
  141. :JackAudioAdapterInterface(buffer_size, sample_rate),fInputData(0),fState(false)
  142. {
  143. const JSList* node;
  144. const jack_driver_param_t* param;
  145. fCaptureChannels = 2;
  146. fPlaybackChannels = 2;
  147. for (node = params; node; node = jack_slist_next(node)) {
  148. param = (const jack_driver_param_t*) node->data;
  149. switch (param->character) {
  150. case 'c' :
  151. break;
  152. case 'i':
  153. fCaptureChannels = param->value.ui;
  154. break;
  155. case 'o':
  156. fPlaybackChannels = param->value.ui;
  157. break;
  158. case 'C':
  159. break;
  160. case 'P':
  161. break;
  162. case 'D':
  163. break;
  164. case 'r':
  165. SetAudioSampleRate(param->value.ui);
  166. break;
  167. case 'l':
  168. break;
  169. }
  170. }
  171. }
  172. OSStatus JackCoreAudioAdapter::GetDefaultDevice(AudioDeviceID* id)
  173. {
  174. OSStatus res;
  175. UInt32 theSize = sizeof(UInt32);
  176. AudioDeviceID inDefault;
  177. AudioDeviceID outDefault;
  178. if ((res = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice, &theSize, &inDefault)) != noErr)
  179. return res;
  180. if ((res = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &theSize, &outDefault)) != noErr)
  181. return res;
  182. jack_log("GetDefaultDevice: input = %ld output = %ld", inDefault, outDefault);
  183. // Get the device only if default input and ouput are the same
  184. if (inDefault == outDefault) {
  185. *id = inDefault;
  186. return noErr;
  187. } else {
  188. jack_error("Default input and output devices are not the same !!");
  189. return kAudioHardwareBadDeviceError;
  190. }
  191. }
  192. OSStatus JackCoreAudioAdapter::GetTotalChannels(AudioDeviceID device, int* channelCount, bool isInput)
  193. {
  194. OSStatus err = noErr;
  195. UInt32 outSize;
  196. Boolean outWritable;
  197. AudioBufferList* bufferList = 0;
  198. *channelCount = 0;
  199. err = AudioDeviceGetPropertyInfo(device, 0, isInput, kAudioDevicePropertyStreamConfiguration, &outSize, &outWritable);
  200. if (err == noErr) {
  201. bufferList = (AudioBufferList*)malloc(outSize);
  202. err = AudioDeviceGetProperty(device, 0, isInput, kAudioDevicePropertyStreamConfiguration, &outSize, bufferList);
  203. if (err == noErr) {
  204. for (unsigned int i = 0; i < bufferList->mNumberBuffers; i++)
  205. *channelCount += bufferList->mBuffers[i].mNumberChannels;
  206. }
  207. if (bufferList)
  208. free(bufferList);
  209. }
  210. return err;
  211. }
  212. // Setup
  213. int JackCoreAudioAdapter::SetupDevices(const char* capture_driver_uid,
  214. const char* playback_driver_uid,
  215. char* capture_driver_name,
  216. char* playback_driver_name)
  217. {
  218. if (GetDefaultDevice(&fDeviceID) != noErr) {
  219. jack_error("Cannot open default device");
  220. return -1;
  221. }
  222. return 0;
  223. }
  224. int JackCoreAudioAdapter::SetupChannels(bool capturing,
  225. bool playing,
  226. int& inchannels,
  227. int& outchannels,
  228. int& in_nChannels,
  229. int& out_nChannels,
  230. bool strict)
  231. {
  232. OSStatus err = noErr;
  233. err = GetTotalChannels(fDeviceID, &in_nChannels, true);
  234. if (err != noErr) {
  235. jack_error("Cannot get input channel number");
  236. printError(err);
  237. return -1;
  238. }
  239. err = GetTotalChannels(fDeviceID, &out_nChannels, false);
  240. if (err != noErr) {
  241. jack_error("Cannot get output channel number");
  242. printError(err);
  243. return -1;
  244. }
  245. return 0;
  246. }
  247. int JackCoreAudioAdapter::SetupBufferSizeAndSampleRate(jack_nframes_t nframes, jack_nframes_t samplerate)
  248. {
  249. OSStatus err = noErr;
  250. UInt32 outSize;
  251. Float64 sampleRate;
  252. // Setting buffer size
  253. outSize = sizeof(UInt32);
  254. err = AudioDeviceSetProperty(fDeviceID, NULL, 0, false, kAudioDevicePropertyBufferFrameSize, outSize, &nframes);
  255. if (err != noErr) {
  256. jack_error("Cannot set buffer size %ld", nframes);
  257. printError(err);
  258. return -1;
  259. }
  260. // Get sample rate
  261. outSize = sizeof(Float64);
  262. err = AudioDeviceGetProperty(fDeviceID, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, &outSize, &sampleRate);
  263. if (err != noErr) {
  264. jack_error("Cannot get current sample rate");
  265. printError(err);
  266. return -1;
  267. }
  268. // If needed, set new sample rate
  269. if (samplerate != (jack_nframes_t)sampleRate) {
  270. sampleRate = (Float64)samplerate;
  271. // To get SR change notification
  272. err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, SRNotificationCallback, this);
  273. if (err != noErr) {
  274. jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyNominalSampleRate");
  275. printError(err);
  276. return -1;
  277. }
  278. err = AudioDeviceSetProperty(fDeviceID, NULL, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, outSize, &sampleRate);
  279. if (err != noErr) {
  280. jack_error("Cannot set sample rate = %ld", samplerate);
  281. printError(err);
  282. return -1;
  283. }
  284. // Waiting for SR change notification
  285. int count = 0;
  286. while (!fState && count++ < 100) {
  287. usleep(100000);
  288. jack_log("Wait count = %ld", count);
  289. }
  290. // Remove SR change notification
  291. AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, SRNotificationCallback);
  292. }
  293. return 0;
  294. }
  295. int JackCoreAudioAdapter::SetupBuffers(int inchannels, int outchannels)
  296. {
  297. jack_log("JackCoreAudioAdapter::SetupBuffers: input = %ld output = %ld", inchannels, outchannels);
  298. // Prepare buffers
  299. fInputData = (AudioBufferList*)malloc(sizeof(UInt32) + inchannels * sizeof(AudioBuffer));
  300. if (fInputData == 0) {
  301. jack_error("Cannot allocate memory for input buffers");
  302. return -1;
  303. }
  304. fInputData->mNumberBuffers = inchannels;
  305. for (int i = 0; i < fCaptureChannels; i++) {
  306. fInputData->mBuffers[i].mNumberChannels = 1;
  307. fInputData->mBuffers[i].mDataByteSize = fBufferSize * sizeof(float);
  308. fInputData->mBuffers[i].mData = malloc(fBufferSize * sizeof(float));
  309. }
  310. return 0;
  311. }
  312. void JackCoreAudioAdapter::DisposeBuffers()
  313. {
  314. if (fInputData) {
  315. for (int i = 0; i < fCaptureChannels; i++)
  316. free(fInputData->mBuffers[i].mData);
  317. free(fInputData);
  318. fInputData = 0;
  319. }
  320. }
  321. int JackCoreAudioAdapter::OpenAUHAL(bool capturing,
  322. bool playing,
  323. int inchannels,
  324. int outchannels,
  325. int in_nChannels,
  326. int out_nChannels,
  327. jack_nframes_t nframes,
  328. jack_nframes_t samplerate,
  329. bool strict)
  330. {
  331. ComponentResult err1;
  332. UInt32 enableIO;
  333. AudioStreamBasicDescription srcFormat, dstFormat;
  334. jack_log("OpenAUHAL capturing = %ld playing = %ld playing = %ld outchannels = %ld in_nChannels = %ld out_nChannels = %ld ", capturing, playing, inchannels, inchannels, in_nChannels, out_nChannels);
  335. // AUHAL
  336. ComponentDescription cd = {kAudioUnitType_Output, kAudioUnitSubType_HALOutput, kAudioUnitManufacturer_Apple, 0, 0};
  337. Component HALOutput = FindNextComponent(NULL, &cd);
  338. err1 = OpenAComponent(HALOutput, &fAUHAL);
  339. if (err1 != noErr) {
  340. jack_error("Error calling OpenAComponent");
  341. printError(err1);
  342. return -1;
  343. }
  344. err1 = AudioUnitInitialize(fAUHAL);
  345. if (err1 != noErr) {
  346. jack_error("Cannot initialize AUHAL unit");
  347. printError(err1);
  348. return -1;
  349. }
  350. // Start I/O
  351. enableIO = 1;
  352. if (capturing && inchannels > 0) {
  353. jack_log("Setup AUHAL input");
  354. err1 = AudioUnitSetProperty(fAUHAL, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &enableIO, sizeof(enableIO));
  355. if (err1 != noErr) {
  356. jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input");
  357. printError(err1);
  358. if (strict)
  359. return -1;
  360. }
  361. }
  362. if (playing && outchannels > 0) {
  363. jack_log("Setup AUHAL output");
  364. err1 = AudioUnitSetProperty(fAUHAL, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, &enableIO, sizeof(enableIO));
  365. if (err1 != noErr) {
  366. jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_EnableIO,kAudioUnitScope_Output");
  367. printError(err1);
  368. if (strict)
  369. return -1;
  370. }
  371. }
  372. // Setup up choosen device, in both input and output cases
  373. err1 = AudioUnitSetProperty(fAUHAL, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &fDeviceID, sizeof(AudioDeviceID));
  374. if (err1 != noErr) {
  375. jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_CurrentDevice");
  376. printError(err1);
  377. if (strict)
  378. return -1;
  379. }
  380. // Set buffer size
  381. if (capturing && inchannels > 0) {
  382. err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 1, (UInt32*) & nframes, sizeof(UInt32));
  383. if (err1 != noErr) {
  384. jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_MaximumFramesPerSlice");
  385. printError(err1);
  386. if (strict)
  387. return -1;
  388. }
  389. }
  390. if (playing && outchannels > 0) {
  391. err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, (UInt32*) & nframes, sizeof(UInt32));
  392. if (err1 != noErr) {
  393. jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_MaximumFramesPerSlice");
  394. printError(err1);
  395. if (strict)
  396. return -1;
  397. }
  398. }
  399. // Setup channel map
  400. if (capturing && inchannels > 0 && inchannels < in_nChannels) {
  401. SInt32 chanArr[in_nChannels];
  402. for (int i = 0; i < in_nChannels; i++) {
  403. chanArr[i] = -1;
  404. }
  405. for (int i = 0; i < inchannels; i++) {
  406. chanArr[i] = i;
  407. }
  408. AudioUnitSetProperty(fAUHAL, kAudioOutputUnitProperty_ChannelMap , kAudioUnitScope_Input, 1, chanArr, sizeof(SInt32) * in_nChannels);
  409. if (err1 != noErr) {
  410. jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_ChannelMap 1");
  411. printError(err1);
  412. }
  413. }
  414. if (playing && outchannels > 0 && outchannels < out_nChannels) {
  415. SInt32 chanArr[out_nChannels];
  416. for (int i = 0; i < out_nChannels; i++) {
  417. chanArr[i] = -1;
  418. }
  419. for (int i = 0; i < outchannels; i++) {
  420. chanArr[i] = i;
  421. }
  422. err1 = AudioUnitSetProperty(fAUHAL, kAudioOutputUnitProperty_ChannelMap, kAudioUnitScope_Output, 0, chanArr, sizeof(SInt32) * out_nChannels);
  423. if (err1 != noErr) {
  424. jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_ChannelMap 0");
  425. printError(err1);
  426. }
  427. }
  428. // Setup stream converters
  429. jack_log("Setup AUHAL input stream converter SR = %ld", samplerate);
  430. srcFormat.mSampleRate = samplerate;
  431. srcFormat.mFormatID = kAudioFormatLinearPCM;
  432. srcFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kLinearPCMFormatFlagIsNonInterleaved;
  433. srcFormat.mBytesPerPacket = sizeof(float);
  434. srcFormat.mFramesPerPacket = 1;
  435. srcFormat.mBytesPerFrame = sizeof(float);
  436. srcFormat.mChannelsPerFrame = outchannels;
  437. srcFormat.mBitsPerChannel = 32;
  438. err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &srcFormat, sizeof(AudioStreamBasicDescription));
  439. if (err1 != noErr) {
  440. jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Input");
  441. printError(err1);
  442. }
  443. jack_log("Setup AUHAL output stream converter SR = %ld", samplerate);
  444. dstFormat.mSampleRate = samplerate;
  445. dstFormat.mFormatID = kAudioFormatLinearPCM;
  446. dstFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kLinearPCMFormatFlagIsNonInterleaved;
  447. dstFormat.mBytesPerPacket = sizeof(float);
  448. dstFormat.mFramesPerPacket = 1;
  449. dstFormat.mBytesPerFrame = sizeof(float);
  450. dstFormat.mChannelsPerFrame = inchannels;
  451. dstFormat.mBitsPerChannel = 32;
  452. err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &dstFormat, sizeof(AudioStreamBasicDescription));
  453. if (err1 != noErr) {
  454. jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Output");
  455. printError(err1);
  456. }
  457. // Setup callbacks
  458. if (inchannels > 0 && outchannels == 0) {
  459. AURenderCallbackStruct output;
  460. output.inputProc = Render;
  461. output.inputProcRefCon = this;
  462. err1 = AudioUnitSetProperty(fAUHAL, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &output, sizeof(output));
  463. if (err1 != noErr) {
  464. jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_SetRenderCallback 1");
  465. printError(err1);
  466. return -1;
  467. }
  468. } else {
  469. AURenderCallbackStruct output;
  470. output.inputProc = Render;
  471. output.inputProcRefCon = this;
  472. err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &output, sizeof(output));
  473. if (err1 != noErr) {
  474. jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_SetRenderCallback 0");
  475. printError(err1);
  476. return -1;
  477. }
  478. }
  479. return 0;
  480. }
  481. void JackCoreAudioAdapter::CloseAUHAL()
  482. {
  483. AudioUnitUninitialize(fAUHAL);
  484. CloseComponent(fAUHAL);
  485. }
  486. int JackCoreAudioAdapter::Open()
  487. {
  488. OSStatus err;
  489. int in_nChannels = 0;
  490. int out_nChannels = 0;
  491. if (SetupDevices("", "", "", "") < 0)
  492. return -1;
  493. if (SetupChannels(true, true, fCaptureChannels, fPlaybackChannels, in_nChannels, out_nChannels, true) < 0)
  494. return -1;
  495. if (SetupBufferSizeAndSampleRate(fBufferSize, fSampleRate) < 0)
  496. return -1;
  497. if (OpenAUHAL(true, true, fCaptureChannels, fPlaybackChannels, in_nChannels, out_nChannels, fBufferSize, fSampleRate, true) < 0)
  498. goto error;
  499. if (SetupBuffers(fCaptureChannels, fPlaybackChannels) < 0)
  500. goto error;
  501. err = AudioOutputUnitStart(fAUHAL);
  502. if (err != noErr)
  503. goto error;
  504. return 0;
  505. error:
  506. Close();
  507. return -1;
  508. }
  509. int JackCoreAudioAdapter::Close()
  510. {
  511. #ifdef JACK_MONITOR
  512. fTable.Save();
  513. #endif
  514. AudioOutputUnitStop(fAUHAL);
  515. DisposeBuffers();
  516. CloseAUHAL();
  517. return 0;
  518. }
  519. int JackCoreAudioAdapter::SetBufferSize(jack_nframes_t buffer_size)
  520. {
  521. JackAudioAdapterInterface::SetBufferSize(buffer_size);
  522. Close();
  523. return Open();
  524. }
  525. } // namespace
  526. #ifdef __cplusplus
  527. extern "C"
  528. {
  529. #endif
  530. EXPORT jack_driver_desc_t* jack_get_descriptor()
  531. {
  532. jack_driver_desc_t *desc;
  533. unsigned int i;
  534. desc = (jack_driver_desc_t*)calloc(1, sizeof(jack_driver_desc_t));
  535. strcpy(desc->name, "coreaudio-adapter");
  536. desc->nparams = 9;
  537. desc->params = (jack_driver_param_desc_t*)calloc(desc->nparams, sizeof(jack_driver_param_desc_t));
  538. i = 0;
  539. strcpy(desc->params[i].name, "channels");
  540. desc->params[i].character = 'c';
  541. desc->params[i].type = JackDriverParamInt;
  542. desc->params[i].value.ui = 0;
  543. strcpy(desc->params[i].short_desc, "Maximum number of channels");
  544. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  545. i++;
  546. strcpy(desc->params[i].name, "inchannels");
  547. desc->params[i].character = 'i';
  548. desc->params[i].type = JackDriverParamInt;
  549. desc->params[i].value.ui = 0;
  550. strcpy(desc->params[i].short_desc, "Maximum number of input channels");
  551. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  552. i++;
  553. strcpy(desc->params[i].name, "outchannels");
  554. desc->params[i].character = 'o';
  555. desc->params[i].type = JackDriverParamInt;
  556. desc->params[i].value.ui = 0;
  557. strcpy(desc->params[i].short_desc, "Maximum number of output channels");
  558. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  559. i++;
  560. strcpy(desc->params[i].name, "capture");
  561. desc->params[i].character = 'C';
  562. desc->params[i].type = JackDriverParamString;
  563. strcpy(desc->params[i].value.str, "will take default CoreAudio input device");
  564. strcpy(desc->params[i].short_desc, "Provide capture ports. Optionally set CoreAudio device name");
  565. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  566. i++;
  567. strcpy(desc->params[i].name, "playback");
  568. desc->params[i].character = 'P';
  569. desc->params[i].type = JackDriverParamString;
  570. strcpy(desc->params[i].value.str, "will take default CoreAudio output device");
  571. strcpy(desc->params[i].short_desc, "Provide playback ports. Optionally set CoreAudio device name");
  572. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  573. i++;
  574. strcpy(desc->params[i].name, "rate");
  575. desc->params[i].character = 'r';
  576. desc->params[i].type = JackDriverParamUInt;
  577. desc->params[i].value.ui = 44100U;
  578. strcpy(desc->params[i].short_desc, "Sample rate");
  579. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  580. i++;
  581. strcpy(desc->params[i].name, "duplex");
  582. desc->params[i].character = 'D';
  583. desc->params[i].type = JackDriverParamBool;
  584. desc->params[i].value.i = TRUE;
  585. strcpy(desc->params[i].short_desc, "Provide both capture and playback ports");
  586. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  587. i++;
  588. strcpy(desc->params[i].name, "device");
  589. desc->params[i].character = 'd';
  590. desc->params[i].type = JackDriverParamString;
  591. strcpy(desc->params[i].value.str, "will take default CoreAudio device name");
  592. strcpy(desc->params[i].short_desc, "CoreAudio device name");
  593. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  594. i++;
  595. strcpy(desc->params[i].name, "list-devices");
  596. desc->params[i].character = 'l';
  597. desc->params[i].type = JackDriverParamBool;
  598. desc->params[i].value.i = TRUE;
  599. strcpy(desc->params[i].short_desc, "Display available CoreAudio devices");
  600. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  601. return desc;
  602. }
  603. #ifdef __cplusplus
  604. }
  605. #endif