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.

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