this repo has no description
1#include "AudioOutputUnitComponent.h"
2#include <CarbonCore/MacErrors.h>
3#include <cstring>
4
5AudioOutputUnitComponent::AudioOutputUnitComponent()
6: AudioUnitComponent({ CFSTR("Sound card output"), CFSTR("Sound card input") })
7{
8 memset(&m_outputCallback, 0, sizeof(m_outputCallback));
9}
10
11OSStatus AudioOutputUnitComponent::setProperty(AudioUnitPropertyID prop, AudioUnitScope scope, AudioUnitElement elem, const void* data, UInt32 dataSize)
12{
13 switch (prop)
14 {
15 case kAudioOutputUnitProperty_EnableIO:
16 {
17 const UInt32* state;
18
19 if (dataSize != sizeof(UInt32))
20 return kAudioUnitErr_InvalidParameter;
21
22 state = static_cast<const UInt32*>(data);
23
24 if (scope == kAudioUnitScope_Output)
25 {
26 if (elem != 0)
27 return kAudioUnitErr_InvalidElement;
28 m_enableOutput = *state != 0;
29 }
30 else if (scope == kAudioUnitScope_Input)
31 {
32 if (elem != 1)
33 return kAudioUnitErr_InvalidElement;
34 m_enableInput = *state != 0;
35 }
36 else
37 return kAudioUnitErr_InvalidScope;
38
39 return noErr;
40 }
41 case kAudioOutputUnitProperty_SetInputCallback:
42 {
43 if (dataSize != sizeof(AURenderCallbackStruct))
44 return kAudioUnitErr_InvalidParameter;
45 //if (scope == kAudioUnitScope_Output)
46 //{
47 if (elem != 1)
48 return kAudioUnitErr_InvalidElement;
49
50 memcpy(&m_outputCallback, data, sizeof(AURenderCallbackStruct));
51
52 return noErr;
53 //}
54 }
55 default:
56 return AudioUnitComponent::setProperty(prop, scope, elem, data, dataSize);
57 }
58}
59
60OSStatus AudioOutputUnitComponent::getProperty(AudioUnitPropertyID prop, AudioUnitScope scope, AudioUnitElement elem, void* data, UInt32* dataSize)
61{
62 switch (prop)
63 {
64 case kAudioOutputUnitProperty_EnableIO:
65 {
66 UInt32* state;
67
68 if (*dataSize < sizeof(UInt32))
69 return kAudioUnitErr_InvalidParameter;
70
71 state = static_cast<UInt32*>(data);
72
73 if (scope == kAudioUnitScope_Output)
74 {
75 if (elem != 0)
76 return kAudioUnitErr_InvalidElement;
77 *state = m_enableOutput;
78 }
79 else if (scope == kAudioUnitScope_Input)
80 {
81 if (elem != 1)
82 return kAudioUnitErr_InvalidElement;
83 *state = m_enableInput;
84 }
85 else
86 return kAudioUnitErr_InvalidScope;
87
88 *dataSize = sizeof(UInt32);
89 return noErr;
90 }
91 default:
92 return AudioUnitComponent::getProperty(prop, scope, elem, data, dataSize);
93 }
94}
95
96OSStatus AudioOutputUnitComponent::getPropertyInfo(AudioUnitPropertyID prop, AudioUnitScope scope, AudioUnitElement elem, UInt32* dataSize, Boolean* writable)
97{
98 switch (prop)
99 {
100 default:
101 return AudioUnitComponent::getPropertyInfo(prop, scope, elem, dataSize, writable);
102 }
103}
104