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.

181 lines
5.8KB

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