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.

161 lines
5.4KB

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