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 #include "/Developer/Examples/CoreAudio/PublicUtility/CALatencyLog.h"
00030
00031 namespace Jack
00032 {
00033
00034 #define kVersion 102
00035 #define LOG_SAMPLE_DURATION 3 // in millisecond
00036
00037 typedef UInt8 CAAudioHardwareDeviceSectionID;
00038 #define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01)
00039 #define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00)
00040 #define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00)
00041 #define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF)
00042
00049 class JackCoreAudioDriver : public JackAudioDriver
00050 {
00051
00052 private:
00053
00054 #ifdef DEBUG
00055
00056 #endif
00057
00058 AudioUnit fAUHAL;
00059
00060 AudioBufferList* fJackInputData;
00061 AudioBufferList* fDriverOutputData;
00062
00063 AudioDeviceID fDeviceID;
00064
00065 AudioUnitRenderActionFlags* fActionFags;
00066 AudioTimeStamp* fCurrentTime;
00067
00068 bool fState;
00069
00071 bool fCapturing;
00072 bool fPlaying;
00073
00074 int fInChannels;
00075 int fOutChannels;
00076
00077 char fCaptureUID[256];
00078 char fPlaybackUID[256];
00079
00080 bool fMonitor;
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, int outchannels);
00132 void DisposeBuffers();
00133
00134 int SetupBufferSizeAndSampleRate(jack_nframes_t nframes, 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, JackEngine* engine, JackSynchro** table);
00153 virtual ~JackCoreAudioDriver();
00154
00155 int Open(jack_nframes_t frames_per_cycle,
00156 jack_nframes_t rate,
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 Close();
00167
00168 int Attach();
00169
00170 int Start();
00171 int Stop();
00172
00173 int Read();
00174 int Write();
00175
00176 int SetBufferSize(jack_nframes_t buffer_size);
00177 };
00178
00179 }
00180
00181 #endif