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