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
|
/*
SuperCollider real time audio synthesis system
Copyright (c) 2002 James McCartney. All rights reserved.
http://www.audiosynth.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <CoreAudio/AudioHardware.h>
#include "SCBase.h"
#include "VMGlobals.h"
#include "PyrKernel.h"
#include "PyrPrimitive.h"
#include "GC.h"
enum
{
OUT = 0,
IN,
BOTH
};
int listDevices(struct VMGlobals *g, int type)
{
int numDevices, num = 0;
PyrSlot *a = g->sp-2;
AudioObjectPropertyAddress propertyAddress;
propertyAddress.mSelector = kAudioHardwarePropertyDevices;
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
// unsigned long count;
UInt32 count;
// OSStatus err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &count, 0);
OSStatus err = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &count);
AudioDeviceID *devices = (AudioDeviceID*)malloc(count);
// err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &count, devices);
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &count, devices);
if (err!=kAudioHardwareNoError)
{
free(devices);
return 0;
}
numDevices = count / sizeof(AudioDeviceID);
int i;
if (type<BOTH)
{
if(type < IN)
{
propertyAddress.mScope = kAudioDevicePropertyScopeOutput;
} else {
propertyAddress.mScope = kAudioDevicePropertyScopeInput;
}
for (i=0; i<numDevices; i++)
{
Boolean writeable;
propertyAddress.mSelector = kAudioDevicePropertyStreams;
// err = AudioDeviceGetPropertyInfo(devices[i], 0, type, kAudioDevicePropertyStreams, &count, &writeable);
err = AudioObjectGetPropertyDataSize(devices[i], &propertyAddress, 0, NULL, &count);
if (err!=kAudioHardwareNoError)
{
free(devices);
return 0;
}
err = AudioObjectIsPropertySettable(devices[i], &propertyAddress, &writeable);
if (err!=kAudioHardwareNoError)
{
free(devices);
return 0;
}
if (!count) devices[i] = 0;
else num++;
}
}
else num = numDevices;
PyrObject* devArray = newPyrArray(g->gc, num * sizeof(PyrObject), 0, true);
SetObject(a, devArray);
int j = 0;
for (i=0; i<numDevices; i++)
{
if (!devices[i]) continue;
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
propertyAddress.mSelector = kAudioDevicePropertyDeviceName;
// err = AudioDeviceGetPropertyInfo(devices[i], 0, false, kAudioDevicePropertyDeviceName, &count, 0);
err = AudioObjectGetPropertyDataSize(devices[i], &propertyAddress, 0, NULL, &count);
if (err != kAudioHardwareNoError)
{
break;
}
char *name = (char*)malloc(count);
// err = AudioDeviceGetProperty(devices[i], 0, false, kAudioDevicePropertyDeviceName, &count, name);
err = AudioObjectGetPropertyData(devices[i], &propertyAddress, 0, NULL, &count, name);
if (err != kAudioHardwareNoError)
{
free(name);
break;
}
PyrString *string = newPyrString(g->gc, name, 0, true);
SetObject(devArray->slots+j, string);
devArray->size++;
g->gc->GCWriteNew(devArray, (PyrObject*)string); // we know array is white so we can use GCWriteNew
free(name);
j++;
}
free(devices);
return 1;
}
int prListAudioDevices(struct VMGlobals *g, int numArgsPushed)
{
int in = 0;
int out = 0;
slotIntVal(g->sp, &out);
slotIntVal(g->sp-1, &in);
int type;
if (in && out) type = BOTH;
else if (in) type = IN;
else type = OUT;
if (listDevices(g, type)) return errNone;
return errFailed;
}
void initCoreAudioPrimitives()
{
definePrimitive(nextPrimitiveIndex(), 0, "_ListAudioDevices", prListAudioDevices, 3, 0);
}
|