-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0001-Added-scsynth-interop.cpp-and-scsynth-interop.h.patch
567 lines (563 loc) · 18.6 KB
/
0001-Added-scsynth-interop.cpp-and-scsynth-interop.h.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
From 714474d726185226174919d1f06a874f36b0eb54 Mon Sep 17 00:00:00 2001
From: Fabian Aussems <[email protected]>
Date: Sun, 13 Mar 2011 19:53:55 +0100
Subject: [PATCH] Added scsynth-interop.cpp and scsynth-interop.h
---
include/server/scsynth-interop.h | 56 +++++
server/scsynth/CMakeLists.txt | 2 +
server/scsynth/scsynth-interop.cpp | 470 ++++++++++++++++++++++++++++++++++++
3 files changed, 528 insertions(+), 0 deletions(-)
create mode 100644 include/server/scsynth-interop.h
create mode 100644 server/scsynth/scsynth-interop.cpp
diff --git a/include/server/scsynth-interop.h b/include/server/scsynth-interop.h
new file mode 100644
index 0000000..ab27cd2
--- /dev/null
+++ b/include/server/scsynth-interop.h
@@ -0,0 +1,56 @@
+#ifndef _SCSYTNH_INTEROP_
+#define _SCSYNTH_INTEROP_
+
+#ifdef SC_WIN32
+# define SC_DLLEXPORT __declspec(dllexport)
+#else
+# define SC_DLLEXPORT
+#endif
+
+struct ScsynthInteropStartOptions
+{
+ int verbosity;
+ const char* UGensPluginPath;
+ const char* inDeviceName;
+ const char* outDeviceName;
+ int numControlBusChannels;
+ int numAudioBusChannels;
+ int numInputBusChannels;
+ int numOutputBusChannels;
+ int bufLength;
+ int preferredHardwareBufferFrameSize;
+ int preferredSampleRate;
+ int numBuffers;
+ int maxNodes;
+ int maxGraphDefs;
+ int realTimeMemorySize;
+ int maxWireBufs;
+ int numRGens;
+};
+
+extern "C" {
+ SC_DLLEXPORT struct ScsynthInteropStartOptions* scsynth_interop_get_default_start_options();
+ SC_DLLEXPORT int scsynth_interop_get_device_count();
+ SC_DLLEXPORT const char* scsynth_interop_get_device_name(int i);
+ SC_DLLEXPORT int scsynth_interop_get_device_max_input_channels(int i);
+ SC_DLLEXPORT int scsynth_interop_get_device_max_output_channels(int i);
+
+ SC_DLLEXPORT int scsynth_interop_init();
+ SC_DLLEXPORT void* scsynth_interop_start(struct ScsynthInteropStartOptions *options); // returns struct World*
+ SC_DLLEXPORT void scsynth_interop_cleanup();
+ SC_DLLEXPORT void* scsynth_interop_copy_sndbuf(void* world, unsigned index); // world is a struct World* , returns struct SndBuf*
+
+ SC_DLLEXPORT void scsynth_interop_wait_for_quit(void* world); // world is a struct World*
+ SC_DLLEXPORT int scsynth_interop_open_udp(void* world, int inPort); // world is a struct World*
+ SC_DLLEXPORT int scsynth_interop_open_tcp(void* world, int inPort, int inMaxConnections, int inBacklog); // world is a struct World*
+ SC_DLLEXPORT bool scsynth_interop_send_packet(void* world, int inSize, char *inData, void (*infunc)(void*, void*,int)); // world is a struct World*, infunc is a ReplyFunc inFunc,
+
+ SC_DLLEXPORT void scsynth_interop_set_crashed_callback( void (*ptr)(void) );
+ SC_DLLEXPORT void scsynth_interop_crash();
+
+ SC_DLLEXPORT void scsynth_interop_load_plugin(const char *filename);
+ SC_DLLEXPORT void scsynth_interop_set_plugin_loaded_callback( void (*ptr)(const char*) );
+
+}
+
+#endif // _SCSYNTH_INTEROP_
diff --git a/server/scsynth/CMakeLists.txt b/server/scsynth/CMakeLists.txt
index 6b254df..b0bb7c3 100644
--- a/server/scsynth/CMakeLists.txt
+++ b/server/scsynth/CMakeLists.txt
@@ -80,6 +80,8 @@ set(scsynth_sources
SC_World.cpp
Rendezvous.cpp
+ scsynth-interop.cpp
+
${CMAKE_SOURCE_DIR}/common/SC_fftlib.cpp
${CMAKE_SOURCE_DIR}/common/SC_AllocPool.cpp
${CMAKE_SOURCE_DIR}/common/SC_DirUtils.cpp
diff --git a/server/scsynth/scsynth-interop.cpp b/server/scsynth/scsynth-interop.cpp
new file mode 100644
index 0000000..80b3feb
--- /dev/null
+++ b/server/scsynth/scsynth-interop.cpp
@@ -0,0 +1,470 @@
+#include "scsynth-interop.h"
+
+#include "SC_CoreAudio.h"
+#include "SC_WorldOptions.h"
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <memory.h>
+
+#ifdef SC_WIN32
+#include <pthread.h>
+#include <winsock2.h>
+#else
+#include <sys/wait.h>
+#endif
+
+#include "SC_SndBuf.h"
+
+/************************************************************************/
+// External state
+/************************************************************************/
+
+//extern void (*plugin_loaded_callback)(const char*);
+
+/************************************************************************/
+// Global state
+/************************************************************************/
+
+void (*crashed_callback)(void) = NULL;
+#ifndef WIN32
+static struct sigaction old_sa[NSIG];
+#endif
+
+/************************************************************************/
+// Plugin loading
+/************************************************************************/
+
+void scsynth_interop_load_plugin(const char * filename) {
+ scprintf("scsynth_interop_load_plugin: not implemented \n");
+}
+
+void scsynth_interop_set_plugin_loaded_callback( void (*ptr)(const char*) )
+{
+ // plugin_loaded_callback = ptr;
+}
+
+/************************************************************************/
+// Crash detection
+/************************************************************************/
+
+void scsynth_interop_crash()
+{
+ int *ptr = NULL;
+ *ptr = 1;
+}
+
+void scsynth_interop_set_crashed_callback( void (*ptr)(void) )
+{
+ crashed_callback = ptr;
+}
+
+#ifndef WIN32
+void scsynth_interop_sigaction(int signal, siginfo_t *info, void *reserved)
+{
+ if(crashed_callback != NULL)
+ {
+ crashed_callback();
+ }
+ old_sa[signal].sa_handler(signal);
+}
+#endif
+
+void catch_crashes()
+{
+#ifndef WIN32
+ struct sigaction* handler = (struct sigaction*)malloc(sizeof(struct sigaction));
+ memset(handler, 0, sizeof(struct sigaction));
+ handler->sa_sigaction = scsynth_interop_sigaction;
+ handler->sa_flags = SA_RESETHAND;
+/*
+ sigaction(SIGKILL, handler, &old_sa[SIGKILL]);
+ sigaction(SIGABRT, handler, &old_sa[SIGABRT]);
+ sigaction(SIGBUS, handler, &old_sa[SIGBUS]);
+ sigaction(SIGFPE, handler, &old_sa[SIGFPE]);
+ sigaction(SIGSEGV, handler, &old_sa[SIGSEGV]);
+ sigaction(SIGSTKFLT, handler, &old_sa[SIGSTKFLT]);
+ sigaction(SIGPIPE, handler, &old_sa[SIGPIPE]);
+*/
+#endif
+}
+
+/************************************************************************/
+// init / cleanup
+/************************************************************************/
+
+int scsynth_interop_init()
+{
+#ifdef SC_WIN32
+#ifdef SC_WIN32_STATIC_PTHREADS
+ // initialize statically linked pthreads library
+ pthread_win32_process_attach_np();
+#endif
+
+ // initialize winsock
+ WSAData wsaData;
+ int nCode;
+ if ((nCode = WSAStartup(MAKEWORD(1, 1), &wsaData)) != 0) {
+ scprintf( "WSAStartup() failed with error code %d.\n", nCode );
+ return -1;
+ }
+#else // SC_WIN32
+
+ //catch_crashes();
+
+#endif
+ return 0;
+}
+
+void scsynth_interop_cleanup()
+{
+#ifdef SC_WIN32
+ // clean up winsock
+ WSACleanup();
+
+#ifdef SC_WIN32_STATIC_PTHREADS
+ // clean up statically linked pthreads
+ pthread_win32_process_detach_np();
+#endif
+#endif
+}
+
+/************************************************************************/
+// Server start / quit
+/************************************************************************/
+
+#ifdef SC_WIN32
+// according to this page: http://www.mkssoftware.com/docs/man3/setlinebuf.3.asp
+// setlinebuf is equivalent to the setvbuf call below.
+inline int setlinebuf(FILE *stream)
+{
+ return setvbuf( stream, (char*)0, _IONBF, 0 );
+}
+#endif
+
+struct ScsynthInteropStartOptions* scsynth_interop_get_default_start_options()
+{
+ struct ScsynthInteropStartOptions *options = (struct ScsynthInteropStartOptions*)malloc(sizeof(struct ScsynthInteropStartOptions));
+ memset(options, 0, sizeof(struct ScsynthInteropStartOptions));
+ options->numControlBusChannels = kDefaultWorldOptions.mNumControlBusChannels;
+ options->numAudioBusChannels = kDefaultWorldOptions.mNumAudioBusChannels;
+ options->numInputBusChannels = kDefaultWorldOptions.mNumInputBusChannels;
+ options->numOutputBusChannels = kDefaultWorldOptions.mNumOutputBusChannels;
+ options->bufLength = kDefaultWorldOptions.mBufLength;
+ options->preferredHardwareBufferFrameSize = kDefaultWorldOptions.mPreferredHardwareBufferFrameSize;
+ options->preferredSampleRate = kDefaultWorldOptions.mPreferredSampleRate;
+ options->numBuffers = kDefaultWorldOptions.mNumBuffers;
+ options->maxNodes = kDefaultWorldOptions.mMaxNodes;
+ options->maxGraphDefs = kDefaultWorldOptions.mMaxGraphDefs;
+ options->realTimeMemorySize = kDefaultWorldOptions.mRealTimeMemorySize;
+ options->maxWireBufs = kDefaultWorldOptions.mMaxWireBufs;
+ options->numRGens = kDefaultWorldOptions.mNumRGens;
+
+ options->verbosity = 1;
+ options->UGensPluginPath = "../server/plugins/";
+ options->inDeviceName = "";
+ options->outDeviceName = "";
+ return options;
+}
+
+void* scsynth_interop_start(struct ScsynthInteropStartOptions *inOptions)
+{
+ setlinebuf(stdout);
+
+ WorldOptions options = kDefaultWorldOptions;
+
+ if( -1 != inOptions->numControlBusChannels) {
+ options.mNumControlBusChannels = inOptions->numControlBusChannels;
+ }
+ if( -1 != inOptions->numAudioBusChannels) {
+ options.mNumAudioBusChannels = inOptions->numAudioBusChannels;
+ }
+ if( -1 != inOptions->numInputBusChannels) {
+ options.mNumInputBusChannels= inOptions->numInputBusChannels;
+ }
+ if( -1 != inOptions->numOutputBusChannels) {
+ options.mNumOutputBusChannels = inOptions->numOutputBusChannels;
+ }
+ if( -1 != inOptions->bufLength) {
+ options.mBufLength = inOptions->bufLength;
+ }
+ if( -1 != inOptions->preferredHardwareBufferFrameSize) {
+ options.mPreferredHardwareBufferFrameSize = inOptions->preferredHardwareBufferFrameSize;
+ }
+ if( -1 != inOptions->preferredSampleRate) {
+ options.mPreferredSampleRate = inOptions->preferredSampleRate;
+ }
+ if( -1 != inOptions->numBuffers) {
+ options.mNumBuffers = inOptions->numBuffers;
+ }
+ if( -1 != inOptions->maxNodes) {
+ options.mMaxNodes = inOptions->maxNodes;
+ }
+ if( -1 != inOptions->maxGraphDefs) {
+ options.mMaxGraphDefs = inOptions->maxGraphDefs;
+ }
+ if( -1 != inOptions->realTimeMemorySize) {
+ options.mRealTimeMemorySize = inOptions->realTimeMemorySize;
+ }
+ if( -1 != inOptions->maxWireBufs) {
+ options.mMaxWireBufs = inOptions->maxWireBufs;
+ }
+ if( -1 != inOptions->numRGens) {
+ options.mNumRGens = inOptions->numRGens;
+ }
+ if( 0 != strcmp("", inOptions->inDeviceName )) { // not empty
+ options.mInDeviceName = inOptions->inDeviceName;
+ }
+ if( 0 != strcmp("", inOptions->outDeviceName )) { // not empty
+ options.mOutDeviceName = inOptions->outDeviceName;
+ }
+
+ options.mVerbosity = inOptions->verbosity;
+ options.mUGensPluginPath = inOptions->UGensPluginPath;
+
+ struct World *world = World_New(&options);
+ if (!world) return 0;
+
+ if(options.mVerbosity >=0) {
+ scprintf("SuperCollider 3 server ready..\n");
+ }
+
+ fflush(stdout);
+
+ return (void*)world;
+}
+
+
+void scsynth_interop_wait_for_quit(void* w)
+{
+ struct World *inWorld = (struct World*)w;
+ World_WaitForQuit(inWorld);
+}
+
+/************************************************************************/
+// Soundbuffer
+/************************************************************************/
+
+void* scsynth_interop_copy_sndbuf(void* w, unsigned index)
+{
+ struct World *world = (struct World*)w;
+ bool didChange;
+ struct SndBuf* buf = (struct SndBuf*) malloc(sizeof(struct SndBuf));
+ memset(buf, 0, sizeof(struct SndBuf));
+ int serverErr = World_CopySndBuf(world, index, buf, false, &didChange);
+ return (void*)buf;
+}
+
+/************************************************************************/
+// Server communication
+/************************************************************************/
+
+int scsynth_interop_open_udp(void* world, int inPort)
+{
+ struct World *inWorld = (struct World*)world;
+ return World_OpenUDP(inWorld, inPort);
+}
+
+int scsynth_interop_open_tcp(void* world, int inPort, int inMaxConnections, int inBacklog)
+{
+ struct World *inWorld = (struct World*)world;
+
+ return World_OpenTCP(inWorld, inPort, inMaxConnections, inBacklog);
+}
+
+bool scsynth_interop_send_packet(void*world, int inSize, char *inData, void (*func)(void*, void*,int))
+{
+ struct World *inWorld = (struct World*)world;
+ ReplyFunc inFunc = (ReplyFunc)func;
+
+ return World_SendPacket(inWorld, inSize, inData, inFunc);
+}
+
+/************************************************************************/
+// Audio system query functions
+/************************************************************************/
+
+int scsynth_interop_get_device_max_output_channels(int i)
+{
+ int retval = 0;
+#if SC_AUDIO_API == SC_AUDIO_API_PORTAUDIO
+ PaError paerror = Pa_Initialize();
+ if( paerror == paNoError ) {
+ const PaDeviceInfo *pdi;
+ const PaHostApiInfo *apiInfo;
+ pdi = Pa_GetDeviceInfo( i );
+ retval = pdi->maxOutputChannels;
+ Pa_Terminate();
+ }
+#endif
+#if SC_AUDIO_API == SC_AUDIO_API_COREAUDIO
+ UInt32 count;
+ OSStatus err = kAudioHardwareNoError;
+ UInt32 bufferListSize;
+ bool isInput = false;
+ AudioBufferList* bufferList = 0;
+ do {
+ err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &count, 0);
+
+ AudioDeviceID *devices = (AudioDeviceID*)malloc(count);
+ err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &count, devices);
+ if (err != kAudioHardwareNoError) {
+ scprintf("get kAudioHardwarePropertyDevices error %4.4s\n", (char*)&err);
+ free(devices);
+ break;
+ }
+
+ err = AudioDeviceGetPropertyInfo(devices[i], 0, isInput, kAudioDevicePropertyStreamConfiguration, &bufferListSize, 0);
+ if (err != kAudioHardwareNoError) {
+ scprintf("info kAudioDevicePropertyStreamConfiguration error %4.4s A %d %08X\n", (char*)&err, i, devices[i]); break;
+ }
+
+ bufferList = (AudioBufferList*)malloc(bufferListSize);
+ if (err != kAudioHardwareNoError) {
+ scprintf("info kAudioDevicePropertyStreamConfiguration error %4.4s A %d %08X\n", (char*)&err, i, devices[i]); break;
+ }
+ err = AudioDeviceGetProperty(devices[i], 0, isInput, kAudioDevicePropertyStreamConfiguration, &bufferListSize, bufferList);
+
+ for (unsigned int j = 0; j < bufferList->mNumberBuffers; j++) {
+ retval += bufferList->mBuffers[j].mNumberChannels;
+ }
+
+ free(bufferList);
+ free(devices);
+ } while(false);
+#endif
+ return retval;
+}
+
+int scsynth_interop_get_device_max_input_channels(int i)
+{
+ int retval = 0;
+#if SC_AUDIO_API == SC_AUDIO_API_PORTAUDIO
+ PaError paerror = Pa_Initialize();
+ if( paerror == paNoError ) {
+ const PaDeviceInfo *pdi;
+ const PaHostApiInfo *apiInfo;
+ pdi = Pa_GetDeviceInfo( i );
+ retval = pdi->maxInputChannels;
+ Pa_Terminate();
+ }
+#endif
+#if SC_AUDIO_API == SC_AUDIO_API_COREAUDIO
+ UInt32 count;
+ OSStatus err = kAudioHardwareNoError;
+ UInt32 bufferListSize;
+ bool isInput = true;
+ AudioBufferList* bufferList = 0;
+ do {
+ err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &count, 0);
+
+ AudioDeviceID *devices = (AudioDeviceID*)malloc(count);
+ err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &count, devices);
+ if (err != kAudioHardwareNoError) {
+ scprintf("get kAudioHardwarePropertyDevices error %4.4s\n", (char*)&err);
+ free(devices);
+ break;
+ }
+
+ err = AudioDeviceGetPropertyInfo(devices[i], 0, isInput, kAudioDevicePropertyStreamConfiguration, &bufferListSize, 0);
+ if (err != kAudioHardwareNoError) {
+ scprintf("info kAudioDevicePropertyStreamConfiguration error %4.4s A %d %08X\n", (char*)&err, i, devices[i]); break;
+ }
+
+ bufferList = (AudioBufferList*)malloc(bufferListSize);
+ if (err != kAudioHardwareNoError) {
+ scprintf("info kAudioDevicePropertyStreamConfiguration error %4.4s A %d %08X\n", (char*)&err, i, devices[i]); break;
+ }
+ err = AudioDeviceGetProperty(devices[i], 0, isInput, kAudioDevicePropertyStreamConfiguration, &bufferListSize, bufferList);
+
+ for (unsigned int j = 0; j < bufferList->mNumberBuffers; j++) {
+ retval += bufferList->mBuffers[j].mNumberChannels;
+ }
+
+ free(bufferList);
+ free(devices);
+ } while(false);
+#endif
+ return retval;
+}
+
+const char* scsynth_interop_get_device_name(int i)
+{
+ char * retval = (char*)malloc(256*sizeof(char));
+#if SC_AUDIO_API == SC_AUDIO_API_PORTAUDIO
+ PaError paerror = Pa_Initialize();
+ if( paerror == paNoError ) {
+ const PaDeviceInfo *pdi;
+ const PaHostApiInfo *apiInfo;
+ pdi = Pa_GetDeviceInfo( i );
+ apiInfo = Pa_GetHostApiInfo(pdi->hostApi);
+ strcpy(retval, apiInfo->name);
+ strcat(retval, " : ");
+ strcat(retval, pdi->name);
+ Pa_Terminate();
+ }
+#endif
+#if SC_AUDIO_API == SC_AUDIO_API_COREAUDIO
+ UInt32 count;
+ OSStatus err = kAudioHardwareNoError;
+ do {
+ err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &count, 0);
+
+ AudioDeviceID *devices = (AudioDeviceID*)malloc(count);
+ err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &count, devices);
+ if (err != kAudioHardwareNoError) {
+ scprintf("get kAudioHardwarePropertyDevices error %4.4s\n", (char*)&err);
+ free(devices);
+ break;
+ }
+ err = AudioDeviceGetPropertyInfo(devices[i], 0, false, kAudioDevicePropertyDeviceName, &count, 0);
+ if (err != kAudioHardwareNoError) {
+ scprintf("info kAudioDevicePropertyDeviceName error %4.4s A %d %08X\n", (char*)&err, i, devices[i]);
+ break;
+ }
+ char *name = (char*)malloc(count);
+ err = AudioDeviceGetProperty(devices[i], 0, false, kAudioDevicePropertyDeviceName, &count, name);
+ if (err != kAudioHardwareNoError) {
+ scprintf("get kAudioDevicePropertyDeviceName error %4.4s A %d %08X\n", (char*)&err, i, devices[i]);
+ free(name);
+ break;
+ }
+ strcpy(retval, name);
+ free(name);
+ free(devices);
+ } while(false);
+#endif
+ return retval;
+}
+
+int scsynth_interop_get_device_count()
+{
+ int retval = 0;
+#if SC_AUDIO_API == SC_AUDIO_API_PORTAUDIO
+ PaError paerror = Pa_Initialize();
+ if( paerror == paNoError ) {
+ retval = Pa_GetDeviceCount();
+ Pa_Terminate();
+ }
+#endif
+#if SC_AUDIO_API == SC_AUDIO_API_COREAUDIO
+ UInt32 count;
+ OSStatus err = kAudioHardwareNoError;
+ do {
+ err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &count, 0);
+
+ AudioDeviceID *devices = (AudioDeviceID*)malloc(count);
+ err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &count, devices);
+ if (err != kAudioHardwareNoError) {
+ scprintf("get kAudioHardwarePropertyDevices error %4.4s\n", (char*)&err);
+ free(devices);
+ break;
+ }
+
+ retval = count / sizeof(AudioDeviceID);
+ free(devices);
+ } while(false);
+#endif
+ return retval;
+}
--
1.7.1