1 |
iliev |
1829 |
/*************************************************************************** |
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 |
iliev |
1832 |
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 |
iliev |
1829 |
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 |
iliev |
1832 |
|
54 |
|
|
if(atomic_read(&(pAqData->pDevice->restartQueue))) return; |
55 |
|
|
|
56 |
iliev |
1829 |
uint bufferSize = pAqData->pDevice->uiBufferSize; |
57 |
|
|
|
58 |
|
|
// let all connected engines render 'fragmentSize' sample points |
59 |
|
|
pAqData->pDevice->RenderAudio(bufferSize); |
60 |
|
|
|
61 |
iliev |
1884 |
Float32* pDataBuf = (Float32*)(inBuffer->mAudioData); |
62 |
iliev |
1829 |
|
63 |
|
|
uint uiCoreAudioChannels = pAqData->pDevice->uiCoreAudioChannels; |
64 |
|
|
for (int c = 0; c < uiCoreAudioChannels; c++) { |
65 |
|
|
float* in = pAqData->pDevice->Channels[c]->Buffer(); |
66 |
|
|
for (int i = 0, o = c; i < bufferSize; i++ , o += uiCoreAudioChannels) { |
67 |
iliev |
1884 |
pDataBuf[o] = in[i]; |
68 |
iliev |
1829 |
} |
69 |
|
|
} |
70 |
|
|
|
71 |
iliev |
1884 |
inBuffer->mAudioDataByteSize = (uiCoreAudioChannels * 4) * bufferSize; |
72 |
iliev |
1829 |
|
73 |
|
|
OSStatus res = AudioQueueEnqueueBuffer(pAqData->mQueue, inBuffer, 0, NULL); |
74 |
|
|
if(res) std::cerr << "AudioQueueEnqueueBuffer: Error " << res << std::endl; |
75 |
|
|
} |
76 |
|
|
|
77 |
iliev |
1832 |
void AudioOutputDeviceCoreAudio::DeviceChanged() { |
78 |
|
|
dmsg(1,("Restarting audio queue...")); |
79 |
|
|
atomic_set(&restartQueue, 1); |
80 |
iliev |
1829 |
} |
81 |
|
|
|
82 |
|
|
AudioOutputDeviceCoreAudio::AudioOutputDeviceCoreAudio ( |
83 |
|
|
std::map<String,DeviceCreationParameter*> Parameters |
84 |
iliev |
1832 |
) : AudioOutputDevice(Parameters), Thread(true, true, 1, 0), CurrentDevice(0) { |
85 |
iliev |
1829 |
|
86 |
|
|
dmsg(2,("AudioOutputDeviceCoreAudio::AudioOutputDeviceCoreAudio()\n")); |
87 |
iliev |
1832 |
if(CAAudioDeviceListModel::GetModel()->GetOutputDeviceCount() < 1) { |
88 |
|
|
throw Exception("No audio output device found"); |
89 |
|
|
} |
90 |
iliev |
1829 |
atomic_set(&pausedNew, 0); |
91 |
|
|
pausedOld = 0; |
92 |
iliev |
1832 |
atomic_set(&restartQueue, 0); |
93 |
iliev |
1829 |
|
94 |
|
|
uiCoreAudioChannels = ((DeviceCreationParameterInt*)Parameters["CHANNELS"])->ValueAsInt(); |
95 |
|
|
uint samplerate = ((DeviceCreationParameterInt*)Parameters["SAMPLERATE"])->ValueAsInt(); |
96 |
iliev |
1832 |
uiBufferNumber = ((DeviceCreationParameterInt*)Parameters["BUFFERS"])->ValueAsInt(); |
97 |
iliev |
1829 |
uiBufferSize = ((DeviceCreationParameterInt*)Parameters["BUFFERSIZE"])->ValueAsInt(); |
98 |
iliev |
1832 |
int device = 0; |
99 |
|
|
try { device = ((ParameterDevice*)Parameters["DEVICE"])->GetDeviceIndex(); } |
100 |
|
|
catch(Exception x) { } |
101 |
iliev |
1829 |
|
102 |
iliev |
1832 |
CurrentDevice = CAAudioDeviceListModel::GetModel()->GetOutputDevice(device); |
103 |
|
|
CurrentDevice.AddListener(this); |
104 |
|
|
|
105 |
iliev |
1884 |
memset (&aqPlayerState.mDataFormat, 0, sizeof(AudioStreamBasicDescription)); |
106 |
|
|
|
107 |
iliev |
1829 |
aqPlayerState.mDataFormat.mSampleRate = samplerate; |
108 |
|
|
aqPlayerState.mDataFormat.mFormatID = kAudioFormatLinearPCM; |
109 |
|
|
|
110 |
|
|
aqPlayerState.mDataFormat.mFormatFlags = |
111 |
iliev |
1884 |
kLinearPCMFormatFlagIsFloat | kLinearPCMFormatFlagIsPacked; |
112 |
iliev |
1829 |
|
113 |
iliev |
1884 |
int samplesize = 4; |
114 |
|
|
aqPlayerState.mDataFormat.mBytesPerPacket = uiCoreAudioChannels * samplesize; |
115 |
iliev |
1829 |
aqPlayerState.mDataFormat.mFramesPerPacket = 1; |
116 |
iliev |
1884 |
aqPlayerState.mDataFormat.mBytesPerFrame = uiCoreAudioChannels * samplesize; |
117 |
iliev |
1829 |
aqPlayerState.mDataFormat.mChannelsPerFrame = uiCoreAudioChannels; |
118 |
iliev |
1884 |
aqPlayerState.mDataFormat.mBitsPerChannel = 8 * samplesize; |
119 |
|
|
aqPlayerState.mDataFormat.mReserved = 0; |
120 |
iliev |
1829 |
|
121 |
|
|
aqPlayerState.mBuffers = new AudioQueueBufferRef[uiBufferNumber]; |
122 |
|
|
|
123 |
|
|
aqPlayerState.bufferByteSize = |
124 |
|
|
MaxSamplesPerCycle() * aqPlayerState.mDataFormat.mBytesPerFrame; |
125 |
|
|
|
126 |
|
|
aqPlayerState.mNumPacketsToRead = MaxSamplesPerCycle(); |
127 |
|
|
|
128 |
|
|
aqPlayerState.pDevice = this; |
129 |
|
|
aqPlayerState.mQueue = NULL; |
130 |
|
|
|
131 |
|
|
uint fragmentSize = MaxSamplesPerCycle(); |
132 |
|
|
// create audio channels for this audio device to which the sampler engines can write to |
133 |
|
|
for (int i = 0; i < uiCoreAudioChannels; i++) { |
134 |
|
|
this->Channels.push_back(new AudioChannel(i, fragmentSize)); |
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
StartThread(); |
138 |
|
|
|
139 |
|
|
if (!((DeviceCreationParameterBool*)Parameters["ACTIVE"])->ValueAsBool()) { |
140 |
|
|
Stop(); |
141 |
|
|
} |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
AudioOutputDeviceCoreAudio::~AudioOutputDevice() { |
145 |
|
|
atomic_set(&(aqPlayerState.mIsRunning), 0); |
146 |
|
|
destroyMutex.Lock(); |
147 |
|
|
AudioQueueDispose(aqPlayerState.mQueue, true); |
148 |
|
|
destroyMutex.Unlock(); |
149 |
|
|
delete [] aqPlayerState.mBuffers; |
150 |
iliev |
1832 |
|
151 |
|
|
CurrentDevice.RemoveListener(this); |
152 |
iliev |
1829 |
} |
153 |
|
|
|
154 |
|
|
String AudioOutputDeviceCoreAudio::Name() { |
155 |
|
|
return "COREAUDIO"; |
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
String AudioOutputDeviceCoreAudio::Description() { |
159 |
|
|
return "Apple CoreAudio"; |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
String AudioOutputDeviceCoreAudio::Version() { |
163 |
iliev |
1884 |
String s = "$Revision: 1.5 $"; |
164 |
iliev |
1829 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
void AudioOutputDeviceCoreAudio::Play() { |
168 |
|
|
atomic_set(&pausedNew, 0); |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
bool AudioOutputDeviceCoreAudio::IsPlaying() { |
172 |
|
|
return !atomic_read(&pausedNew); |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
void AudioOutputDeviceCoreAudio::Stop() { |
176 |
|
|
atomic_set(&pausedNew, 1); |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
uint AudioOutputDeviceCoreAudio::MaxSamplesPerCycle() { |
180 |
|
|
return uiBufferSize; |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
uint AudioOutputDeviceCoreAudio::SampleRate() { |
184 |
|
|
return aqPlayerState.mDataFormat.mSampleRate; |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
String AudioOutputDeviceCoreAudio::Driver() { |
188 |
|
|
return Name(); |
189 |
|
|
} |
190 |
|
|
|
191 |
|
|
AudioChannel* AudioOutputDeviceCoreAudio::CreateChannel(uint ChannelNr) { |
192 |
|
|
// just create a mix channel |
193 |
|
|
return new AudioChannel(ChannelNr, Channel(ChannelNr % uiCoreAudioChannels)); |
194 |
|
|
} |
195 |
|
|
|
196 |
iliev |
1832 |
void AudioOutputDeviceCoreAudio::FillBuffers() { |
197 |
|
|
for (int i = 0; i < uiBufferNumber; ++i) { |
198 |
|
|
HandleOutputBuffer ( |
199 |
iliev |
1829 |
&aqPlayerState, |
200 |
iliev |
1832 |
aqPlayerState.mQueue, |
201 |
|
|
aqPlayerState.mBuffers[i] |
202 |
iliev |
1829 |
); |
203 |
iliev |
1832 |
} |
204 |
|
|
} |
205 |
iliev |
1829 |
|
206 |
iliev |
1832 |
void AudioOutputDeviceCoreAudio::PrimeAudioQueue() { |
207 |
|
|
OSStatus res = AudioQueuePrime(aqPlayerState.mQueue, 0, NULL); |
208 |
|
|
if(res) { |
209 |
|
|
String s = String("AudioQueuePrime: Error ") + ToString(res); |
210 |
|
|
throw Exception(s); |
211 |
|
|
} |
212 |
|
|
} |
213 |
iliev |
1829 |
|
214 |
iliev |
1884 |
void AudioOutputDeviceCoreAudio::CreateAndStartAudioQueue() throw(Exception) { |
215 |
iliev |
1832 |
OSStatus res = AudioQueueNewOutput ( |
216 |
|
|
&aqPlayerState.mDataFormat, |
217 |
|
|
HandleOutputBuffer, |
218 |
|
|
&aqPlayerState, |
219 |
|
|
CFRunLoopGetCurrent(), |
220 |
|
|
kCFRunLoopCommonModes, |
221 |
|
|
0, |
222 |
|
|
&aqPlayerState.mQueue |
223 |
|
|
); |
224 |
iliev |
1829 |
|
225 |
iliev |
1832 |
if(res) { |
226 |
|
|
String s = String("AudioQueueNewOutput: Error ") + ToString(res); |
227 |
|
|
throw Exception(s); |
228 |
iliev |
1829 |
} |
229 |
|
|
|
230 |
iliev |
1832 |
CFStringRef devUID = CFStringCreateWithCString ( |
231 |
|
|
NULL, CurrentDevice.GetUID().c_str(), kCFStringEncodingASCII |
232 |
|
|
); |
233 |
|
|
res = AudioQueueSetProperty ( |
234 |
|
|
aqPlayerState.mQueue, |
235 |
|
|
kAudioQueueProperty_CurrentDevice, |
236 |
|
|
&devUID, sizeof(CFStringRef) |
237 |
|
|
); |
238 |
|
|
CFRelease(devUID); |
239 |
|
|
|
240 |
|
|
if(res) { |
241 |
|
|
String s = String("Failed to set audio device: ") + ToString(res); |
242 |
|
|
throw Exception(s); |
243 |
|
|
} |
244 |
|
|
|
245 |
iliev |
1829 |
for (int i = 0; i < uiBufferNumber; ++i) { |
246 |
iliev |
1832 |
res = AudioQueueAllocateBuffer ( |
247 |
iliev |
1829 |
aqPlayerState.mQueue, |
248 |
iliev |
1832 |
aqPlayerState.bufferByteSize, |
249 |
|
|
&aqPlayerState.mBuffers[i] |
250 |
iliev |
1829 |
); |
251 |
iliev |
1832 |
|
252 |
|
|
if(res) { |
253 |
|
|
String s = String("AudioQueueAllocateBuffer: Error "); |
254 |
|
|
throw Exception(s + ToString(res)); |
255 |
|
|
} |
256 |
iliev |
1829 |
} |
257 |
|
|
|
258 |
iliev |
1832 |
res = AudioQueueAddPropertyListener ( |
259 |
|
|
aqPlayerState.mQueue, |
260 |
|
|
kAudioQueueProperty_CurrentDevice, |
261 |
|
|
AudioQueueListener, |
262 |
|
|
NULL |
263 |
|
|
); |
264 |
|
|
if(res) std::cerr << "Failed to register device change listener: " << res << std::endl; |
265 |
|
|
|
266 |
|
|
res = AudioQueueAddPropertyListener ( |
267 |
|
|
aqPlayerState.mQueue, |
268 |
|
|
kAudioQueueProperty_IsRunning, |
269 |
|
|
AudioQueueListener, |
270 |
|
|
NULL |
271 |
|
|
); |
272 |
|
|
if(res) std::cerr << "Failed to register running listener: " << res << std::endl; |
273 |
|
|
|
274 |
iliev |
1829 |
Float32 gain = 1.0; |
275 |
|
|
|
276 |
iliev |
1832 |
res = AudioQueueSetParameter ( |
277 |
iliev |
1829 |
aqPlayerState.mQueue, |
278 |
|
|
kAudioQueueParam_Volume, |
279 |
|
|
gain |
280 |
|
|
); |
281 |
|
|
|
282 |
|
|
if(res) std::cerr << "AudioQueueSetParameter: Error " << res << std::endl; |
283 |
|
|
|
284 |
|
|
atomic_set(&(aqPlayerState.mIsRunning), 1); |
285 |
iliev |
1832 |
FillBuffers(); |
286 |
|
|
PrimeAudioQueue(); |
287 |
iliev |
1829 |
|
288 |
|
|
res = AudioQueueStart(aqPlayerState.mQueue, NULL); |
289 |
|
|
if(res) { |
290 |
|
|
String s = String("AudioQueueStart: Error ") + ToString(res); |
291 |
|
|
throw Exception(s); |
292 |
|
|
} |
293 |
iliev |
1832 |
} |
294 |
iliev |
1829 |
|
295 |
iliev |
1832 |
void AudioOutputDeviceCoreAudio::DestroyAudioQueue() { |
296 |
|
|
AudioQueueFlush(aqPlayerState.mQueue); |
297 |
|
|
AudioQueueStop (aqPlayerState.mQueue, true); |
298 |
|
|
AudioQueueDispose(aqPlayerState.mQueue, true); |
299 |
|
|
aqPlayerState.mQueue = NULL; |
300 |
|
|
} |
301 |
|
|
|
302 |
|
|
/** |
303 |
|
|
* Entry point for the thread. |
304 |
|
|
*/ |
305 |
|
|
int AudioOutputDeviceCoreAudio::Main() { |
306 |
iliev |
1835 |
dmsg(1,("CoreAudio thread started\n")); |
307 |
iliev |
1832 |
OSStatus res; |
308 |
|
|
if(aqPlayerState.mQueue == NULL) { |
309 |
|
|
/* |
310 |
|
|
* Need to be run from this thread because of CFRunLoopGetCurrent() |
311 |
|
|
* which returns the CFRunLoop object for the current thread. |
312 |
|
|
*/ |
313 |
iliev |
1884 |
try { CreateAndStartAudioQueue(); } |
314 |
|
|
catch(Exception e) { |
315 |
|
|
std::cerr << "Failed to star audio queue: " + e.Message() << std::endl; |
316 |
|
|
return 0; |
317 |
|
|
} |
318 |
iliev |
1832 |
} |
319 |
|
|
|
320 |
iliev |
1829 |
destroyMutex.Lock(); |
321 |
|
|
do { |
322 |
|
|
if(atomic_read(&pausedNew) != pausedOld) { |
323 |
|
|
pausedOld = atomic_read(&pausedNew); |
324 |
|
|
|
325 |
|
|
if(pausedOld) { |
326 |
|
|
res = AudioQueuePause(aqPlayerState.mQueue); |
327 |
|
|
if(res) std::cerr << "AudioQueuePause: Error " << res << std::endl; |
328 |
|
|
} else { |
329 |
|
|
res = AudioQueuePrime(aqPlayerState.mQueue, 0, NULL); |
330 |
|
|
if(res) std::cerr << "AudioQueuePrime: Error " << res << std::endl; |
331 |
|
|
res = AudioQueueStart(aqPlayerState.mQueue, NULL); |
332 |
|
|
if(res) std::cerr << "AudioQueueStart: Error " << res << std::endl; |
333 |
|
|
} |
334 |
|
|
} |
335 |
iliev |
1832 |
|
336 |
|
|
if(atomic_read(&restartQueue)) { |
337 |
|
|
DestroyAudioQueue(); |
338 |
|
|
try { CreateAndStartAudioQueue(); } |
339 |
|
|
catch(Exception e) { |
340 |
|
|
destroyMutex.Unlock(); |
341 |
|
|
throw e; |
342 |
|
|
} |
343 |
|
|
atomic_set(&restartQueue, 0); |
344 |
|
|
dmsg(1,("Audio queue restarted")); |
345 |
|
|
} |
346 |
iliev |
1829 |
|
347 |
|
|
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.2, false); |
348 |
|
|
} while (atomic_read(&(aqPlayerState.mIsRunning))); |
349 |
|
|
destroyMutex.Unlock(); |
350 |
|
|
|
351 |
|
|
dmsg(2,("CoreAudio thread stopped\n")); |
352 |
|
|
|
353 |
iliev |
1846 |
pthread_exit(NULL); |
354 |
iliev |
1829 |
return 0; |
355 |
|
|
} |
356 |
|
|
|
357 |
|
|
|
358 |
iliev |
1832 |
// *************** 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 = s.find(' '); |
429 |
|
|
s = s.substr(0, n); |
430 |
|
|
return ToInt(s) - 1; |
431 |
|
|
} |
432 |
|
|
|
433 |
iliev |
1829 |
// *************** 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 |
iliev |
1832 |
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 |
iliev |
1829 |
optional<int> |
455 |
|
|
AudioOutputDeviceCoreAudio::ParameterSampleRate::DefaultAsInt(std::map<String,String> Parameters) { |
456 |
|
|
dmsg(2,("AudioOutputDeviceCoreAudio::ParameterSampleRate::DefaultAsInt()\n")); |
457 |
iliev |
1832 |
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 |
iliev |
1829 |
} |
469 |
|
|
|
470 |
iliev |
1832 |
std::vector<int> |
471 |
|
|
AudioOutputDeviceCoreAudio::ParameterSampleRate::PossibilitiesAsInt(std::map<String,String> Parameters) { |
472 |
|
|
ParameterDevice dev(Parameters["DEVICE"]); |
473 |
|
|
std::vector<int> srates; |
474 |
iliev |
1829 |
|
475 |
iliev |
1832 |
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 |
iliev |
1829 |
// *************** 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 |
iliev |
1832 |
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 |
iliev |
1829 |
} |
512 |
|
|
|
513 |
iliev |
1832 |
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 |
iliev |
1829 |
// *************** 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 |
iliev |
1884 |
return 256; |
616 |
iliev |
1829 |
} |
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 |