-
Notifications
You must be signed in to change notification settings - Fork 0
/
Convolvotron.h
172 lines (124 loc) · 4.56 KB
/
Convolvotron.h
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* File: Convolvotron.h
*
* Version: 1.0
*
* Created: 5/26/09
*
* Copyright: Copyright © 2009 Meatscience, All Rights Reserved
*
*/
#define DEBUG 1
#if DEBUG
#define CoreAudio_Debug 1
#endif
#include "ConvolutionVersion.h"
#include "ConvolvotronProperties.h"
#include "AUEffectBase.h"
#include <AudioUnit/AudioUnitCarbonView.h>
#include <AudioToolbox/AudioToolbox.h>
#include <Convolver.h>
#include <ConvolverFilter.h>
#include "AUConvolver.h"
#include <boost/shared_ptr.hpp>
#include <vector>
#include <map>
#if AU_DEBUG_DISPATCHER
#include "AUDebugDispatcher.h"
#endif
#include <pthread.h>
#ifndef __Convolvotron_h__
#define __Convolvotron_h__
#pragma mark ____Convolvotron Parameters
typedef struct {
int parameter;
CFStringRef name;
float minValue;
float maxValue;
float defaultValue;
AudioUnitParameterUnit unit;
UInt32 flags;
} ParameterDescription;
ParameterDescription parameters[] = {
{kParam_WetDry, CFSTR("Dry/Wet Mix"), 0.0, 100.0, 70.0, kAudioUnitParameterUnit_EqualPowerCrossfade, 0},
{kParam_OutputGain, CFSTR("Output Gain"), -40.0, 12.0, 0.0, kAudioUnitParameterUnit_Decibels, 0},
/*{kParam_StereoSeparation, CFSTR("Stereo Separation"), 0.0, 100.0, 100.0, kAudioUnitParameterUnit_EqualPowerCrossfade, 0}
{kParam_PreDelay, CFSTR("Pre-delay"), 0.0, 250.0, 0.0, kAudioUnitParameterUnit_Milliseconds, 0},
{kParam_VolumeCompensation, CFSTR("Volume Compensation"), 0.0, 1.0, 1.0, kAudioUnitParameterUnit_Boolean, 0}*/
};
//static const UInt32 irBufferSize = 32768;
#pragma mark ____Convolvotron
class Convolvotron : public AUEffectBase
{
public:
Convolvotron(AudioUnit component);
virtual ~Convolvotron ();
virtual ComponentResult Initialize();
/*! @method ProcessBufferLists */
virtual OSStatus ProcessBufferLists(AudioUnitRenderActionFlags & ioActionFlags,
const AudioBufferList & inBuffer,
AudioBufferList & outBuffer,
UInt32 inFramesToProcess );
virtual OSStatus GetParameterValueStrings(AudioUnitScope inScope,
AudioUnitParameterID inParameterID,
CFArrayRef * outStrings);
virtual OSStatus GetParameterInfo(AudioUnitScope inScope,
AudioUnitParameterID inParameterID,
AudioUnitParameterInfo &outParameterInfo);
virtual OSStatus GetPropertyInfo(AudioUnitPropertyID inID,
AudioUnitScope inScope,
AudioUnitElement inElement,
UInt32 & outDataSize,
Boolean & outWritable );
virtual OSStatus GetProperty(AudioUnitPropertyID inID,
AudioUnitScope inScope,
AudioUnitElement inElement,
void * outData);
virtual OSStatus SetProperty( AudioUnitPropertyID inID,
AudioUnitScope inScope,
AudioUnitElement inElement,
const void * inData,
UInt32 inDataSize);
virtual ComponentResult SaveState(CFPropertyListRef * outData);
virtual ComponentResult RestoreState(CFPropertyListRef plist);
virtual bool SupportsTail () { return true; }
virtual Float64 GetTailTime();
virtual Float64 GetLatency();
/*! @method Version */
virtual OSStatus Version() { return kConvolutionVersion; }
void LoadIR(std::string &filename, bool inBackground=false);
void LoadIRInBackground(std::string &filename);
int GetNumCustomUIComponents () { return 1; }
void GetUIComponentDescs (ComponentDescription* inDescArray) {
inDescArray[0].componentType = kAudioUnitCarbonViewComponentType;
inDescArray[0].componentSubType = Convolution_COMP_SUBTYPE;
inDescArray[0].componentManufacturer = Convolution_COMP_MANF;
inDescArray[0].componentFlags = 0;
inDescArray[0].componentFlagsMask = 0;
}
protected:
boost::shared_ptr<Convolver::AUConvolver> auConvolver;
// We need a mutex because the background thread can scribble us
boost::shared_ptr<Convolver::IR> ir;
std::map<std::string, boost::shared_ptr<Convolver::IR> > filenameToIRCache;
pthread_mutex_t filtersMutex;
std::string irFilename;
pthread_t irLoadingThread;
IRLoadingStatus irLoadingStatus;
Float64 tailTime;
static Float32 peak;
private:
uint32_t frameSize;
void setFrameSize(uint32_t frameSize);
void LoadUnitIR();
boost::shared_ptr<Convolver::Filter> getMonoIR();
void cancelIRLoadingThread();
void SetIR(std::string &filename, boost::shared_ptr<Convolver::IR > ir);
#if DEMO
time_t endTime;
time_t lastBlipTime;
bool demoExpired;
#endif
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#endif