-
Notifications
You must be signed in to change notification settings - Fork 2
/
PKPitchEffect.cpp
89 lines (75 loc) · 2.46 KB
/
PKPitchEffect.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
/*
* PKPitchEffect.cpp
* PlayerKit
*
* Created by Peter MacWhinnie on 1/14/11.
* Copyright 2011 __MyCompanyName__. All rights reserved.
*
*/
#include "PKPitchEffect.h"
#include "CoreAudioErrors.h"
#include <iostream>
#pragma mark -
#pragma mark Creation
PK_EXTERN PKPitchEffectRef PKPitchEffectCreate(CFErrorRef *outError)
{
AudioComponentDescription pitchDescription = {
kAudioUnitType_Effect,
kAudioUnitSubType_Pitch,
kAudioUnitManufacturer_Apple,
};
return PKAudioEffectCreate(pitchDescription, outError);
}
#pragma mark -
#pragma mark Properties
PK_EXTERN Boolean PKPitchEffectSetPitch(PKPitchEffectRef effect, AudioUnitParameterValue value, CFErrorRef *outError)
{
OSStatus error = PKAudioEffectSetParameter(effect,
value,
kTimePitchParam_Pitch,
kAudioUnitScope_Global,
0);
if(error != noErr)
{
if(outError) *outError = PKCopyError(PKEffectsErrorDomain,
error,
NULL,
CFSTR("Could not set pitch, Error %@ (%d)."), CoreAudioGetErrorName(error), error);
return false;
}
return true;
}
PK_EXTERN AudioUnitParameterValue PKPitchEffectGetPitch(PKPitchEffectRef effect)
{
AudioUnitParameterValue value = 0.0;
OSStatus error = PKAudioEffectCopyParameter(effect, &value, kTimePitchParam_Pitch, kAudioUnitScope_Global);
if(error != noErr)
std::cerr << __PRETTY_FUNCTION__ << ": Could not get value of pitch. Ignoring error " << error << "." << std::endl;
return value;
}
#pragma mark -
PK_EXTERN Boolean PKPitchEffectSetBlendAmount(PKPitchEffectRef effect, AudioUnitParameterValue value, CFErrorRef *outError)
{
OSStatus error = PKAudioEffectSetParameter(effect,
value,
kTimePitchParam_EffectBlend,
kAudioUnitScope_Global,
0);
if(error != noErr)
{
if(outError) *outError = PKCopyError(PKEffectsErrorDomain,
error,
NULL,
CFSTR("Could not set pitch blend amount, Error %@ (%d)."), CoreAudioGetErrorName(error), error);
return false;
}
return true;
}
PK_EXTERN AudioUnitParameterValue PKPitchEffectGetBlendAmount(PKPitchEffectRef effect)
{
AudioUnitParameterValue value = 0.0;
OSStatus error = PKAudioEffectCopyParameter(effect, &value, kTimePitchParam_EffectBlend, kAudioUnitScope_Global);
if(error != noErr)
std::cerr << __PRETTY_FUNCTION__ << ": Could not get value of pitch blemd amount. Ignoring error " << error << "." << std::endl;
return value;
}