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