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.

194 lines
6.2KB

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