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.

166 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. static OSStatus Render(void *inRefCon,
  51. AudioUnitRenderActionFlags *ioActionFlags,
  52. const AudioTimeStamp *inTimeStamp,
  53. UInt32 inBusNumber,
  54. UInt32 inNumberFrames,
  55. AudioBufferList *ioData);
  56. static OSStatus SRNotificationCallback(AudioDeviceID inDevice,
  57. UInt32 inChannel,
  58. Boolean isInput,
  59. AudioDevicePropertyID inPropertyID,
  60. void* inClientData);
  61. static OSStatus DeviceNotificationCallback(AudioDeviceID inDevice,
  62. UInt32 inChannel,
  63. Boolean isInput,
  64. AudioDevicePropertyID inPropertyID,
  65. void* inClientData);
  66. OSStatus GetDefaultDevice(AudioDeviceID* id);
  67. OSStatus GetTotalChannels(AudioDeviceID device, int& channelCount, bool isInput);
  68. OSStatus GetDeviceIDFromUID(const char* UID, AudioDeviceID* id);
  69. OSStatus GetDefaultInputDevice(AudioDeviceID* id);
  70. OSStatus GetDefaultOutputDevice(AudioDeviceID* id);
  71. OSStatus GetDeviceNameFromID(AudioDeviceID id, char* name);
  72. // Setup
  73. OSStatus CreateAggregateDevice(AudioDeviceID captureDeviceID, AudioDeviceID playbackDeviceID, jack_nframes_t samplerate, AudioDeviceID* outAggregateDevice);
  74. OSStatus CreateAggregateDeviceAux(vector<AudioDeviceID> captureDeviceID, vector<AudioDeviceID> playbackDeviceID, jack_nframes_t samplerate, AudioDeviceID* outAggregateDevice);
  75. OSStatus DestroyAggregateDevice();
  76. bool IsAggregateDevice(AudioDeviceID device);
  77. int SetupDevices(const char* capture_driver_uid,
  78. const char* playback_driver_uid,
  79. char* capture_driver_name,
  80. char* playback_driver_name,
  81. jack_nframes_t samplerate);
  82. int SetupChannels(bool capturing,
  83. bool playing,
  84. int& inchannels,
  85. int& outchannels,
  86. int& in_nChannels,
  87. int& out_nChannels,
  88. bool strict);
  89. int OpenAUHAL(bool capturing,
  90. bool playing,
  91. int inchannels,
  92. int outchannels,
  93. int in_nChannels,
  94. int out_nChannels,
  95. jack_nframes_t buffer_size,
  96. jack_nframes_t samplerate);
  97. int SetupBufferSize(jack_nframes_t buffer_size);
  98. int SetupSampleRate(jack_nframes_t samplerate);
  99. int SetupSampleRateAux(AudioDeviceID inDevice, jack_nframes_t samplerate);
  100. int SetupBuffers(int inchannels);
  101. void DisposeBuffers();
  102. void CloseAUHAL();
  103. int AddListeners();
  104. void RemoveListeners();
  105. public:
  106. JackCoreAudioAdapter( jack_nframes_t buffer_size, jack_nframes_t sample_rate, const JSList* params);
  107. ~JackCoreAudioAdapter()
  108. {}
  109. virtual int Open();
  110. virtual int Close();
  111. virtual int SetSampleRate(jack_nframes_t sample_rate);
  112. virtual int SetBufferSize(jack_nframes_t buffer_size);
  113. };
  114. }
  115. #ifdef __cplusplus
  116. extern "C"
  117. {
  118. #endif
  119. #include "JackCompilerDeps.h"
  120. #include "driver_interface.h"
  121. SERVER_EXPORT jack_driver_desc_t* jack_get_descriptor();
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #endif