-
Notifications
You must be signed in to change notification settings - Fork 5
/
AudioDeviceInfoPatch.m
137 lines (107 loc) · 3.57 KB
/
AudioDeviceInfoPatch.m
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
#import "AudioDeviceInfoPatch.h"
#import <CoreAudio/CoreAudio.h>
@implementation AudioDeviceInfoPatch : QCPatch
+ (QCPatchExecutionMode)executionModeWithIdentifier:(id)fp8
{
return kQCPatchExecutionModeProvider;
}
+ (BOOL)allowsSubpatchesWithIdentifier:(id)fp8
{
return NO;
}
+ (QCPatchTimeMode)timeModeWithIdentifier:(id)fp8
{
return kQCPatchTimeModeNone;
}
- (id)initWithIdentifier:(id)fp8
{
if(self=[super initWithIdentifier:fp8])
{
[[self userInfo] setObject: @"Kineme Audio Device Info" forKey: @"name"];
}
return self;
}
- (void)enable:(QCOpenGLContext *)context
{
NSMutableArray *inputDevices = [[NSMutableArray alloc] initWithCapacity:16];
NSMutableArray *outputDevices = [[NSMutableArray alloc] initWithCapacity:16];
UInt32 deviceCount;
AudioDeviceID *audioDevices;
{
UInt32 sz;
AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices,&sz,NULL);
audioDevices=(AudioDeviceID *)malloc(sz);
AudioHardwareGetProperty(kAudioHardwarePropertyDevices,&sz,audioDevices);
deviceCount = (sz / sizeof(AudioDeviceID));
}
UInt32 i;
for(i=0;i<deviceCount;++i)
{
NSMutableDictionary *deviceInfoDictionary = [[NSMutableDictionary alloc] initWithCapacity:16];
{
UInt32 sz=sizeof(CFStringRef);
NSString *s;
AudioDeviceGetProperty(audioDevices[i],0,false,kAudioObjectPropertyName,&sz,&s);
[deviceInfoDictionary setObject:s forKey:@"Name"];
[s release];
}
{
UInt32 sz=sizeof(CFStringRef);
NSString *s;
AudioDeviceGetProperty(audioDevices[i],0,false,kAudioObjectPropertyManufacturer,&sz,&s);
[deviceInfoDictionary setObject:s forKey:@"Manufacturer"];
[s release];
}
{
UInt32 sz=sizeof(CFStringRef);
NSString *s;
AudioDeviceGetProperty(audioDevices[i],0,false,kAudioDevicePropertyDeviceUID,&sz,&s);
[deviceInfoDictionary setObject:s forKey:@"UID"];
[s release];
}
NSUInteger inputChannelCount = 0;
{
BOOL isInput=true;
UInt32 sz=sizeof(CFStringRef);
AudioDeviceGetPropertyInfo(audioDevices[i],0,isInput,kAudioDevicePropertyStreamConfiguration,&sz,NULL);
AudioBufferList *bufferList=(AudioBufferList *)malloc(sz);
AudioDeviceGetProperty(audioDevices[i],0,isInput,kAudioDevicePropertyStreamConfiguration,&sz,bufferList);
UInt32 j;
for(j=0;j<bufferList->mNumberBuffers;++j)
inputChannelCount += bufferList->mBuffers[j].mNumberChannels;
free(bufferList);
[deviceInfoDictionary setObject:[NSNumber numberWithInt:inputChannelCount] forKey:@"InputChannels"];
}
NSUInteger outputChannelCount = 0;
{
BOOL isInput=false;
UInt32 sz=sizeof(CFStringRef);
AudioDeviceGetPropertyInfo(audioDevices[i],0,isInput,kAudioDevicePropertyStreamConfiguration,&sz,NULL);
AudioBufferList *bufferList=(AudioBufferList *)malloc(sz);
AudioDeviceGetProperty(audioDevices[i],0,isInput,kAudioDevicePropertyStreamConfiguration,&sz,bufferList);
UInt32 j;
for(j=0;j<bufferList->mNumberBuffers;++j)
outputChannelCount += bufferList->mBuffers[j].mNumberChannels;
free(bufferList);
[deviceInfoDictionary setObject:[NSNumber numberWithInt:outputChannelCount] forKey:@"OutputChannels"];
}
if( inputChannelCount )
[inputDevices addObject:deviceInfoDictionary];
if( outputChannelCount )
[outputDevices addObject:deviceInfoDictionary];
[deviceInfoDictionary release];
}
{
QCStructure *s = [[QCStructure alloc] initWithArray:inputDevices];
[outputInputDevices setStructureValue:s];
[s release];
}
{
QCStructure *s = [[QCStructure alloc] initWithArray:outputDevices];
[outputOutputDevices setStructureValue:s];
[s release];
}
[inputDevices release];
[outputDevices release];
}
@end