1 /* Copyright © 2007 Apple Inc. All Rights Reserved.
3 Disclaimer: IMPORTANT: This Apple software is supplied to you by
4 Apple Inc. ("Apple") in consideration of your agreement to the
5 following terms, and your use, installation, modification or
6 redistribution of this Apple software constitutes acceptance of these
7 terms. If you do not agree with these terms, please do not use,
8 install, modify or redistribute this Apple software.
10 In consideration of your agreement to abide by the following terms, and
11 subject to these terms, Apple grants you a personal, non-exclusive
12 license, under Apple's copyrights in this original Apple software (the
13 "Apple Software"), to use, reproduce, modify and redistribute the Apple
14 Software, with or without modifications, in source and/or binary forms;
15 provided that if you redistribute the Apple Software in its entirety and
16 without modifications, you must retain this notice and the following
17 text and disclaimers in all such redistributions of the Apple Software.
18 Neither the name, trademarks, service marks or logos of Apple Inc.
19 may be used to endorse or promote products derived from the Apple
20 Software without specific prior written permission from Apple. Except
21 as expressly stated in this notice, no other rights or licenses, express
22 or implied, are granted by Apple herein, including but not limited to
23 any patent rights that may be infringed by your derivative works or by
24 other works in which the Apple Software may be incorporated.
26 The Apple Software is provided by Apple on an "AS IS" basis. APPLE
27 MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
28 THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
29 FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
30 OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
32 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
33 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
36 MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
37 AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
38 STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
39 POSSIBILITY OF SUCH DAMAGE.
41 /*=============================================================================
44 =============================================================================*/
46 #ifndef __AUEffectBase_h__
47 #define __AUEffectBase_h__
50 #include "AUSilentTimeout.h"
54 // Base class for an effect with one input stream, one output stream,
55 // any number of channels.
56 /*! @class AUEffectBase */
57 class AUEffectBase
: public AUBase
{
59 /*! @ctor AUEffectBase */
60 AUEffectBase( AudioUnit audioUnit
,
61 bool inProcessesInPlace
= true );
62 /*! @dtor ~AUEffectBase */
65 /*! @method Initialize */
66 virtual ComponentResult
Initialize();
68 /*! @method Cleanup */
69 virtual void Cleanup();
73 virtual ComponentResult
Reset( AudioUnitScope inScope
,
74 AudioUnitElement inElement
);
76 /*! @method GetPropertyInfo */
77 virtual ComponentResult
GetPropertyInfo (AudioUnitPropertyID inID
,
78 AudioUnitScope inScope
,
79 AudioUnitElement inElement
,
81 Boolean
& outWritable
);
83 /*! @method GetProperty */
84 virtual ComponentResult
GetProperty (AudioUnitPropertyID inID
,
85 AudioUnitScope inScope
,
86 AudioUnitElement inElement
,
89 /*! @method SetProperty */
90 virtual ComponentResult
SetProperty(AudioUnitPropertyID inID
,
91 AudioUnitScope inScope
,
92 AudioUnitElement inElement
,
96 /*! @method StreamFormatWritable */
97 virtual bool StreamFormatWritable (AudioUnitScope scope
,
98 AudioUnitElement element
);
100 /*! @method ChangeStreamFormat */
101 virtual ComponentResult
ChangeStreamFormat (
102 AudioUnitScope inScope
,
103 AudioUnitElement inElement
,
104 const CAStreamBasicDescription
& inPrevFormat
,
105 const CAStreamBasicDescription
& inNewFormat
);
107 /*! @method Render */
108 virtual ComponentResult
Render(AudioUnitRenderActionFlags
& ioActionFlags
,
109 const AudioTimeStamp
& inTimeStamp
,
110 UInt32 inNumberFrames
);
112 // our virtual methods
114 // If your unit processes N to N channels, and there are no interactions between channels,
115 // it can override NewKernel to create a mono processing object per channel. Otherwise,
116 // don't override NewKernel, and instead, override ProcessBufferLists.
117 /*! @method NewKernel */
118 virtual AUKernelBase
* NewKernel() { return NULL
; }
120 /*! @method ProcessBufferLists */
121 virtual OSStatus
ProcessBufferLists(
122 AudioUnitRenderActionFlags
& ioActionFlags
,
123 const AudioBufferList
& inBuffer
,
124 AudioBufferList
& outBuffer
,
125 UInt32 inFramesToProcess
);
127 /*! @method MaintainKernels */
128 void MaintainKernels();
130 // convenience format accessors (use output 0's format)
131 /*! @method GetSampleRate */
132 Float64
GetSampleRate();
134 /*! @method GetNumberOfChannels */
135 UInt32
GetNumberOfChannels();
137 // convenience wrappers for accessing parameters in the global scope
138 /*! @method SetParameter */
139 void SetParameter( AudioUnitParameterID paramID
,
140 AudioUnitParameterValue value
)
142 Globals()->SetParameter(paramID
, value
);
145 /*! @method GetParameter */
146 AudioUnitParameterValue
GetParameter( AudioUnitParameterID paramID
)
148 return Globals()->GetParameter(paramID
);
151 /*! @method IsBypassEffect */
152 // This is used for the property value - to reflect to the UI if an effect is bypassed
153 bool IsBypassEffect () { return mBypassEffect
; }
156 /*! @method ShouldBypassEffect */
157 // This is used in the render call to see if an effect is bypassed
158 // It can return a different status than IsBypassEffect (though it MUST take that into account)
159 virtual bool ShouldBypassEffect () { return IsBypassEffect(); }
162 /*! @method SetBypassEffect */
163 virtual void SetBypassEffect (bool inFlag
) { mBypassEffect
= inFlag
; }
165 /*! @method SetParamHasSampleRateDependency */
166 void SetParamHasSampleRateDependency (bool inFlag
)
168 mParamSRDep
= inFlag
;
171 /*! @method GetParamHasSampleRateDependency */
172 bool GetParamHasSampleRateDependency () const { return mParamSRDep
; }
175 struct ScheduledProcessParams
// pointer passed in as void* userData param for ProcessScheduledSlice()
177 AudioUnitRenderActionFlags
*actionFlags
;
178 AudioBufferList
*inputBufferList
;
179 AudioBufferList
*outputBufferList
;
182 virtual ComponentResult
ProcessScheduledSlice( void *inUserData
,
183 UInt32 inStartFrameInBuffer
,
184 UInt32 inSliceFramesToProcess
,
185 UInt32 inTotalBufferFrames
);
188 bool ProcessesInPlace() const {return mProcessesInPlace
;};
189 void SetProcessesInPlace(bool inProcessesInPlace
) {mProcessesInPlace
= inProcessesInPlace
;};
191 typedef std::vector
<AUKernelBase
*> KernelList
;
194 /*! @var mKernelList */
195 KernelList mKernelList
;
197 /*! @method IsInputSilent */
198 bool IsInputSilent (AudioUnitRenderActionFlags inActionFlags
, UInt32 inFramesToProcess
)
200 bool inputSilent
= (inActionFlags
& kAudioUnitRenderAction_OutputIsSilence
) != 0;
202 // take latency and tail time into account when propagating the silent bit
203 UInt32 silentTimeoutFrames
= UInt32(GetSampleRate() * (GetLatency() + GetTailTime()));
204 mSilentTimeout
.Process (inFramesToProcess
, silentTimeoutFrames
, inputSilent
);
209 /*! @var mBypassEffect */
211 /*! @var mParamSRDep */
214 /*! @var mProcessesInplace */
215 bool mProcessesInPlace
;
217 /*! @var mSilentTimeout */
218 AUSilentTimeout mSilentTimeout
;
224 // Base class for a "kernel", an object that performs DSP on one channel of an interleaved stream.
225 /*! @class AUKernelBase */
228 /*! @ctor AUKernelBase */
229 AUKernelBase(AUEffectBase
*inAudioUnit
) :
230 mAudioUnit(inAudioUnit
), mIsLastKernel(false) { }
232 /*! @dtor ~AUKernelBase */
233 virtual ~AUKernelBase() { }
236 virtual void Reset() { }
238 /*! @method Process */
239 virtual void Process( const AudioSampleType
* inSourceP
,
240 AudioSampleType
* inDestP
,
241 UInt32 inFramesToProcess
,
242 UInt32 inNumChannels
,
243 bool & ioSilence
) = 0;
245 /*! @method GetSampleRate */
246 Float64
GetSampleRate()
248 return mAudioUnit
->GetSampleRate();
251 /*! @method GetParameter */
252 AudioUnitParameterValue
GetParameter (AudioUnitParameterID paramID
)
254 return mAudioUnit
->GetParameter(paramID
);
257 void SetChannelNum (UInt32 inChan
) { mChannelNum
= inChan
; }
258 UInt32
GetChannelNum () { return mChannelNum
; }
260 bool IsLastKernel() const {return mIsLastKernel
;};
261 void SetLastKernel(bool inIsLastKernel
) {mIsLastKernel
= inIsLastKernel
;};
264 /*! @var mAudioUnit */
265 AUEffectBase
* mAudioUnit
;
273 #endif // __AUEffectBase_h__