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.

177 lines
5.7KB

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