00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __JackCoreAudioDriver__
00021 #define __JackCoreAudioDriver__
00022
00023 #include <AudioToolbox/AudioConverter.h>
00024 #include <CoreAudio/CoreAudio.h>
00025 #include <AudioUnit/AudioUnit.h>
00026 #include "JackAudioDriver.h"
00027 #include "JackTime.h"
00028
00029 namespace Jack
00030 {
00031
00032 #define kVersion 102
00033
00034 typedef UInt8 CAAudioHardwareDeviceSectionID;
00035 #define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01)
00036 #define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00)
00037 #define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00)
00038 #define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF)
00039
00046 class JackCoreAudioDriver : public JackAudioDriver
00047 {
00048
00049 private:
00050
00051 AudioUnit fAUHAL;
00052
00053 AudioBufferList* fJackInputData;
00054 AudioBufferList* fDriverOutputData;
00055
00056 AudioDeviceID fDeviceID;
00057
00058 AudioUnitRenderActionFlags* fActionFags;
00059 AudioTimeStamp* fCurrentTime;
00060
00061 bool fState;
00062
00063
00064 bool fCapturing;
00065 bool fPlaying;
00066
00067 int fInChannels;
00068 int fOutChannels;
00069
00070 char fCaptureUID[256];
00071 char fPlaybackUID[256];
00072
00073 bool fMonitor;
00074 float fIOUsage;
00075
00076
00077
00078
00079
00080
00081
00082 static OSStatus Render(void *inRefCon,
00083 AudioUnitRenderActionFlags *ioActionFlags,
00084 const AudioTimeStamp *inTimeStamp,
00085 UInt32 inBusNumber,
00086 UInt32 inNumberFrames,
00087 AudioBufferList *ioData);
00088
00089 static OSStatus MeasureCallback(AudioDeviceID inDevice,
00090 const AudioTimeStamp* inNow,
00091 const AudioBufferList* inInputData,
00092 const AudioTimeStamp* inInputTime,
00093 AudioBufferList* outOutputData,
00094 const AudioTimeStamp* inOutputTime,
00095 void* inClientData);
00096
00097 static OSStatus DeviceNotificationCallback(AudioDeviceID inDevice,
00098 UInt32 inChannel,
00099 Boolean isInput,
00100 AudioDevicePropertyID inPropertyID,
00101 void* inClientData);
00102
00103
00104 static OSStatus SRNotificationCallback(AudioDeviceID inDevice,
00105 UInt32 inChannel,
00106 Boolean isInput,
00107 AudioDevicePropertyID inPropertyID,
00108 void* inClientData);
00109
00110 OSStatus GetDeviceIDFromUID(const char* UID, AudioDeviceID* id);
00111 OSStatus GetDefaultDevice(AudioDeviceID* id);
00112 OSStatus GetDefaultInputDevice(AudioDeviceID* id);
00113 OSStatus GetDefaultOutputDevice(AudioDeviceID* id);
00114 OSStatus GetDeviceNameFromID(AudioDeviceID id, char* name);
00115 OSStatus GetTotalChannels(AudioDeviceID device, int& channelCount, bool isInput);
00116
00117
00118 int SetupDevices(const char* capture_driver_uid,
00119 const char* playback_driver_uid,
00120 char* capture_driver_name,
00121 char* playback_driver_name);
00122
00123 int SetupChannels(bool capturing,
00124 bool playing,
00125 int& inchannels,
00126 int& outchannels,
00127 int& in_nChannels,
00128 int& out_nChannels,
00129 bool strict);
00130
00131 int SetupBuffers(int inchannels);
00132 void DisposeBuffers();
00133
00134 int SetupBufferSizeAndSampleRate(jack_nframes_t buffer_size, jack_nframes_t samplerate);
00135
00136 int OpenAUHAL(bool capturing,
00137 bool playing,
00138 int inchannels,
00139 int outchannels,
00140 int in_nChannels,
00141 int out_nChannels,
00142 jack_nframes_t nframes,
00143 jack_nframes_t samplerate,
00144 bool strict);
00145 void CloseAUHAL();
00146
00147 int AddListeners();
00148 void RemoveListeners();
00149
00150 public:
00151
00152 JackCoreAudioDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table);
00153 virtual ~JackCoreAudioDriver();
00154
00155 int Open(jack_nframes_t buffer_size,
00156 jack_nframes_t samplerate,
00157 bool capturing,
00158 bool playing,
00159 int chan_in,
00160 int chan_out,
00161 bool monitor,
00162 const char* capture_driver_name,
00163 const char* playback_driver_name,
00164 jack_nframes_t capture_latency,
00165 jack_nframes_t playback_latency,
00166 int async_output_latency);
00167 int Close();
00168
00169 int Attach();
00170
00171 int Start();
00172 int Stop();
00173
00174 int Read();
00175 int Write();
00176
00177
00178 bool IsFixedBufferSize()
00179 {
00180 return false;
00181 }
00182
00183 int SetBufferSize(jack_nframes_t buffer_size);
00184 };
00185
00186 }
00187
00188 #endif