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.

192 lines
6.1KB

  1. /*
  2. Copyright (C) 2004-2008 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #ifndef __JackCoreAudioDriver__
  16. #define __JackCoreAudioDriver__
  17. #include <AudioToolbox/AudioConverter.h>
  18. #include <CoreAudio/CoreAudio.h>
  19. #include <AudioUnit/AudioUnit.h>
  20. #include "JackAudioDriver.h"
  21. #include "JackTime.h"
  22. namespace Jack
  23. {
  24. #define kVersion 102
  25. typedef UInt8 CAAudioHardwareDeviceSectionID;
  26. #define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01)
  27. #define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00)
  28. #define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00)
  29. #define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF)
  30. /*!
  31. \brief The CoreAudio driver.
  32. \todo hardware monitoring
  33. */
  34. class JackCoreAudioDriver : public JackAudioDriver
  35. {
  36. private:
  37. AudioUnit fAUHAL;
  38. AudioBufferList* fJackInputData;
  39. AudioBufferList* fDriverOutputData;
  40. AudioDeviceID fDeviceID;
  41. AudioUnitRenderActionFlags* fActionFags;
  42. AudioTimeStamp* fCurrentTime;
  43. bool fState;
  44. // Initial state
  45. bool fCapturing;
  46. bool fPlaying;
  47. int fInChannels;
  48. int fOutChannels;
  49. char fCaptureUID[256];
  50. char fPlaybackUID[256];
  51. bool fMonitor;
  52. float fIOUsage;
  53. float fComputationGrain;
  54. /*
  55. #ifdef MAC_OS_X_VERSION_10_5
  56. AudioDeviceIOProcID fMesureCallbackID;
  57. #endif
  58. */
  59. static OSStatus Render(void *inRefCon,
  60. AudioUnitRenderActionFlags *ioActionFlags,
  61. const AudioTimeStamp *inTimeStamp,
  62. UInt32 inBusNumber,
  63. UInt32 inNumberFrames,
  64. AudioBufferList *ioData);
  65. static OSStatus MeasureCallback(AudioDeviceID inDevice,
  66. const AudioTimeStamp* inNow,
  67. const AudioBufferList* inInputData,
  68. const AudioTimeStamp* inInputTime,
  69. AudioBufferList* outOutputData,
  70. const AudioTimeStamp* inOutputTime,
  71. void* inClientData);
  72. static OSStatus DeviceNotificationCallback(AudioDeviceID inDevice,
  73. UInt32 inChannel,
  74. Boolean isInput,
  75. AudioDevicePropertyID inPropertyID,
  76. void* inClientData);
  77. static OSStatus SRNotificationCallback(AudioDeviceID inDevice,
  78. UInt32 inChannel,
  79. Boolean isInput,
  80. AudioDevicePropertyID inPropertyID,
  81. void* inClientData);
  82. OSStatus GetDeviceIDFromUID(const char* UID, AudioDeviceID* id);
  83. OSStatus GetDefaultDevice(AudioDeviceID* id);
  84. OSStatus GetDefaultInputDevice(AudioDeviceID* id);
  85. OSStatus GetDefaultOutputDevice(AudioDeviceID* id);
  86. OSStatus GetDeviceNameFromID(AudioDeviceID id, char* name);
  87. OSStatus GetTotalChannels(AudioDeviceID device, int& channelCount, bool isInput);
  88. // Setup
  89. OSStatus CreateAggregateDevice(AudioDeviceID captureDeviceID, AudioDeviceID playbackDeviceID, AudioDeviceID* outAggregateDevice);
  90. int SetupDevices(const char* capture_driver_uid,
  91. const char* playback_driver_uid,
  92. char* capture_driver_name,
  93. char* playback_driver_name);
  94. int SetupChannels(bool capturing,
  95. bool playing,
  96. int& inchannels,
  97. int& outchannels,
  98. int& in_nChannels,
  99. int& out_nChannels,
  100. bool strict);
  101. int SetupBuffers(int inchannels);
  102. void DisposeBuffers();
  103. int SetupBufferSizeAndSampleRate(jack_nframes_t buffer_size, jack_nframes_t samplerate);
  104. int OpenAUHAL(bool capturing,
  105. bool playing,
  106. int inchannels,
  107. int outchannels,
  108. int in_nChannels,
  109. int out_nChannels,
  110. jack_nframes_t nframes,
  111. jack_nframes_t samplerate,
  112. bool strict);
  113. void CloseAUHAL();
  114. int AddListeners();
  115. void RemoveListeners();
  116. public:
  117. JackCoreAudioDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table);
  118. virtual ~JackCoreAudioDriver();
  119. int Open(jack_nframes_t buffer_size,
  120. jack_nframes_t samplerate,
  121. bool capturing,
  122. bool playing,
  123. int chan_in,
  124. int chan_out,
  125. bool monitor,
  126. const char* capture_driver_name,
  127. const char* playback_driver_name,
  128. jack_nframes_t capture_latency,
  129. jack_nframes_t playback_latency,
  130. int async_output_latency,
  131. int computation_grain);
  132. int Close();
  133. int Attach();
  134. int Start();
  135. int Stop();
  136. int Read();
  137. int Write();
  138. // BufferSize can be changed
  139. bool IsFixedBufferSize()
  140. {
  141. return false;
  142. }
  143. int SetBufferSize(jack_nframes_t buffer_size);
  144. };
  145. } // end of namespace
  146. #endif