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.

115 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 __JackCoreAudioIOAdapter__
  16. #define __JackCoreAudioIOAdapter__
  17. #include "JackIOAdapter.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 JackCoreAudioIOAdapter : public JackIOAdapterInterface
  30. {
  31. private:
  32. AudioUnit fAUHAL;
  33. AudioBufferList* fInputData;
  34. JackFilter fProducerFilter;
  35. JackFilter fConsumerFilter;
  36. AudioDeviceID fDeviceID;
  37. bool fState;
  38. AudioUnitRenderActionFlags* fActionFags;
  39. AudioTimeStamp* fCurrentTime;
  40. static OSStatus Render(void *inRefCon,
  41. AudioUnitRenderActionFlags *ioActionFlags,
  42. const AudioTimeStamp *inTimeStamp,
  43. UInt32 inBusNumber,
  44. UInt32 inNumberFrames,
  45. AudioBufferList *ioData);
  46. static OSStatus SRNotificationCallback(AudioDeviceID inDevice,
  47. UInt32 inChannel,
  48. Boolean isInput,
  49. AudioDevicePropertyID inPropertyID,
  50. void* inClientData);
  51. OSStatus GetDefaultDevice(AudioDeviceID* id);
  52. OSStatus GetTotalChannels(AudioDeviceID device, int* channelCount, bool isInput);
  53. // Setup
  54. int SetupDevices(const char* capture_driver_uid,
  55. const char* playback_driver_uid,
  56. char* capture_driver_name,
  57. char* playback_driver_name);
  58. int SetupChannels(bool capturing,
  59. bool playing,
  60. int& inchannels,
  61. int& outchannels,
  62. int& in_nChannels,
  63. int& out_nChannels,
  64. bool strict);
  65. int OpenAUHAL(bool capturing,
  66. bool playing,
  67. int inchannels,
  68. int outchannels,
  69. int in_nChannels,
  70. int out_nChannels,
  71. jack_nframes_t nframes,
  72. jack_nframes_t samplerate,
  73. bool strict);
  74. int SetupBufferSizeAndSampleRate(jack_nframes_t nframes, jack_nframes_t samplerate);
  75. int SetupBuffers(int inchannels, int outchannels);
  76. void DisposeBuffers();
  77. void CloseAUHAL();
  78. public:
  79. JackCoreAudioIOAdapter(int input, int output, int buffer_size, float sample_rate)
  80. :JackIOAdapterInterface(input, output, buffer_size, sample_rate),fInputData(0),fState(false)
  81. {}
  82. ~JackCoreAudioIOAdapter()
  83. {}
  84. virtual int Open();
  85. virtual int Close();
  86. };
  87. }
  88. #endif