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"
38 typedef UInt8 CAAudioHardwareDeviceSectionID
;
39 #define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01)
40 #define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00)
41 #define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00)
42 #define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF)
44 #define WAIT_COUNTER 60
45 #define WAIT_NOTIFICATION_COUNTER 30
48 \brief The CoreAudio driver.
50 \todo hardware monitoring
55 class JackCoreAudioDriver
: public JackAudioDriver
60 JackAC3Encoder
* fAC3Encoder
;
64 AudioBufferList
* fJackInputData
;
65 AudioBufferList
* fDriverOutputData
;
67 AudioDeviceID fDeviceID
; // Used "duplex" device
68 AudioObjectID fPluginID
; // Used for aggregate device
70 AudioUnitRenderActionFlags
* fActionFags
;
71 const AudioTimeStamp
* fCurrentTime
;
76 char fCaptureUID
[256];
77 char fPlaybackUID
[256];
80 float fComputationGrain
;
81 bool fClockDriftCompensate
;
82 bool fDigitalPlayback
;
84 static OSStatus
Render(void *inRefCon
,
85 AudioUnitRenderActionFlags
*ioActionFlags
,
86 const AudioTimeStamp
*inTimeStamp
,
88 UInt32 inNumberFrames
,
89 AudioBufferList
*ioData
);
91 static OSStatus
AudioHardwareNotificationCallback(AudioHardwarePropertyID inPropertyID
,void* inClientData
);
93 static OSStatus
DeviceNotificationCallback(AudioDeviceID inDevice
,
96 AudioDevicePropertyID inPropertyID
,
99 static OSStatus
SRNotificationCallback(AudioDeviceID inDevice
,
102 AudioDevicePropertyID inPropertyID
,
105 static OSStatus
BSNotificationCallback(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
);
117 OSStatus
GetStreamLatencies(AudioDeviceID device
, bool isInput
, vector
<int>& latencies
);
120 OSStatus
CreateAggregateDevice(AudioDeviceID captureDeviceID
, AudioDeviceID playbackDeviceID
, jack_nframes_t samplerate
, AudioDeviceID
* outAggregateDevice
);
121 OSStatus
CreateAggregateDeviceAux(vector
<AudioDeviceID
> captureDeviceID
, vector
<AudioDeviceID
> playbackDeviceID
, jack_nframes_t samplerate
, AudioDeviceID
* outAggregateDevice
);
122 OSStatus
DestroyAggregateDevice();
123 bool IsAggregateDevice(AudioDeviceID device
);
125 int SetupDevices(const char* capture_driver_uid
,
126 const char* playback_driver_uid
,
127 char* capture_driver_name
,
128 char* playback_driver_name
,
129 jack_nframes_t samplerate
,
132 int SetupChannels(bool capturing
,
140 int SetupBuffers(int inchannels
);
141 void DisposeBuffers();
143 int SetupBufferSize(jack_nframes_t buffer_size
);
144 int SetupSampleRate(jack_nframes_t samplerate
);
145 int SetupSampleRateAux(AudioDeviceID inDevice
, jack_nframes_t samplerate
);
147 int OpenAUHAL(bool capturing
,
153 const vector
<int>& chan_in_list
,
154 const vector
<int>& chan_out_list
,
155 jack_nframes_t nframes
,
156 jack_nframes_t samplerate
);
160 void RemoveListeners();
162 bool TakeHogAux(AudioDeviceID deviceID
, bool isInput
);
165 void UpdateLatencies();
167 bool IsDigitalDevice(AudioDeviceID device
);
171 JackCoreAudioDriver(const char* name
, const char* alias
, JackLockedEngine
* engine
, JackSynchro
* table
);
172 virtual ~JackCoreAudioDriver();
174 int Open(jack_nframes_t buffer_size
,
175 jack_nframes_t samplerate
,
180 const char* chan_in_list
,
181 const char* chan_out_list
,
183 const char* capture_driver_name
,
184 const char* playback_driver_name
,
185 jack_nframes_t capture_latency
,
186 jack_nframes_t playback_latency
,
187 int async_output_latency
,
188 int computation_grain
,
204 // BufferSize can be changed
205 bool IsFixedBufferSize()
210 int SetBufferSize(jack_nframes_t buffer_size
);
213 } // end of namespace