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.

114 lines
4.2KB

  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 <AudioToolbox/AudioConverter.h>
  20. #include <CoreAudio/CoreAudio.h>
  21. #include <AudioUnit/AudioUnit.h>
  22. namespace Jack
  23. {
  24. typedef UInt8 CAAudioHardwareDeviceSectionID;
  25. #define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01)
  26. #define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00)
  27. #define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00)
  28. #define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF)
  29. class JackCoreAudioAdapter : public JackAudioAdapterInterface
  30. {
  31. private:
  32. AudioUnit fAUHAL;
  33. AudioBufferList* fInputData;
  34. AudioDeviceID fDeviceID;
  35. bool fState;
  36. AudioUnitRenderActionFlags* fActionFags;
  37. AudioTimeStamp* fCurrentTime;
  38. static OSStatus Render(void *inRefCon,
  39. AudioUnitRenderActionFlags *ioActionFlags,
  40. const AudioTimeStamp *inTimeStamp,
  41. UInt32 inBusNumber,
  42. UInt32 inNumberFrames,
  43. AudioBufferList *ioData);
  44. static OSStatus SRNotificationCallback(AudioDeviceID inDevice,
  45. UInt32 inChannel,
  46. Boolean isInput,
  47. AudioDevicePropertyID inPropertyID,
  48. void* inClientData);
  49. OSStatus GetDefaultDevice(AudioDeviceID* id);
  50. OSStatus GetTotalChannels(AudioDeviceID device, int* channelCount, bool isInput);
  51. // Setup
  52. int SetupDevices(const char* capture_driver_uid,
  53. const char* playback_driver_uid,
  54. char* capture_driver_name,
  55. char* playback_driver_name);
  56. int SetupChannels(bool capturing,
  57. bool playing,
  58. int& inchannels,
  59. int& outchannels,
  60. int& in_nChannels,
  61. int& out_nChannels,
  62. bool strict);
  63. int OpenAUHAL(bool capturing,
  64. bool playing,
  65. int inchannels,
  66. int outchannels,
  67. int in_nChannels,
  68. int out_nChannels,
  69. jack_nframes_t nframes,
  70. jack_nframes_t samplerate,
  71. bool strict);
  72. int SetupBufferSizeAndSampleRate(jack_nframes_t nframes, jack_nframes_t samplerate);
  73. int SetupBuffers(int inchannels, int outchannels);
  74. void DisposeBuffers();
  75. void CloseAUHAL();
  76. public:
  77. JackCoreAudioAdapter(int input, int output, jack_nframes_t buffer_size, jack_nframes_t sample_rate)
  78. :JackAudioAdapterInterface(input, output, buffer_size, sample_rate),fInputData(0),fState(false)
  79. {}
  80. ~JackCoreAudioAdapter()
  81. {}
  82. virtual int Open();
  83. virtual int Close();
  84. virtual int SetBufferSize(jack_nframes_t buffer_size);
  85. };
  86. }
  87. #endif