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.

190 lines
6.0KB

  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. /*
  54. #ifdef MAC_OS_X_VERSION_10_5
  55. AudioDeviceIOProcID fMesureCallbackID;
  56. #endif
  57. */
  58. static OSStatus Render(void *inRefCon,
  59. AudioUnitRenderActionFlags *ioActionFlags,
  60. const AudioTimeStamp *inTimeStamp,
  61. UInt32 inBusNumber,
  62. UInt32 inNumberFrames,
  63. AudioBufferList *ioData);
  64. static OSStatus MeasureCallback(AudioDeviceID inDevice,
  65. const AudioTimeStamp* inNow,
  66. const AudioBufferList* inInputData,
  67. const AudioTimeStamp* inInputTime,
  68. AudioBufferList* outOutputData,
  69. const AudioTimeStamp* inOutputTime,
  70. void* inClientData);
  71. static OSStatus DeviceNotificationCallback(AudioDeviceID inDevice,
  72. UInt32 inChannel,
  73. Boolean isInput,
  74. AudioDevicePropertyID inPropertyID,
  75. void* inClientData);
  76. static OSStatus SRNotificationCallback(AudioDeviceID inDevice,
  77. UInt32 inChannel,
  78. Boolean isInput,
  79. AudioDevicePropertyID inPropertyID,
  80. void* inClientData);
  81. OSStatus GetDeviceIDFromUID(const char* UID, AudioDeviceID* id);
  82. OSStatus GetDefaultDevice(AudioDeviceID* id);
  83. OSStatus GetDefaultInputDevice(AudioDeviceID* id);
  84. OSStatus GetDefaultOutputDevice(AudioDeviceID* id);
  85. OSStatus GetDeviceNameFromID(AudioDeviceID id, char* name);
  86. OSStatus GetTotalChannels(AudioDeviceID device, int& channelCount, bool isInput);
  87. // Setup
  88. OSStatus CreateAggregateDevice(AudioDeviceID captureDeviceID, AudioDeviceID playbackDeviceID, AudioDeviceID* outAggregateDevice);
  89. int SetupDevices(const char* capture_driver_uid,
  90. const char* playback_driver_uid,
  91. char* capture_driver_name,
  92. char* playback_driver_name);
  93. int SetupChannels(bool capturing,
  94. bool playing,
  95. int& inchannels,
  96. int& outchannels,
  97. int& in_nChannels,
  98. int& out_nChannels,
  99. bool strict);
  100. int SetupBuffers(int inchannels);
  101. void DisposeBuffers();
  102. int SetupBufferSizeAndSampleRate(jack_nframes_t buffer_size, jack_nframes_t samplerate);
  103. int OpenAUHAL(bool capturing,
  104. bool playing,
  105. int inchannels,
  106. int outchannels,
  107. int in_nChannels,
  108. int out_nChannels,
  109. jack_nframes_t nframes,
  110. jack_nframes_t samplerate,
  111. bool strict);
  112. void CloseAUHAL();
  113. int AddListeners();
  114. void RemoveListeners();
  115. public:
  116. JackCoreAudioDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table);
  117. virtual ~JackCoreAudioDriver();
  118. int Open(jack_nframes_t buffer_size,
  119. jack_nframes_t samplerate,
  120. bool capturing,
  121. bool playing,
  122. int chan_in,
  123. int chan_out,
  124. bool monitor,
  125. const char* capture_driver_name,
  126. const char* playback_driver_name,
  127. jack_nframes_t capture_latency,
  128. jack_nframes_t playback_latency,
  129. int async_output_latency);
  130. int Close();
  131. int Attach();
  132. int Start();
  133. int Stop();
  134. int Read();
  135. int Write();
  136. // BufferSize can be changed
  137. bool IsFixedBufferSize()
  138. {
  139. return false;
  140. }
  141. int SetBufferSize(jack_nframes_t buffer_size);
  142. };
  143. } // end of namespace
  144. #endif