Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 249 lines (202 sloc) 5.473 kb
e9b09c0 Completely redesigned public interface. It now uses CFTypes and uses a u...
Peter MacWhinnie authored
1 /*
2 * PKAudioEffect.cpp
3 * PlayerKit
4 *
5 * Created by Peter MacWhinnie on 10/16/10.
6 * Copyright 2010 __MyCompanyName__. All rights reserved.
7 *
8 */
9
10 #import "PKAudioEffect.h"
11 #import "PKAudioPlayerInternal.h"
12
13 struct PKAudioEffect
14 {
15 AUNode node;
16 PKAudioPlayerEngine *engine;
17 };
18
19 #pragma mark Lifecycle
20
21 PK_EXTERN PKAudioEffectRef PKAudioEffectCreate(AudioComponentDescription description, CFErrorRef *outError)
22 {
23 AUNode node = 0;
24 try
25 {
26 node = AudioPlayerState.engine->AddNode(&description);
27 }
28 catch (RBException e)
29 {
30 if(outError) *outError = e.CopyError();
31
32 return NULL;
33 }
34
35 PKAudioEffect *effect = new PKAudioEffect;
36 effect->node = node;
37 effect->engine = AudioPlayerState.engine;
38 effect->engine->Retain();
39
40 return effect;
41 }
42
43 PK_EXTERN Boolean PKAudioEffectRemove(PKAudioEffectRef effect, CFErrorRef *outError)
44 {
45 try
46 {
47 RBParameterAssert(effect);
48
49 effect->engine->RemoveNode(effect->node);
50 effect->engine->Release();
51
52 delete effect;
53 }
54 catch (RBException e)
55 {
56 if(outError) *outError = e.CopyError();
57
58 delete effect;
59
60 return false;
61 }
62
63 return true;
64 }
65
66 #pragma mark -
67 #pragma mark Properties
68
69 PK_EXTERN CFStringRef PKAudioEffectCopyTitle(PKAudioEffectRef effect)
70 {
71 if(effect)
72 {
73 try
74 {
75 return effect->engine->CopyTitleForNode(effect->node);
76 }
77 catch (RBException e)
78 {
79 //Ignore it.
80 }
81 }
82
83 return NULL;
84 }
85
86 #pragma mark -
87
88 PK_EXTERN Boolean PKAudioEffectSetClassInfo(PKAudioEffectRef effect, CFPropertyListRef classInfo, CFErrorRef *outError)
89 {
90 try
91 {
92 RBParameterAssert(effect);
93
94 OSStatus error = PKAudioEffectSetProperty(effect,
95 &classInfo,
96 sizeof(classInfo),
97 kAudioUnitProperty_ClassInfo,
d5bd8f6 Updated effects code.
Peter MacWhinnie authored
98 kAudioUnitScope_Global,
99 0);
e9b09c0 Completely redesigned public interface. It now uses CFTypes and uses a u...
Peter MacWhinnie authored
100 if(error != noErr)
101 {
102 if(outError) *outError = PKCopyError(PKEffectsErrorDomain,
103 error,
104 NULL,
105 CFSTR("Could not set class data. Error code %ld."), error);
106
107 return false;
108 }
109 }
110 catch (RBException e)
111 {
112 if(outError) *outError = e.CopyError();
113
114 return false;
115 }
116
117 return true;
118 }
119
120 PK_EXTERN CFPropertyListRef PKAudioEffectCopyClassInfo(PKAudioEffectRef effect)
121 {
122 CFPropertyListRef classInfo = NULL;
123 UInt32 classInfoSize = sizeof(classInfo);
d5bd8f6 Updated effects code.
Peter MacWhinnie authored
124 if(PKAudioEffectCopyProperty(effect, (void **)&classInfo, &classInfoSize, kAudioUnitProperty_ClassInfo, kAudioUnitScope_Global, 0) == noErr)
e9b09c0 Completely redesigned public interface. It now uses CFTypes and uses a u...
Peter MacWhinnie authored
125 return classInfo;
126
127 return NULL;
128 }
129
130 #pragma mark -
b7ab9aa Functional matrix reverb effect.
Peter MacWhinnie authored
131
132 PK_EXTERN Boolean PKAudioEffectSetEnabled(PKAudioEffectRef effect, Boolean enabled, CFErrorRef *outError)
133 {
134 UInt32 bypass = !enabled;
135 OSStatus error = PKAudioEffectSetProperty(effect,
136 &bypass,
137 sizeof(bypass),
138 kAudioUnitProperty_BypassEffect,
139 kAudioUnitScope_Global,
140 0);
141 if(error != noErr)
142 {
143 if(outError) *outError = PKCopyError(PKEffectsErrorDomain,
144 error,
145 NULL,
146 CFSTR("Could not set enabled. Error code %ld."), error);
147
148 return false;
149 }
150
151 return true;
152 }
153
154 PK_EXTERN Boolean PKAudioEffectIsEnabled(PKAudioEffectRef effect)
155 {
156 UInt32 enabled = 0;
157 UInt32 enabledSize = sizeof(enabled);
158 PKAudioEffectCopyProperty(effect,
159 (void **)&enabled,
160 &enabledSize,
161 kAudioUnitProperty_BypassEffect,
162 kAudioUnitScope_Global,
163 0);
164
165 return enabled;
166 }
167
168 #pragma mark -
e9b09c0 Completely redesigned public interface. It now uses CFTypes and uses a u...
Peter MacWhinnie authored
169 #pragma mark Audio Unit Properties
170
d5bd8f6 Updated effects code.
Peter MacWhinnie authored
171 PK_EXTERN OSStatus PKAudioEffectSetProperty(PKAudioEffectRef effect, const void *inData, UInt32 inSize, AudioUnitPropertyID inPropertyID, AudioUnitScope inScope, AudioUnitElement element)
e9b09c0 Completely redesigned public interface. It now uses CFTypes and uses a u...
Peter MacWhinnie authored
172 {
173 if(!effect)
174 return -50 /* paramErr */;
175
176 try
177 {
d5bd8f6 Updated effects code.
Peter MacWhinnie authored
178 effect->engine->SetPropertyValue(inData, inSize, inPropertyID, inScope, effect->node, element);
e9b09c0 Completely redesigned public interface. It now uses CFTypes and uses a u...
Peter MacWhinnie authored
179 }
180 catch (RBException e)
181 {
182 return e.GetCode();
183 }
184
185 return noErr;
186 }
187
d5bd8f6 Updated effects code.
Peter MacWhinnie authored
188 PK_EXTERN OSStatus PKAudioEffectCopyProperty(PKAudioEffectRef effect, void **outValue, UInt32 *ioSize, AudioUnitPropertyID inPropertyID, AudioUnitScope inScope, AudioUnitElement element)
e9b09c0 Completely redesigned public interface. It now uses CFTypes and uses a u...
Peter MacWhinnie authored
189 {
190 if(!effect)
191 return -50 /* paramErr */;
192
193 try
194 {
d5bd8f6 Updated effects code.
Peter MacWhinnie authored
195 effect->engine->CopyPropertyValue(outValue, ioSize, inPropertyID, inScope, effect->node, element);
e9b09c0 Completely redesigned public interface. It now uses CFTypes and uses a u...
Peter MacWhinnie authored
196 }
197 catch (RBException e)
198 {
199 return e.GetCode();
200 }
201
202 return noErr;
203 }
204
205 #pragma mark -
206 #pragma mark Audio Unit Parameters
207
208 PK_EXTERN OSStatus PKAudioEffectSetParameter(PKAudioEffectRef effect, AudioUnitParameterValue inData, AudioUnitParameterID inPropertyID, AudioUnitScope inScope, UInt32 inBufferOffsetInNumberOfFrames)
209 {
210 if(!effect)
211 return -50 /* paramErr */;
212
213 try
214 {
215 effect->engine->SetParameterValue(inData, inPropertyID, inScope, effect->node, inBufferOffsetInNumberOfFrames);
216 }
217 catch (RBException e)
218 {
219 return e.GetCode();
220 }
221
222 return noErr;
223 }
224
225 PK_EXTERN OSStatus PKAudioEffectCopyParameter(PKAudioEffectRef effect, AudioUnitParameterValue *outValue, AudioUnitParameterID inPropertyID, AudioUnitScope inScope)
226 {
227 if(!effect)
228 return -50 /* paramErr */;
229
230 try
231 {
232 effect->engine->CopyParameterValue(outValue, inPropertyID, inScope, effect->node);
233 }
234 catch (RBException e)
235 {
236 return e.GetCode();
237 }
238
239 return noErr;
240 }
d5bd8f6 Updated effects code.
Peter MacWhinnie authored
241
242 #pragma mark -
243
244 PK_EXTERN OSStatus PKAudioEffectCopyParameterInfo(PKAudioEffectRef effect, AudioUnitParameterID inPropertyID, AudioUnitParameterInfo *outInfo)
245 {
246 UInt32 outInfoSize = sizeof(*outInfo);
247 return PKAudioEffectCopyProperty(effect, (void **)outInfo, &outInfoSize, kAudioUnitProperty_ParameterInfo, kAudioUnitScope_Global, inPropertyID);
248 }
Something went wrong with that request. Please try again.