1 |
iliev |
1829 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* LinuxSampler - modular, streaming capable sampler * |
4 |
|
|
* * |
5 |
schoenebeck |
3054 |
* Copyright (C) 2009 Grigor Iliev * |
6 |
|
|
* Copyright (C) 2011-2013 Andreas Persson * |
7 |
schoenebeck |
3290 |
* Copyright (C) 2014-2017 Christian Schoenebeck * |
8 |
iliev |
1829 |
* * |
9 |
|
|
* This program is free software; you can redistribute it and/or modify * |
10 |
|
|
* it under the terms of the GNU General Public License as published by * |
11 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
12 |
|
|
* (at your option) any later version. * |
13 |
|
|
* * |
14 |
|
|
* This program is distributed in the hope that it will be useful, * |
15 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
16 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
17 |
|
|
* GNU General Public License for more details. * |
18 |
|
|
* * |
19 |
|
|
* You should have received a copy of the GNU General Public License * |
20 |
|
|
* along with this program; if not, write to the Free Software * |
21 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
22 |
|
|
* MA 02111-1307 USA * |
23 |
|
|
***************************************************************************/ |
24 |
|
|
|
25 |
|
|
#include "AudioOutputDeviceCoreAudio.h" |
26 |
|
|
|
27 |
|
|
#include "../../common/global_private.h" |
28 |
|
|
|
29 |
|
|
namespace LinuxSampler { |
30 |
|
|
|
31 |
iliev |
1832 |
void AudioOutputDeviceCoreAudio::AudioQueueListener ( |
32 |
|
|
void *inUserData, AudioQueueRef inAQ, AudioQueuePropertyID inID |
33 |
|
|
) { |
34 |
|
|
switch(inID) { |
35 |
|
|
case kAudioQueueProperty_IsRunning: |
36 |
|
|
|
37 |
|
|
break; |
38 |
|
|
case kAudioQueueProperty_CurrentDevice: |
39 |
|
|
|
40 |
|
|
break; |
41 |
|
|
} |
42 |
|
|
} |
43 |
|
|
|
44 |
iliev |
1829 |
void AudioOutputDeviceCoreAudio::HandleOutputBuffer ( |
45 |
|
|
void *aqData, |
46 |
|
|
AudioQueueRef inAQ, |
47 |
|
|
AudioQueueBufferRef inBuffer |
48 |
|
|
) { |
49 |
|
|
AQPlayerState* pAqData = (AQPlayerState*) aqData; |
50 |
|
|
if (atomic_read(&(pAqData->mIsRunning)) == 0) { |
51 |
|
|
AudioQueueFlush(pAqData->mQueue); |
52 |
|
|
AudioQueueStop (pAqData->mQueue, true); |
53 |
|
|
return; |
54 |
|
|
} |
55 |
iliev |
1832 |
|
56 |
|
|
if(atomic_read(&(pAqData->pDevice->restartQueue))) return; |
57 |
|
|
|
58 |
iliev |
1829 |
uint bufferSize = pAqData->pDevice->uiBufferSize; |
59 |
|
|
|
60 |
|
|
// let all connected engines render 'fragmentSize' sample points |
61 |
|
|
pAqData->pDevice->RenderAudio(bufferSize); |
62 |
|
|
|
63 |
iliev |
1884 |
Float32* pDataBuf = (Float32*)(inBuffer->mAudioData); |
64 |
iliev |
1829 |
|
65 |
|
|
uint uiCoreAudioChannels = pAqData->pDevice->uiCoreAudioChannels; |
66 |
|
|
for (int c = 0; c < uiCoreAudioChannels; c++) { |
67 |
|
|
float* in = pAqData->pDevice->Channels[c]->Buffer(); |
68 |
|
|
for (int i = 0, o = c; i < bufferSize; i++ , o += uiCoreAudioChannels) { |
69 |
iliev |
1884 |
pDataBuf[o] = in[i]; |
70 |
iliev |
1829 |
} |
71 |
|
|
} |
72 |
|
|
|
73 |
iliev |
1884 |
inBuffer->mAudioDataByteSize = (uiCoreAudioChannels * 4) * bufferSize; |
74 |
iliev |
1829 |
|
75 |
|
|
OSStatus res = AudioQueueEnqueueBuffer(pAqData->mQueue, inBuffer, 0, NULL); |
76 |
|
|
if(res) std::cerr << "AudioQueueEnqueueBuffer: Error " << res << std::endl; |
77 |
|
|
} |
78 |
|
|
|
79 |
iliev |
1832 |
void AudioOutputDeviceCoreAudio::DeviceChanged() { |
80 |
|
|
dmsg(1,("Restarting audio queue...")); |
81 |
|
|
atomic_set(&restartQueue, 1); |
82 |
iliev |
1829 |
} |
83 |
|
|
|
84 |
|
|
AudioOutputDeviceCoreAudio::AudioOutputDeviceCoreAudio ( |
85 |
|
|
std::map<String,DeviceCreationParameter*> Parameters |
86 |
iliev |
1832 |
) : AudioOutputDevice(Parameters), Thread(true, true, 1, 0), CurrentDevice(0) { |
87 |
iliev |
1829 |
|
88 |
|
|
dmsg(2,("AudioOutputDeviceCoreAudio::AudioOutputDeviceCoreAudio()\n")); |
89 |
iliev |
1832 |
if(CAAudioDeviceListModel::GetModel()->GetOutputDeviceCount() < 1) { |
90 |
|
|
throw Exception("No audio output device found"); |
91 |
|
|
} |
92 |
iliev |
1829 |
atomic_set(&pausedNew, 0); |
93 |
|
|
pausedOld = 0; |
94 |
iliev |
1832 |
atomic_set(&restartQueue, 0); |
95 |
iliev |
1829 |
|
96 |
|
|
uiCoreAudioChannels = ((DeviceCreationParameterInt*)Parameters["CHANNELS"])->ValueAsInt(); |
97 |
|
|
uint samplerate = ((DeviceCreationParameterInt*)Parameters["SAMPLERATE"])->ValueAsInt(); |
98 |
iliev |
1832 |
uiBufferNumber = ((DeviceCreationParameterInt*)Parameters["BUFFERS"])->ValueAsInt(); |
99 |
iliev |
1829 |
uiBufferSize = ((DeviceCreationParameterInt*)Parameters["BUFFERSIZE"])->ValueAsInt(); |
100 |
iliev |
1832 |
int device = 0; |
101 |
|
|
try { device = ((ParameterDevice*)Parameters["DEVICE"])->GetDeviceIndex(); } |
102 |
|
|
catch(Exception x) { } |
103 |
iliev |
1829 |
|
104 |
iliev |
1832 |
CurrentDevice = CAAudioDeviceListModel::GetModel()->GetOutputDevice(device); |
105 |
|
|
CurrentDevice.AddListener(this); |
106 |
|
|
|
107 |
iliev |
1884 |
memset (&aqPlayerState.mDataFormat, 0, sizeof(AudioStreamBasicDescription)); |
108 |
|
|
|
109 |
iliev |
1829 |
aqPlayerState.mDataFormat.mSampleRate = samplerate; |
110 |
|
|
aqPlayerState.mDataFormat.mFormatID = kAudioFormatLinearPCM; |
111 |
|
|
|
112 |
|
|
aqPlayerState.mDataFormat.mFormatFlags = |
113 |
iliev |
1884 |
kLinearPCMFormatFlagIsFloat | kLinearPCMFormatFlagIsPacked; |
114 |
iliev |
1829 |
|
115 |
iliev |
1884 |
int samplesize = 4; |
116 |
|
|
aqPlayerState.mDataFormat.mBytesPerPacket = uiCoreAudioChannels * samplesize; |
117 |
iliev |
1829 |
aqPlayerState.mDataFormat.mFramesPerPacket = 1; |
118 |
iliev |
1884 |
aqPlayerState.mDataFormat.mBytesPerFrame = uiCoreAudioChannels * samplesize; |
119 |
iliev |
1829 |
aqPlayerState.mDataFormat.mChannelsPerFrame = uiCoreAudioChannels; |
120 |
iliev |
1884 |
aqPlayerState.mDataFormat.mBitsPerChannel = 8 * samplesize; |
121 |
|
|
aqPlayerState.mDataFormat.mReserved = 0; |
122 |
iliev |
1829 |
|
123 |
|
|
aqPlayerState.mBuffers = new AudioQueueBufferRef[uiBufferNumber]; |
124 |
|
|
|
125 |
|
|
aqPlayerState.bufferByteSize = |
126 |
|
|
MaxSamplesPerCycle() * aqPlayerState.mDataFormat.mBytesPerFrame; |
127 |
|
|
|
128 |
|
|
aqPlayerState.mNumPacketsToRead = MaxSamplesPerCycle(); |
129 |
|
|
|
130 |
|
|
aqPlayerState.pDevice = this; |
131 |
|
|
aqPlayerState.mQueue = NULL; |
132 |
|
|
|
133 |
|
|
uint fragmentSize = MaxSamplesPerCycle(); |
134 |
|
|
// create audio channels for this audio device to which the sampler engines can write to |
135 |
|
|
for (int i = 0; i < uiCoreAudioChannels; i++) { |
136 |
|
|
this->Channels.push_back(new AudioChannel(i, fragmentSize)); |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
StartThread(); |
140 |
|
|
|
141 |
|
|
if (!((DeviceCreationParameterBool*)Parameters["ACTIVE"])->ValueAsBool()) { |
142 |
|
|
Stop(); |
143 |
|
|
} |
144 |
|
|
} |
145 |
|
|
|
146 |
persson |
2183 |
AudioOutputDeviceCoreAudio::~AudioOutputDeviceCoreAudio() { |
147 |
schoenebeck |
3290 |
StopThread(); |
148 |
|
|
|
149 |
iliev |
1829 |
atomic_set(&(aqPlayerState.mIsRunning), 0); |
150 |
persson |
2427 |
{ |
151 |
|
|
LockGuard lock(destroyMutex); |
152 |
|
|
AudioQueueDispose(aqPlayerState.mQueue, true); |
153 |
|
|
} |
154 |
iliev |
1829 |
delete [] aqPlayerState.mBuffers; |
155 |
iliev |
1832 |
|
156 |
|
|
CurrentDevice.RemoveListener(this); |
157 |
iliev |
1829 |
} |
158 |
|
|
|
159 |
|
|
String AudioOutputDeviceCoreAudio::Name() { |
160 |
|
|
return "COREAUDIO"; |
161 |
|
|
} |
162 |
|
|
|
163 |
|
|
String AudioOutputDeviceCoreAudio::Description() { |
164 |
|
|
return "Apple CoreAudio"; |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
String AudioOutputDeviceCoreAudio::Version() { |
168 |
schoenebeck |
2494 |
String s = "$Revision$"; |
169 |
iliev |
1829 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
void AudioOutputDeviceCoreAudio::Play() { |
173 |
|
|
atomic_set(&pausedNew, 0); |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
bool AudioOutputDeviceCoreAudio::IsPlaying() { |
177 |
|
|
return !atomic_read(&pausedNew); |
178 |
|
|
} |
179 |
|
|
|
180 |
|
|
void AudioOutputDeviceCoreAudio::Stop() { |
181 |
|
|
atomic_set(&pausedNew, 1); |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
uint AudioOutputDeviceCoreAudio::MaxSamplesPerCycle() { |
185 |
|
|
return uiBufferSize; |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
uint AudioOutputDeviceCoreAudio::SampleRate() { |
189 |
|
|
return aqPlayerState.mDataFormat.mSampleRate; |
190 |
|
|
} |
191 |
|
|
|
192 |
|
|
String AudioOutputDeviceCoreAudio::Driver() { |
193 |
|
|
return Name(); |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
AudioChannel* AudioOutputDeviceCoreAudio::CreateChannel(uint ChannelNr) { |
197 |
|
|
// just create a mix channel |
198 |
|
|
return new AudioChannel(ChannelNr, Channel(ChannelNr % uiCoreAudioChannels)); |
199 |
|
|
} |
200 |
|
|
|
201 |
iliev |
1832 |
void AudioOutputDeviceCoreAudio::FillBuffers() { |
202 |
|
|
for (int i = 0; i < uiBufferNumber; ++i) { |
203 |
|
|
HandleOutputBuffer ( |
204 |
iliev |
1829 |
&aqPlayerState, |
205 |
iliev |
1832 |
aqPlayerState.mQueue, |
206 |
|
|
aqPlayerState.mBuffers[i] |
207 |
iliev |
1829 |
); |
208 |
iliev |
1832 |
} |
209 |
|
|
} |
210 |
iliev |
1829 |
|
211 |
iliev |
1832 |
void AudioOutputDeviceCoreAudio::PrimeAudioQueue() { |
212 |
|
|
OSStatus res = AudioQueuePrime(aqPlayerState.mQueue, 0, NULL); |
213 |
|
|
if(res) { |
214 |
|
|
String s = String("AudioQueuePrime: Error ") + ToString(res); |
215 |
|
|
throw Exception(s); |
216 |
|
|
} |
217 |
|
|
} |
218 |
iliev |
1829 |
|
219 |
iliev |
1884 |
void AudioOutputDeviceCoreAudio::CreateAndStartAudioQueue() throw(Exception) { |
220 |
iliev |
1832 |
OSStatus res = AudioQueueNewOutput ( |
221 |
|
|
&aqPlayerState.mDataFormat, |
222 |
|
|
HandleOutputBuffer, |
223 |
|
|
&aqPlayerState, |
224 |
|
|
CFRunLoopGetCurrent(), |
225 |
|
|
kCFRunLoopCommonModes, |
226 |
|
|
0, |
227 |
|
|
&aqPlayerState.mQueue |
228 |
|
|
); |
229 |
iliev |
1829 |
|
230 |
iliev |
1832 |
if(res) { |
231 |
|
|
String s = String("AudioQueueNewOutput: Error ") + ToString(res); |
232 |
|
|
throw Exception(s); |
233 |
iliev |
1829 |
} |
234 |
|
|
|
235 |
iliev |
1832 |
CFStringRef devUID = CFStringCreateWithCString ( |
236 |
|
|
NULL, CurrentDevice.GetUID().c_str(), kCFStringEncodingASCII |
237 |
|
|
); |
238 |
|
|
res = AudioQueueSetProperty ( |
239 |
|
|
aqPlayerState.mQueue, |
240 |
|
|
kAudioQueueProperty_CurrentDevice, |
241 |
|
|
&devUID, sizeof(CFStringRef) |
242 |
|
|
); |
243 |
|
|
CFRelease(devUID); |
244 |
|
|
|
245 |
|
|
if(res) { |
246 |
|
|
String s = String("Failed to set audio device: ") + ToString(res); |
247 |
|
|
throw Exception(s); |
248 |
|
|
} |
249 |
|
|
|
250 |
iliev |
1829 |
for (int i = 0; i < uiBufferNumber; ++i) { |
251 |
iliev |
1832 |
res = AudioQueueAllocateBuffer ( |
252 |
iliev |
1829 |
aqPlayerState.mQueue, |
253 |
iliev |
1832 |
aqPlayerState.bufferByteSize, |
254 |
|
|
&aqPlayerState.mBuffers[i] |
255 |
iliev |
1829 |
); |
256 |
iliev |
1832 |
|
257 |
|
|
if(res) { |
258 |
|
|
String s = String("AudioQueueAllocateBuffer: Error "); |
259 |
|
|
throw Exception(s + ToString(res)); |
260 |
|
|
} |
261 |
iliev |
1829 |
} |
262 |
|
|
|
263 |
iliev |
1832 |
res = AudioQueueAddPropertyListener ( |
264 |
|
|
aqPlayerState.mQueue, |
265 |
|
|
kAudioQueueProperty_CurrentDevice, |
266 |
|
|
AudioQueueListener, |
267 |
|
|
NULL |
268 |
|
|
); |
269 |
|
|
if(res) std::cerr << "Failed to register device change listener: " << res << std::endl; |
270 |
|
|
|
271 |
|
|
res = AudioQueueAddPropertyListener ( |
272 |
|
|
aqPlayerState.mQueue, |
273 |
|
|
kAudioQueueProperty_IsRunning, |
274 |
|
|
AudioQueueListener, |
275 |
|
|
NULL |
276 |
|
|
); |
277 |
|
|
if(res) std::cerr << "Failed to register running listener: " << res << std::endl; |
278 |
|
|
|
279 |
iliev |
1829 |
Float32 gain = 1.0; |
280 |
|
|
|
281 |
iliev |
1832 |
res = AudioQueueSetParameter ( |
282 |
iliev |
1829 |
aqPlayerState.mQueue, |
283 |
|
|
kAudioQueueParam_Volume, |
284 |
|
|
gain |
285 |
|
|
); |
286 |
|
|
|
287 |
|
|
if(res) std::cerr << "AudioQueueSetParameter: Error " << res << std::endl; |
288 |
|
|
|
289 |
|
|
atomic_set(&(aqPlayerState.mIsRunning), 1); |
290 |
iliev |
1832 |
FillBuffers(); |
291 |
|
|
PrimeAudioQueue(); |
292 |
iliev |
1829 |
|
293 |
|
|
res = AudioQueueStart(aqPlayerState.mQueue, NULL); |
294 |
|
|
if(res) { |
295 |
|
|
String s = String("AudioQueueStart: Error ") + ToString(res); |
296 |
|
|
throw Exception(s); |
297 |
|
|
} |
298 |
iliev |
1832 |
} |
299 |
iliev |
1829 |
|
300 |
iliev |
1832 |
void AudioOutputDeviceCoreAudio::DestroyAudioQueue() { |
301 |
|
|
AudioQueueFlush(aqPlayerState.mQueue); |
302 |
|
|
AudioQueueStop (aqPlayerState.mQueue, true); |
303 |
|
|
AudioQueueDispose(aqPlayerState.mQueue, true); |
304 |
|
|
aqPlayerState.mQueue = NULL; |
305 |
|
|
} |
306 |
|
|
|
307 |
|
|
/** |
308 |
|
|
* Entry point for the thread. |
309 |
|
|
*/ |
310 |
|
|
int AudioOutputDeviceCoreAudio::Main() { |
311 |
iliev |
1835 |
dmsg(1,("CoreAudio thread started\n")); |
312 |
iliev |
1832 |
OSStatus res; |
313 |
|
|
if(aqPlayerState.mQueue == NULL) { |
314 |
|
|
/* |
315 |
|
|
* Need to be run from this thread because of CFRunLoopGetCurrent() |
316 |
|
|
* which returns the CFRunLoop object for the current thread. |
317 |
|
|
*/ |
318 |
iliev |
1884 |
try { CreateAndStartAudioQueue(); } |
319 |
|
|
catch(Exception e) { |
320 |
|
|
std::cerr << "Failed to star audio queue: " + e.Message() << std::endl; |
321 |
|
|
return 0; |
322 |
|
|
} |
323 |
iliev |
1832 |
} |
324 |
|
|
|
325 |
persson |
2427 |
{ |
326 |
|
|
LockGuard lock(destroyMutex); |
327 |
|
|
do { |
328 |
|
|
if(atomic_read(&pausedNew) != pausedOld) { |
329 |
|
|
pausedOld = atomic_read(&pausedNew); |
330 |
iliev |
1829 |
|
331 |
persson |
2427 |
if(pausedOld) { |
332 |
|
|
res = AudioQueuePause(aqPlayerState.mQueue); |
333 |
|
|
if(res) std::cerr << "AudioQueuePause: Error " << res << std::endl; |
334 |
|
|
} else { |
335 |
|
|
res = AudioQueuePrime(aqPlayerState.mQueue, 0, NULL); |
336 |
|
|
if(res) std::cerr << "AudioQueuePrime: Error " << res << std::endl; |
337 |
|
|
res = AudioQueueStart(aqPlayerState.mQueue, NULL); |
338 |
|
|
if(res) std::cerr << "AudioQueueStart: Error " << res << std::endl; |
339 |
|
|
} |
340 |
iliev |
1829 |
} |
341 |
iliev |
1832 |
|
342 |
persson |
2427 |
if(atomic_read(&restartQueue)) { |
343 |
|
|
DestroyAudioQueue(); |
344 |
|
|
CreateAndStartAudioQueue(); |
345 |
|
|
atomic_set(&restartQueue, 0); |
346 |
|
|
dmsg(1,("Audio queue restarted")); |
347 |
iliev |
1832 |
} |
348 |
iliev |
1829 |
|
349 |
persson |
2427 |
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.2, false); |
350 |
|
|
} while (atomic_read(&(aqPlayerState.mIsRunning))); |
351 |
|
|
} |
352 |
iliev |
1829 |
|
353 |
|
|
dmsg(2,("CoreAudio thread stopped\n")); |
354 |
|
|
|
355 |
iliev |
1846 |
pthread_exit(NULL); |
356 |
iliev |
1829 |
return 0; |
357 |
|
|
} |
358 |
|
|
|
359 |
|
|
|
360 |
iliev |
1832 |
// *************** ParameterDevice *************** |
361 |
|
|
// * |
362 |
|
|
|
363 |
|
|
AudioOutputDeviceCoreAudio::ParameterDevice::ParameterDevice() : DeviceCreationParameterString() { |
364 |
|
|
InitWithDefault(); // use default device |
365 |
|
|
} |
366 |
|
|
|
367 |
|
|
AudioOutputDeviceCoreAudio::ParameterDevice::ParameterDevice(String s) |
368 |
|
|
throw (Exception) : DeviceCreationParameterString(s) { |
369 |
|
|
} |
370 |
|
|
|
371 |
|
|
String AudioOutputDeviceCoreAudio::ParameterDevice::Description() { |
372 |
|
|
return "Output device to be used"; |
373 |
|
|
} |
374 |
|
|
|
375 |
|
|
bool AudioOutputDeviceCoreAudio::ParameterDevice::Fix() { |
376 |
|
|
return true; |
377 |
|
|
} |
378 |
|
|
|
379 |
|
|
bool AudioOutputDeviceCoreAudio::ParameterDevice::Mandatory() { |
380 |
|
|
return false; |
381 |
|
|
} |
382 |
|
|
|
383 |
|
|
std::map<String,DeviceCreationParameter*> |
384 |
|
|
AudioOutputDeviceCoreAudio::ParameterDevice::DependsAsParameters() { |
385 |
|
|
return std::map<String,DeviceCreationParameter*>(); // no dependencies |
386 |
|
|
} |
387 |
|
|
|
388 |
|
|
optional<String> |
389 |
|
|
AudioOutputDeviceCoreAudio::ParameterDevice::DefaultAsString(std::map<String,String> Parameters) { |
390 |
|
|
CAAudioDeviceListModel* devs = CAAudioDeviceListModel::GetModel(); |
391 |
|
|
if (devs->GetOutputDeviceCount() < 1) { |
392 |
|
|
throw Exception("AudioOutputDeviceCoreAudio: Can't find any output device"); |
393 |
|
|
} |
394 |
|
|
UInt32 idx = devs->GetOutputDeviceIndex(devs->GetDefaultOutputDeviceID()); |
395 |
|
|
return CreateDeviceName(idx); |
396 |
|
|
} |
397 |
|
|
|
398 |
|
|
std::vector<String> |
399 |
|
|
AudioOutputDeviceCoreAudio::ParameterDevice::PossibilitiesAsString(std::map<String,String> Parameters) { |
400 |
|
|
std::vector<String> deviceNames; |
401 |
|
|
|
402 |
|
|
CAAudioDeviceListModel* devs = CAAudioDeviceListModel::GetModel(); |
403 |
|
|
for(int i = 0; i < devs->GetOutputDeviceCount(); i++) { |
404 |
|
|
if(devs->GetOutputDevice(i).GetChannelNumber() < 1) continue; |
405 |
|
|
|
406 |
|
|
deviceNames.push_back(CreateDeviceName(i)); |
407 |
|
|
} |
408 |
|
|
|
409 |
|
|
return deviceNames; |
410 |
|
|
} |
411 |
|
|
|
412 |
|
|
String AudioOutputDeviceCoreAudio::ParameterDevice::CreateDeviceName(int devIndex) { |
413 |
|
|
CAAudioDeviceListModel* devs = CAAudioDeviceListModel::GetModel(); |
414 |
|
|
// Note that the space " " is used as delimiter to obtain the |
415 |
|
|
// device index. See GetDeviceIndex() |
416 |
|
|
return ToString(devIndex + 1) + " " + devs->GetOutputDevice(devIndex).GetName(); |
417 |
|
|
} |
418 |
|
|
|
419 |
|
|
void AudioOutputDeviceCoreAudio::ParameterDevice::OnSetValue(String s) throw (Exception) { |
420 |
|
|
// not posssible, as parameter is fix |
421 |
|
|
} |
422 |
|
|
|
423 |
|
|
String AudioOutputDeviceCoreAudio::ParameterDevice::Name() { |
424 |
|
|
return "DEVICE"; |
425 |
|
|
} |
426 |
|
|
|
427 |
|
|
int AudioOutputDeviceCoreAudio::ParameterDevice::GetDeviceIndex() { |
428 |
|
|
String s = ValueAsString(); |
429 |
|
|
if(s.empty()) return -1; |
430 |
schoenebeck |
3054 |
int n = (int) s.find(' '); |
431 |
iliev |
1832 |
s = s.substr(0, n); |
432 |
|
|
return ToInt(s) - 1; |
433 |
|
|
} |
434 |
|
|
|
435 |
iliev |
1829 |
// *************** ParameterSampleRate *************** |
436 |
|
|
// * |
437 |
|
|
|
438 |
|
|
AudioOutputDeviceCoreAudio::ParameterSampleRate::ParameterSampleRate() : |
439 |
|
|
AudioOutputDevice::ParameterSampleRate::ParameterSampleRate() { |
440 |
|
|
|
441 |
|
|
} |
442 |
|
|
|
443 |
|
|
AudioOutputDeviceCoreAudio::ParameterSampleRate::ParameterSampleRate(String s) : |
444 |
|
|
AudioOutputDevice::ParameterSampleRate::ParameterSampleRate(s) { |
445 |
|
|
|
446 |
|
|
} |
447 |
|
|
|
448 |
iliev |
1832 |
std::map<String,DeviceCreationParameter*> |
449 |
|
|
AudioOutputDeviceCoreAudio::ParameterSampleRate::DependsAsParameters() { |
450 |
|
|
static ParameterDevice device; |
451 |
|
|
std::map<String,DeviceCreationParameter*> dependencies; |
452 |
|
|
dependencies[device.Name()] = &device; |
453 |
|
|
return dependencies; |
454 |
|
|
} |
455 |
|
|
|
456 |
iliev |
1829 |
optional<int> |
457 |
|
|
AudioOutputDeviceCoreAudio::ParameterSampleRate::DefaultAsInt(std::map<String,String> Parameters) { |
458 |
|
|
dmsg(2,("AudioOutputDeviceCoreAudio::ParameterSampleRate::DefaultAsInt()\n")); |
459 |
iliev |
1832 |
ParameterDevice dev(Parameters["DEVICE"]); |
460 |
|
|
int samplerate = 44100; |
461 |
|
|
|
462 |
|
|
try { |
463 |
|
|
int idx = dev.GetDeviceIndex(); |
464 |
|
|
|
465 |
|
|
CAAudioDeviceListModel* devs = CAAudioDeviceListModel::GetModel(); |
466 |
|
|
samplerate = devs->GetOutputDevice(idx).GetDefaultSamplerate(); |
467 |
|
|
} catch(Exception e) { } |
468 |
|
|
|
469 |
|
|
return samplerate; |
470 |
iliev |
1829 |
} |
471 |
|
|
|
472 |
iliev |
1832 |
std::vector<int> |
473 |
|
|
AudioOutputDeviceCoreAudio::ParameterSampleRate::PossibilitiesAsInt(std::map<String,String> Parameters) { |
474 |
|
|
ParameterDevice dev(Parameters["DEVICE"]); |
475 |
|
|
std::vector<int> srates; |
476 |
iliev |
1829 |
|
477 |
iliev |
1832 |
try { |
478 |
|
|
int idx = dev.GetDeviceIndex(); |
479 |
|
|
CAAudioDeviceListModel* devs = CAAudioDeviceListModel::GetModel(); |
480 |
|
|
srates = devs->GetOutputDevice(idx).GetNominalSamplerates(); |
481 |
|
|
} catch(Exception x) { } |
482 |
|
|
|
483 |
|
|
return srates; |
484 |
|
|
} |
485 |
|
|
|
486 |
|
|
|
487 |
iliev |
1829 |
// *************** ParameterChannels *************** |
488 |
|
|
// * |
489 |
|
|
|
490 |
|
|
AudioOutputDeviceCoreAudio::ParameterChannels::ParameterChannels() : |
491 |
|
|
AudioOutputDevice::ParameterChannels::ParameterChannels() { |
492 |
|
|
|
493 |
|
|
} |
494 |
|
|
|
495 |
|
|
AudioOutputDeviceCoreAudio::ParameterChannels::ParameterChannels(String s) : |
496 |
|
|
AudioOutputDevice::ParameterChannels::ParameterChannels(s) { |
497 |
|
|
|
498 |
|
|
} |
499 |
|
|
|
500 |
|
|
optional<int> |
501 |
|
|
AudioOutputDeviceCoreAudio::ParameterChannels::DefaultAsInt(std::map<String,String> Parameters) { |
502 |
|
|
dmsg(2,("AudioOutputDeviceCoreAudio::ParameterChannels::DefaultAsInt()\n")); |
503 |
iliev |
1832 |
ParameterDevice dev(Parameters["DEVICE"]); |
504 |
|
|
int chns = 2; |
505 |
|
|
|
506 |
|
|
try { |
507 |
|
|
int idx = dev.GetDeviceIndex(); |
508 |
|
|
CAAudioDeviceListModel* devs = CAAudioDeviceListModel::GetModel(); |
509 |
|
|
chns = devs->GetOutputDevice(idx).GetChannelNumber(); |
510 |
|
|
} catch(Exception e) { } |
511 |
|
|
|
512 |
|
|
return chns; |
513 |
iliev |
1829 |
} |
514 |
|
|
|
515 |
iliev |
1832 |
std::vector<int> |
516 |
|
|
AudioOutputDeviceCoreAudio::ParameterChannels::PossibilitiesAsInt(std::map<String,String> Parameters) { |
517 |
|
|
ParameterDevice dev(Parameters["DEVICE"]); |
518 |
|
|
std::vector<int> chns; |
519 |
|
|
|
520 |
|
|
try { |
521 |
|
|
int idx = dev.GetDeviceIndex(); |
522 |
|
|
CAAudioDeviceListModel* devs = CAAudioDeviceListModel::GetModel(); |
523 |
|
|
for(int i = 1; i <= devs->GetOutputDevice(idx).GetChannelNumber(); i++) { |
524 |
|
|
chns.push_back(i); |
525 |
|
|
} |
526 |
|
|
} catch(Exception x) { } |
527 |
|
|
|
528 |
|
|
return chns; |
529 |
|
|
} |
530 |
|
|
|
531 |
iliev |
1829 |
// *************** ParameterBuffers *************** |
532 |
|
|
// * |
533 |
|
|
|
534 |
|
|
AudioOutputDeviceCoreAudio::ParameterBuffers::ParameterBuffers() : DeviceCreationParameterInt() { |
535 |
|
|
InitWithDefault(); |
536 |
|
|
} |
537 |
|
|
|
538 |
|
|
AudioOutputDeviceCoreAudio::ParameterBuffers::ParameterBuffers(String s) |
539 |
|
|
throw (Exception) : DeviceCreationParameterInt(s) { |
540 |
|
|
} |
541 |
|
|
|
542 |
|
|
String AudioOutputDeviceCoreAudio::ParameterBuffers::Description() { |
543 |
|
|
return "Number of audio buffer"; |
544 |
|
|
} |
545 |
|
|
|
546 |
|
|
bool AudioOutputDeviceCoreAudio::ParameterBuffers::Fix() { |
547 |
|
|
return true; |
548 |
|
|
} |
549 |
|
|
|
550 |
|
|
bool AudioOutputDeviceCoreAudio::ParameterBuffers::Mandatory() { |
551 |
|
|
return false; |
552 |
|
|
} |
553 |
|
|
|
554 |
|
|
std::map<String,DeviceCreationParameter*> |
555 |
|
|
AudioOutputDeviceCoreAudio::ParameterBuffers::DependsAsParameters() { |
556 |
|
|
return std::map<String,DeviceCreationParameter*>(); |
557 |
|
|
} |
558 |
|
|
|
559 |
|
|
optional<int> |
560 |
|
|
AudioOutputDeviceCoreAudio::ParameterBuffers::DefaultAsInt(std::map<String,String> Parameters) { |
561 |
|
|
return 3; |
562 |
|
|
} |
563 |
|
|
|
564 |
|
|
optional<int> |
565 |
|
|
AudioOutputDeviceCoreAudio::ParameterBuffers::RangeMinAsInt(std::map<String,String> Parameters) { |
566 |
|
|
return 2; |
567 |
|
|
} |
568 |
|
|
|
569 |
|
|
optional<int> |
570 |
|
|
AudioOutputDeviceCoreAudio::ParameterBuffers::RangeMaxAsInt(std::map<String,String> Parameters) { |
571 |
|
|
return 16; |
572 |
|
|
} |
573 |
|
|
|
574 |
|
|
std::vector<int> |
575 |
|
|
AudioOutputDeviceCoreAudio::ParameterBuffers::PossibilitiesAsInt(std::map<String,String> Parameters) { |
576 |
|
|
return std::vector<int>(); |
577 |
|
|
} |
578 |
|
|
|
579 |
|
|
void AudioOutputDeviceCoreAudio::ParameterBuffers::OnSetValue(int i) throw (Exception) { |
580 |
|
|
// not posssible, as parameter is fix |
581 |
|
|
} |
582 |
|
|
|
583 |
|
|
String AudioOutputDeviceCoreAudio::ParameterBuffers::Name() { |
584 |
|
|
return "BUFFERS"; |
585 |
|
|
} |
586 |
|
|
|
587 |
|
|
// *************** ParameterBufferSize *************** |
588 |
|
|
// * |
589 |
|
|
|
590 |
|
|
AudioOutputDeviceCoreAudio::ParameterBufferSize::ParameterBufferSize() : DeviceCreationParameterInt() { |
591 |
|
|
InitWithDefault(); |
592 |
|
|
} |
593 |
|
|
|
594 |
|
|
AudioOutputDeviceCoreAudio::ParameterBufferSize::ParameterBufferSize(String s) |
595 |
|
|
throw (Exception) : DeviceCreationParameterInt(s) { |
596 |
|
|
} |
597 |
|
|
|
598 |
|
|
String AudioOutputDeviceCoreAudio::ParameterBufferSize::Description() { |
599 |
|
|
return "Size of the audio buffer in sample frames"; |
600 |
|
|
} |
601 |
|
|
|
602 |
|
|
bool AudioOutputDeviceCoreAudio::ParameterBufferSize::Fix() { |
603 |
|
|
return true; |
604 |
|
|
} |
605 |
|
|
|
606 |
|
|
bool AudioOutputDeviceCoreAudio::ParameterBufferSize::Mandatory() { |
607 |
|
|
return false; |
608 |
|
|
} |
609 |
|
|
|
610 |
|
|
std::map<String,DeviceCreationParameter*> |
611 |
|
|
AudioOutputDeviceCoreAudio::ParameterBufferSize::DependsAsParameters() { |
612 |
|
|
return std::map<String,DeviceCreationParameter*>(); |
613 |
|
|
} |
614 |
|
|
|
615 |
|
|
optional<int> |
616 |
|
|
AudioOutputDeviceCoreAudio::ParameterBufferSize::DefaultAsInt(std::map<String,String> Parameters) { |
617 |
iliev |
1884 |
return 256; |
618 |
iliev |
1829 |
} |
619 |
|
|
|
620 |
|
|
optional<int> |
621 |
|
|
AudioOutputDeviceCoreAudio::ParameterBufferSize::RangeMinAsInt(std::map<String,String> Parameters) { |
622 |
|
|
return 32; |
623 |
|
|
} |
624 |
|
|
|
625 |
|
|
optional<int> |
626 |
|
|
AudioOutputDeviceCoreAudio::ParameterBufferSize::RangeMaxAsInt(std::map<String,String> Parameters) { |
627 |
|
|
return 4096; |
628 |
|
|
} |
629 |
|
|
|
630 |
|
|
std::vector<int> |
631 |
|
|
AudioOutputDeviceCoreAudio::ParameterBufferSize::PossibilitiesAsInt(std::map<String,String> Parameters) { |
632 |
|
|
return std::vector<int>(); |
633 |
|
|
} |
634 |
|
|
|
635 |
|
|
void AudioOutputDeviceCoreAudio::ParameterBufferSize::OnSetValue(int i) throw (Exception) { |
636 |
|
|
// not posssible, as parameter is fix |
637 |
|
|
} |
638 |
|
|
|
639 |
|
|
String AudioOutputDeviceCoreAudio::ParameterBufferSize::Name() { |
640 |
|
|
return "BUFFERSIZE"; |
641 |
|
|
} |
642 |
|
|
} // namespace LinuxSampler |