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.

182 lines
5.3KB

  1. /*
  2. Copyright (C) 2004-2006 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. #include "/Developer/Examples/CoreAudio/PublicUtility/CALatencyLog.h"
  23. namespace Jack
  24. {
  25. #define kVersion 102
  26. #define LOG_SAMPLE_DURATION 3 // in millisecond
  27. typedef UInt8 CAAudioHardwareDeviceSectionID;
  28. #define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01)
  29. #define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00)
  30. #define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00)
  31. #define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF)
  32. /*!
  33. \brief The CoreAudio driver.
  34. \todo hardware monitoring
  35. */
  36. class JackCoreAudioDriver : public JackAudioDriver
  37. {
  38. private:
  39. #ifdef DEBUG
  40. //CALatencyLog* fLogFile;
  41. #endif
  42. AudioUnit fAUHAL;
  43. AudioBufferList* fJackInputData;
  44. AudioBufferList* fDriverOutputData;
  45. AudioDeviceID fDeviceID;
  46. AudioUnitRenderActionFlags* fActionFags;
  47. AudioTimeStamp* fCurrentTime;
  48. bool fState;
  49. /// Intitial state
  50. bool fCapturing;
  51. bool fPlaying;
  52. int fInChannels;
  53. int fOutChannels;
  54. char fCaptureUID[256];
  55. char fPlaybackUID[256];
  56. bool fMonitor;
  57. static OSStatus Render(void *inRefCon,
  58. AudioUnitRenderActionFlags *ioActionFlags,
  59. const AudioTimeStamp *inTimeStamp,
  60. UInt32 inBusNumber,
  61. UInt32 inNumberFrames,
  62. AudioBufferList *ioData);
  63. static OSStatus MeasureCallback(AudioDeviceID inDevice,
  64. const AudioTimeStamp* inNow,
  65. const AudioBufferList* inInputData,
  66. const AudioTimeStamp* inInputTime,
  67. AudioBufferList* outOutputData,
  68. const AudioTimeStamp* inOutputTime,
  69. void* inClientData);
  70. static OSStatus DeviceNotificationCallback(AudioDeviceID inDevice,
  71. UInt32 inChannel,
  72. Boolean isInput,
  73. AudioDevicePropertyID inPropertyID,
  74. void* inClientData);
  75. static OSStatus SRNotificationCallback(AudioDeviceID inDevice,
  76. UInt32 inChannel,
  77. Boolean isInput,
  78. AudioDevicePropertyID inPropertyID,
  79. void* inClientData);
  80. OSStatus GetDeviceIDFromUID(const char* UID, AudioDeviceID* id);
  81. OSStatus GetDefaultDevice(AudioDeviceID* id);
  82. OSStatus GetDefaultInputDevice(AudioDeviceID* id);
  83. OSStatus GetDefaultOutputDevice(AudioDeviceID* id);
  84. OSStatus GetDeviceNameFromID(AudioDeviceID id, char* name);
  85. OSStatus GetTotalChannels(AudioDeviceID device, int* channelCount, bool isInput);
  86. // Setup
  87. int SetupDevices(const char* capture_driver_uid,
  88. const char* playback_driver_uid,
  89. char* capture_driver_name,
  90. char* playback_driver_name);
  91. int SetupChannels(bool capturing,
  92. bool playing,
  93. int& inchannels,
  94. int& outchannels,
  95. int& in_nChannels,
  96. int& out_nChannels,
  97. bool strict);
  98. int SetupBuffers(int inchannels, int outchannels);
  99. void DisposeBuffers();
  100. int SetupBufferSizeAndSampleRate(jack_nframes_t nframes, jack_nframes_t samplerate);
  101. int OpenAUHAL(bool capturing,
  102. bool playing,
  103. int inchannels,
  104. int outchannels,
  105. int in_nChannels,
  106. int out_nChannels,
  107. jack_nframes_t nframes,
  108. jack_nframes_t samplerate,
  109. bool strict);
  110. void CloseAUHAL();
  111. int AddListeners();
  112. void RemoveListeners();
  113. public:
  114. JackCoreAudioDriver(const char* name, JackEngine* engine, JackSynchro** table);
  115. virtual ~JackCoreAudioDriver();
  116. int Open(jack_nframes_t frames_per_cycle,
  117. jack_nframes_t rate,
  118. bool capturing,
  119. bool playing,
  120. int chan_in,
  121. int chan_out,
  122. bool monitor,
  123. const char* capture_driver_name,
  124. const char* playback_driver_name,
  125. jack_nframes_t capture_latency,
  126. jack_nframes_t playback_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