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.

150 lines
4.9KB

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