-
Notifications
You must be signed in to change notification settings - Fork 2
/
PKDelayEffect.cpp
150 lines (126 loc) · 4.34 KB
/
PKDelayEffect.cpp
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
/*
* PKDelayEffect.cpp
* PlayerKit
*
* Created by Peter MacWhinnie on 1/14/11.
* Copyright 2011 __MyCompanyName__. All rights reserved.
*
*/
#include "PKDelayEffect.h"
#include "CoreAudioErrors.h"
#include <iostream>
#pragma mark Creation
PK_EXTERN PKDelayEffectRef PKDelayEffectCreate(CFErrorRef *outError)
{
AudioComponentDescription delayDescription = {
kAudioUnitType_Effect,
kAudioUnitSubType_Delay,
kAudioUnitManufacturer_Apple,
};
return PKAudioEffectCreate(delayDescription, outError);
}
#pragma mark -
#pragma mark Properties
PK_EXTERN Boolean PKDelayEffectSetAmount(PKDelayEffectRef effect, AudioUnitParameterValue value, CFErrorRef *outError)
{
OSStatus error = PKAudioEffectSetParameter(effect,
value,
kDelayParam_WetDryMix,
kAudioUnitScope_Global,
0);
if(error != noErr)
{
if(outError) *outError = PKCopyError(PKEffectsErrorDomain,
error,
NULL,
CFSTR("Could not set delay amount, Error %@ (%d)."), CoreAudioGetErrorName(error), error);
return false;
}
return true;
}
PK_EXTERN AudioUnitParameterValue PKDelayEffectGetAmount(PKDelayEffectRef effect)
{
AudioUnitParameterValue value = 0.0;
OSStatus error = PKAudioEffectCopyParameter(effect, &value, kDelayParam_WetDryMix, kAudioUnitScope_Global);
if(error != noErr)
std::cerr << __PRETTY_FUNCTION__ << ": Could not get value of amount. Ignoring error " << error << "." << std::endl;
return value;
}
#pragma mark -
PK_EXTERN Boolean PKDelayEffectSetDelayTime(PKDelayEffectRef effect, AudioUnitParameterValue value, CFErrorRef *outError)
{
OSStatus error = PKAudioEffectSetParameter(effect,
value,
kDelayParam_DelayTime,
kAudioUnitScope_Global,
0);
if(error != noErr)
{
if(outError) *outError = PKCopyError(PKEffectsErrorDomain,
error,
NULL,
CFSTR("Could not set delay time, Error %@ (%d)."), CoreAudioGetErrorName(error), error);
return false;
}
return true;
}
PK_EXTERN AudioUnitParameterValue PKDelayEffectGetDelayTime(PKDelayEffectRef effect)
{
AudioUnitParameterValue value = 0.0;
OSStatus error = PKAudioEffectCopyParameter(effect, &value, kDelayParam_DelayTime, kAudioUnitScope_Global);
if(error != noErr)
std::cerr << __PRETTY_FUNCTION__ << ": Could not get value of delay time. Ignoring error " << error << "." << std::endl;
return value;
}
#pragma mark -
PK_EXTERN Boolean PKDelayEffectSetFeedback(PKDelayEffectRef effect, AudioUnitParameterValue value, CFErrorRef *outError)
{
OSStatus error = PKAudioEffectSetParameter(effect,
value,
kDelayParam_Feedback,
kAudioUnitScope_Global,
0);
if(error != noErr)
{
if(outError) *outError = PKCopyError(PKEffectsErrorDomain,
error,
NULL,
CFSTR("Could not set delay feedback amount, Error %@ (%d)."), CoreAudioGetErrorName(error), error);
return false;
}
return true;
}
PK_EXTERN AudioUnitParameterValue PKDelayEffectGetFeedback(PKDelayEffectRef effect)
{
AudioUnitParameterValue value = 0.0;
OSStatus error = PKAudioEffectCopyParameter(effect, &value, kDelayParam_Feedback, kAudioUnitScope_Global);
if(error != noErr)
std::cerr << __PRETTY_FUNCTION__ << ": Could not get value of feedback. Ignoring error " << error << "." << std::endl;
return value;
}
#pragma mark -
PK_EXTERN Boolean PKDelayEffectSetLopassCutoff(PKDelayEffectRef effect, AudioUnitParameterValue value, CFErrorRef *outError)
{
OSStatus error = PKAudioEffectSetParameter(effect,
value,
kDelayParam_LopassCutoff,
kAudioUnitScope_Global,
0);
if(error != noErr)
{
if(outError) *outError = PKCopyError(PKEffectsErrorDomain,
error,
NULL,
CFSTR("Could not set delay lopass cutoff, Error %@ (%d)."), CoreAudioGetErrorName(error), error);
return false;
}
return true;
}
PK_EXTERN AudioUnitParameterValue PKDelayEffectGetLopassCutoff(PKDelayEffectRef effect)
{
AudioUnitParameterValue value = 0.0;
OSStatus error = PKAudioEffectCopyParameter(effect, &value, kDelayParam_LopassCutoff, kAudioUnitScope_Global);
if(error != noErr)
std::cerr << __PRETTY_FUNCTION__ << ": Could not get value of lopass cutoff. Ignoring error " << error << "." << std::endl;
return value;
}