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.

155 lines
5.1KB

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