2 Copyright (C) 2004-2008 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __JackCoreAudioDriver__
21 #define __JackCoreAudioDriver__
23 #include <AudioToolbox/AudioConverter.h>
24 #include <CoreAudio/CoreAudio.h>
25 #include <AudioUnit/AudioUnit.h>
26 #include "JackAudioDriver.h"
34 typedef UInt8 CAAudioHardwareDeviceSectionID
;
35 #define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01)
36 #define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00)
37 #define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00)
38 #define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF)
41 \brief The CoreAudio driver.
43 \todo hardware monitoring
46 class JackCoreAudioDriver
: public JackAudioDriver
53 AudioBufferList
* fJackInputData
;
54 AudioBufferList
* fDriverOutputData
;
56 AudioDeviceID fDeviceID
; // Used "duplex" device
57 AudioObjectID fPluginID
; // Used for aggregate device
59 AudioUnitRenderActionFlags
* fActionFags
;
60 AudioTimeStamp
* fCurrentTime
;
71 char fCaptureUID
[256];
72 char fPlaybackUID
[256];
76 float fComputationGrain
;
79 #ifdef MAC_OS_X_VERSION_10_5
80 AudioDeviceIOProcID fMesureCallbackID;
84 static OSStatus
Render(void *inRefCon
,
85 AudioUnitRenderActionFlags
*ioActionFlags
,
86 const AudioTimeStamp
*inTimeStamp
,
88 UInt32 inNumberFrames
,
89 AudioBufferList
*ioData
);
91 static OSStatus
MeasureCallback(AudioDeviceID inDevice
,
92 const AudioTimeStamp
* inNow
,
93 const AudioBufferList
* inInputData
,
94 const AudioTimeStamp
* inInputTime
,
95 AudioBufferList
* outOutputData
,
96 const AudioTimeStamp
* inOutputTime
,
99 static OSStatus
DeviceNotificationCallback(AudioDeviceID inDevice
,
102 AudioDevicePropertyID inPropertyID
,
105 static OSStatus
SRNotificationCallback(AudioDeviceID inDevice
,
108 AudioDevicePropertyID inPropertyID
,
111 OSStatus
GetDeviceIDFromUID(const char* UID
, AudioDeviceID
* id
);
112 OSStatus
GetDefaultDevice(AudioDeviceID
* id
);
113 OSStatus
GetDefaultInputDevice(AudioDeviceID
* id
);
114 OSStatus
GetDefaultOutputDevice(AudioDeviceID
* id
);
115 OSStatus
GetDeviceNameFromID(AudioDeviceID id
, char* name
);
116 OSStatus
GetTotalChannels(AudioDeviceID device
, int& channelCount
, bool isInput
);
119 OSStatus
CreateAggregateDevice(AudioDeviceID captureDeviceID
, AudioDeviceID playbackDeviceID
, AudioDeviceID
* outAggregateDevice
);
120 OSStatus
DestroyAggregateDevice();
122 int SetupDevices(const char* capture_driver_uid
,
123 const char* playback_driver_uid
,
124 char* capture_driver_name
,
125 char* playback_driver_name
);
127 int SetupChannels(bool capturing
,
135 int SetupBuffers(int inchannels
);
136 void DisposeBuffers();
138 int SetupBufferSizeAndSampleRate(jack_nframes_t buffer_size
, jack_nframes_t samplerate
);
140 int OpenAUHAL(bool capturing
,
146 jack_nframes_t nframes
,
147 jack_nframes_t samplerate
,
152 void RemoveListeners();
154 bool TakeHog(AudioDeviceID deviceID
, bool isInput
);
158 JackCoreAudioDriver(const char* name
, const char* alias
, JackLockedEngine
* engine
, JackSynchro
* table
);
159 virtual ~JackCoreAudioDriver();
161 int Open(jack_nframes_t buffer_size
,
162 jack_nframes_t samplerate
,
168 const char* capture_driver_name
,
169 const char* playback_driver_name
,
170 jack_nframes_t capture_latency
,
171 jack_nframes_t playback_latency
,
172 int async_output_latency
,
173 int computation_grain
);
184 // BufferSize can be changed
185 bool IsFixedBufferSize()
190 int SetBufferSize(jack_nframes_t buffer_size
);
193 } // end of namespace