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.

144 lines
4.4KB

  1. /*
  2. Copyright (C) 2004-2006 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 __JackCoreAudioDriver__
  16. #define __JackCoreAudioDriver__
  17. #include <AudioToolbox/AudioConverter.h>
  18. #include <CoreAudio/CoreAudio.h>
  19. #include <AudioUnit/AudioUnit.h>
  20. #include "JackAudioDriver.h"
  21. #include "JackTime.h"
  22. #include "JackThread.h"
  23. #include "/Developer/Examples/CoreAudio/PublicUtility/CALatencyLog.h"
  24. namespace Jack
  25. {
  26. #define kVersion 102
  27. #define LOG_SAMPLE_DURATION 3 // in millisecond
  28. typedef UInt8 CAAudioHardwareDeviceSectionID;
  29. #define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01)
  30. #define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00)
  31. #define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00)
  32. #define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF)
  33. /*!
  34. \brief The CoreAudio driver.
  35. \todo hardware monitoring
  36. */
  37. class JackCoreAudioDriver : public JackAudioDriver, public JackRunnableInterface
  38. {
  39. private:
  40. #ifdef DEBUG
  41. //CALatencyLog* fLogFile;
  42. #endif
  43. AudioUnit fAUHAL;
  44. AudioBufferList* fJackInputData;
  45. AudioBufferList* fDriverOutputData;
  46. AudioDeviceID fDeviceID;
  47. AudioUnitRenderActionFlags* fActionFags;
  48. AudioTimeStamp* fCurrentTime;
  49. bool fState;
  50. CFAbsoluteTime fStopTime;
  51. UInt32 fRunning;
  52. JackThread* fThread;
  53. static OSStatus Render(void *inRefCon,
  54. AudioUnitRenderActionFlags *ioActionFlags,
  55. const AudioTimeStamp *inTimeStamp,
  56. UInt32 inBusNumber,
  57. UInt32 inNumberFrames,
  58. AudioBufferList *ioData);
  59. static OSStatus MeasureCallback(AudioDeviceID inDevice,
  60. const AudioTimeStamp* inNow,
  61. const AudioBufferList* inInputData,
  62. const AudioTimeStamp* inInputTime,
  63. AudioBufferList* outOutputData,
  64. const AudioTimeStamp* inOutputTime,
  65. void* inClientData);
  66. static OSStatus DeviceNotificationCallback(AudioDeviceID inDevice,
  67. UInt32 inChannel,
  68. Boolean isInput,
  69. AudioDevicePropertyID inPropertyID,
  70. void* inClientData);
  71. static OSStatus SRNotificationCallback(AudioDeviceID inDevice,
  72. UInt32 inChannel,
  73. Boolean isInput,
  74. AudioDevicePropertyID inPropertyID,
  75. void* inClientData);
  76. OSStatus GetDeviceIDFromUID(const char* UID, AudioDeviceID* id);
  77. OSStatus GetDefaultDevice(AudioDeviceID* id);
  78. OSStatus GetDefaultInputDevice(AudioDeviceID* id);
  79. OSStatus GetDefaultOutputDevice(AudioDeviceID* id);
  80. OSStatus GetDeviceNameFromID(AudioDeviceID id, char* name);
  81. OSStatus GetTotalChannels(AudioDeviceID device, long* channelCount, bool isInput);
  82. public:
  83. JackCoreAudioDriver(const char* name, JackEngine* engine, JackSynchro** table);
  84. virtual ~JackCoreAudioDriver();
  85. int Open(jack_nframes_t frames_per_cycle,
  86. jack_nframes_t rate,
  87. bool capturing,
  88. bool playing,
  89. int chan_in,
  90. int chan_out,
  91. bool monitor,
  92. const char* capture_driver_name,
  93. const char* playback_driver_name,
  94. jack_nframes_t capture_latency,
  95. jack_nframes_t playback_latency);
  96. int Close();
  97. int Attach();
  98. int Start();
  99. int Stop();
  100. int Read();
  101. int Write();
  102. int SetBufferSize(jack_nframes_t buffer_size);
  103. bool Execute();
  104. };
  105. } // end of namespace
  106. #endif