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.

167 lines
5.6KB

  1. /*
  2. Copyright (C) 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 __JackCoreAudioAdapter__
  16. #define __JackCoreAudioAdapter__
  17. #include "JackAudioAdapterInterface.h"
  18. #include "jack.h"
  19. #include "jslist.h"
  20. #include <AudioToolbox/AudioConverter.h>
  21. #include <CoreAudio/CoreAudio.h>
  22. #include <AudioUnit/AudioUnit.h>
  23. #include <vector>
  24. using namespace std;
  25. namespace Jack
  26. {
  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. #define WAIT_COUNTER 60
  33. /*!
  34. \brief Audio adapter using CoreAudio API.
  35. */
  36. class JackCoreAudioAdapter : public JackAudioAdapterInterface
  37. {
  38. private:
  39. AudioUnit fAUHAL;
  40. AudioBufferList* fInputData;
  41. char fCaptureUID[256];
  42. char fPlaybackUID[256];
  43. bool fCapturing;
  44. bool fPlaying;
  45. AudioDeviceID fDeviceID; // Used "duplex" device
  46. AudioObjectID fPluginID; // Used for aggregate device
  47. bool fState;
  48. AudioUnitRenderActionFlags* fActionFags;
  49. AudioTimeStamp* fCurrentTime;
  50. bool fClockDriftCompensate;
  51. static OSStatus Render(void *inRefCon,
  52. AudioUnitRenderActionFlags *ioActionFlags,
  53. const AudioTimeStamp *inTimeStamp,
  54. UInt32 inBusNumber,
  55. UInt32 inNumberFrames,
  56. AudioBufferList *ioData);
  57. static OSStatus SRNotificationCallback(AudioDeviceID inDevice,
  58. UInt32 inChannel,
  59. Boolean isInput,
  60. AudioDevicePropertyID inPropertyID,
  61. void* inClientData);
  62. static OSStatus DeviceNotificationCallback(AudioDeviceID inDevice,
  63. UInt32 inChannel,
  64. Boolean isInput,
  65. AudioDevicePropertyID inPropertyID,
  66. void* inClientData);
  67. OSStatus GetDefaultDevice(AudioDeviceID* id);
  68. OSStatus GetTotalChannels(AudioDeviceID device, int& channelCount, bool isInput);
  69. OSStatus GetDeviceIDFromUID(const char* UID, AudioDeviceID* id);
  70. OSStatus GetDefaultInputDevice(AudioDeviceID* id);
  71. OSStatus GetDefaultOutputDevice(AudioDeviceID* id);
  72. OSStatus GetDeviceNameFromID(AudioDeviceID id, char* name);
  73. // Setup
  74. OSStatus CreateAggregateDevice(AudioDeviceID captureDeviceID, AudioDeviceID playbackDeviceID, jack_nframes_t samplerate, AudioDeviceID* outAggregateDevice);
  75. OSStatus CreateAggregateDeviceAux(vector<AudioDeviceID> captureDeviceID, vector<AudioDeviceID> playbackDeviceID, jack_nframes_t samplerate, AudioDeviceID* outAggregateDevice);
  76. OSStatus DestroyAggregateDevice();
  77. bool IsAggregateDevice(AudioDeviceID device);
  78. int SetupDevices(const char* capture_driver_uid,
  79. const char* playback_driver_uid,
  80. char* capture_driver_name,
  81. char* playback_driver_name,
  82. jack_nframes_t samplerate);
  83. int SetupChannels(bool capturing,
  84. bool playing,
  85. int& inchannels,
  86. int& outchannels,
  87. int& in_nChannels,
  88. int& out_nChannels,
  89. bool strict);
  90. int OpenAUHAL(bool capturing,
  91. bool playing,
  92. int inchannels,
  93. int outchannels,
  94. int in_nChannels,
  95. int out_nChannels,
  96. jack_nframes_t buffer_size,
  97. jack_nframes_t samplerate);
  98. int SetupBufferSize(jack_nframes_t buffer_size);
  99. int SetupSampleRate(jack_nframes_t samplerate);
  100. int SetupSampleRateAux(AudioDeviceID inDevice, jack_nframes_t samplerate);
  101. int SetupBuffers(int inchannels);
  102. void DisposeBuffers();
  103. void CloseAUHAL();
  104. int AddListeners();
  105. void RemoveListeners();
  106. public:
  107. JackCoreAudioAdapter( jack_nframes_t buffer_size, jack_nframes_t sample_rate, const JSList* params);
  108. ~JackCoreAudioAdapter()
  109. {}
  110. virtual int Open();
  111. virtual int Close();
  112. virtual int SetSampleRate(jack_nframes_t sample_rate);
  113. virtual int SetBufferSize(jack_nframes_t buffer_size);
  114. };
  115. }
  116. #ifdef __cplusplus
  117. extern "C"
  118. {
  119. #endif
  120. #include "JackCompilerDeps.h"
  121. #include "driver_interface.h"
  122. SERVER_EXPORT jack_driver_desc_t* jack_get_descriptor();
  123. #ifdef __cplusplus
  124. }
  125. #endif
  126. #endif