alternative new version of the AppleUtility library
[ardour.git] / libs / appleutility / CoreAudio / AudioUnits / AUPublic / OtherBases / AUPannerBase.h
1 /*
2      File: AUPannerBase.h
3  Abstract: Part of CoreAudio Utility Classes
4   Version: 1.1
5  
6  Disclaimer: IMPORTANT:  This Apple software is supplied to you by Apple
7  Inc. ("Apple") in consideration of your agreement to the following
8  terms, and your use, installation, modification or redistribution of
9  this Apple software constitutes acceptance of these terms.  If you do
10  not agree with these terms, please do not use, install, modify or
11  redistribute this Apple software.
12  
13  In consideration of your agreement to abide by the following terms, and
14  subject to these terms, Apple grants you a personal, non-exclusive
15  license, under Apple's copyrights in this original Apple software (the
16  "Apple Software"), to use, reproduce, modify and redistribute the Apple
17  Software, with or without modifications, in source and/or binary forms;
18  provided that if you redistribute the Apple Software in its entirety and
19  without modifications, you must retain this notice and the following
20  text and disclaimers in all such redistributions of the Apple Software.
21  Neither the name, trademarks, service marks or logos of Apple Inc. may
22  be used to endorse or promote products derived from the Apple Software
23  without specific prior written permission from Apple.  Except as
24  expressly stated in this notice, no other rights or licenses, express or
25  implied, are granted by Apple herein, including but not limited to any
26  patent rights that may be infringed by your derivative works or by other
27  works in which the Apple Software may be incorporated.
28  
29  The Apple Software is provided by Apple on an "AS IS" basis.  APPLE
30  MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
31  THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
32  FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
33  OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
34  
35  IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
36  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
39  MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
40  AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
41  STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
42  POSSIBILITY OF SUCH DAMAGE.
43  
44  Copyright (C) 2014 Apple Inc. All Rights Reserved.
45  
46 */
47 #ifndef __AUPannerBase_h__
48 #define __AUPannerBase_h__
49
50 #include "AUBase.h"
51 #include <math.h>
52 #include "CAAutoDisposer.h"
53 #include "CAAudioChannelLayout.h"
54
55
56 /*! @class AUPannerBase */
57 class AUPannerBase : public AUBase
58 {
59 public:
60 /*! @ctor AUPannerBase */
61     AUPannerBase(AudioComponentInstance inAudioUnit);
62 /*! @dtor ~AUPannerBase */
63     virtual ~AUPannerBase();
64     
65         /*! @method Initialize */
66         virtual OSStatus                        Initialize();
67
68         /*! @method Cleanup */
69         virtual void                            Cleanup();
70
71
72         /*! @method Reset */
73         virtual OSStatus                        Reset(          AudioUnitScope                          inScope,
74                                                                                         AudioUnitElement                        inElement);
75
76         /*! @method CanScheduleParameters */
77         virtual bool                            CanScheduleParameters() const { return false; }
78
79         /*! @method GetParameterInfo */
80         virtual OSStatus                        GetParameterInfo(       AudioUnitScope                  inScope,
81                                                                                                         AudioUnitParameterID    inParameterID,
82                                                                                                         AudioUnitParameterInfo  &outParameterInfo );
83
84
85         /*! @method GetPropertyInfo */
86         virtual OSStatus                        GetPropertyInfo (AudioUnitPropertyID    inID,
87                                                                                         AudioUnitScope                          inScope,
88                                                                                         AudioUnitElement                        inElement,
89                                                                                         UInt32 &                                        outDataSize,
90                                                                                         Boolean &                                       outWritable);
91
92         /*! @method GetProperty */
93         virtual OSStatus                        GetProperty (AudioUnitPropertyID                inID,
94                                                                                         AudioUnitScope                          inScope,
95                                                                                         AudioUnitElement                        inElement,
96                                                                                         void *                                          outData);
97
98         /*! @method SetProperty */
99         virtual OSStatus                        SetProperty(AudioUnitPropertyID                 inID,
100                                                                                         AudioUnitScope                          inScope,
101                                                                                         AudioUnitElement                        inElement,
102                                                                                         const void *                            inData,
103                                                                                         UInt32                                          inDataSize);
104
105
106         /*! @method StreamFormatWritable */
107         virtual bool                            StreamFormatWritable (AudioUnitScope    scope,
108                                                                                         AudioUnitElement                        element);
109
110         /*! @method ChangeStreamFormat */
111         virtual OSStatus                        ChangeStreamFormat (
112                                                                                 AudioUnitScope                                          inScope,
113                                                                                 AudioUnitElement                                        inElement,
114                                                                                 const CAStreamBasicDescription &        inPrevFormat,
115                                                                                 const CAStreamBasicDescription &        inNewFormat);
116
117         
118         /*! @method IsBypassEffect */
119         // This is used for the property value - to reflect to the UI if an effect is bypassed
120         bool                                            IsBypassEffect () { return mBypassEffect; }
121                                                 
122         /*! @method SetBypassEffect */
123         virtual void                            SetBypassEffect (bool inFlag) { mBypassEffect = inFlag; }
124         
125
126         /*! @method Render */
127         virtual OSStatus        Render(AudioUnitRenderActionFlags &             ioActionFlags,
128                                                                                 const AudioTimeStamp &                  inTimeStamp,
129                                                                                 UInt32                                                  inNumberFrames);
130
131         /*! @method Render */
132         virtual OSStatus        PannerRender(AudioUnitRenderActionFlags &               ioActionFlags,
133                                                                                 const AudioTimeStamp &                  inTimeStamp,
134                                                                                 UInt32                                                  inNumberFrames) = 0;
135
136         /*! @method BypassRender */
137         virtual OSStatus        BypassRender(AudioUnitRenderActionFlags &               ioActionFlags,
138                                                                                 const AudioTimeStamp &                  inTimeStamp,
139                                                                                 UInt32                                                  inNumberFrames);
140
141
142         /*! @method GetAudioChannelLayout */
143         virtual UInt32                          GetAudioChannelLayout(  AudioUnitScope                          inScope,
144                                                                                                                 AudioUnitElement                        inElement,
145                                                                                                                 AudioChannelLayout *            outLayoutPtr,
146                                                                                                                 Boolean &                                       outWritable);
147
148         /*! @method SetAudioChannelLayout */
149         virtual OSStatus                        SetAudioChannelLayout(  AudioUnitScope                          inScope, 
150                                                                                                                 AudioUnitElement                        inElement,
151                                                                                                                 const AudioChannelLayout *      inLayout);
152
153         /*! @method RemoveAudioChannelLayout */
154         virtual OSStatus                        RemoveAudioChannelLayout(       AudioUnitScope                  inScope, 
155                                                                                                                         AudioUnitElement                inElement);
156
157         /*! @method GetChannelLayoutTags */
158         virtual UInt32                          GetChannelLayoutTags(           AudioUnitScope                          inScope,
159                                                                                                                         AudioUnitElement                        inElement, 
160                                                                                                                         AudioChannelLayoutTag*          outTags);
161
162         /*! @method GetNumberOfInputChannels */
163         UInt32                                          GetNumberOfInputChannels() { return ((AUIOElement*)Inputs().SafeGetElement(0))->NumberChannels(); };
164         /*! @method GetNumberOfOutputChannels */
165         UInt32                                          GetNumberOfOutputChannels() { return ((AUIOElement*)Outputs().SafeGetElement(0))->NumberChannels(); }
166
167         /*! @method GetParameter */
168         virtual OSStatus        GetParameter(                   AudioUnitParameterID                    inParamID,
169                                                                                                                 AudioUnitScope                                  inScope,
170                                                                                                                 AudioUnitElement                                inElement,
171                                                                                                                 Float32 &                                               outValue);
172                                                                                                 
173         /*! @method SetParameter */
174         virtual OSStatus        SetParameter(                   AudioUnitParameterID                    inParamID,
175                                                                                                                 AudioUnitScope                                  inScope,
176                                                                                                                 AudioUnitElement                                inElement,
177                                                                                                                 Float32                                                 inValue,
178                                                                                                                 UInt32                                                  inBufferOffsetInFrames);
179
180         // convenience wrappers for accessing parameters in the global scope
181         /*! @method SetParameter */
182         void                                            SetParameter(                   UInt32                                                  inParamID,
183                                                                                                                 Float32                                                 inValue)
184                                                                 {
185                                                                         OSStatus err = SetParameter(inParamID, kAudioUnitScope_Global, 0, inValue, 0);
186                                                                         if (err) throw err;
187                                                                 }
188                                                                 
189         /*! @method GetParameter */
190         Float32                                         GetParameter(                   UInt32                                                  inParamID )
191                                                                 {
192                                                                         Float32 outValue = 0.;
193                                                                         OSStatus err = GetParameter(inParamID, kAudioUnitScope_Global, 0, outValue);
194                                                                         if (err) throw err;
195                                                                         return outValue;
196                                                                 }
197
198         /*! @method InputChannelConfigIsSupported */
199         bool                                            InputChannelConfigIsSupported(UInt32 inNumberChannels);
200         /*! @method OutputChannelConfigIsSupported */
201         bool                                            OutputChannelConfigIsSupported(UInt32 inNumberChannels);
202         /*! @method ChannelConfigIsSupported */
203         bool                                            ChannelConfigIsSupported();
204
205         /*! @method SupportsTail */
206         virtual bool                            SupportsTail () { return true; }
207         /*! @method GetTailTime */
208     virtual Float64                             GetTailTime() { return 0; }
209
210
211         /*! @method GetGain */
212         Float32                                         GetGain()        { return GetParameter(kPannerParam_Gain); }
213         /*! @method GetTailTime */
214         Float32                                         GetAzimuth()     { return GetParameter(kPannerParam_Azimuth); }
215         /*! @method GetElevation */
216         Float32                                         GetElevation()   { return GetParameter(kPannerParam_Elevation); }
217         /*! @method GetDistance */
218         Float32                                         GetDistance()    { return GetParameter(kPannerParam_Distance); }
219         /*! @method GetCoordScale */
220         Float32                                         GetCoordScale()  { return GetParameter(kPannerParam_CoordScale); }
221         /*! @method GetRefDistance */
222         Float32                                         GetRefDistance() { return GetParameter(kPannerParam_RefDistance); }                                     
223                                         
224         /*! @method SetGain */
225         void                                            SetGain(Float32 inValue)        { SetParameter(kPannerParam_Gain, inValue); }
226         /*! @method SetAzimuth */
227         void                                            SetAzimuth(Float32 inValue)     { SetParameter(kPannerParam_Azimuth, inValue); }
228         /*! @method SetElevation */
229         void                                            SetElevation(Float32 inValue)   { SetParameter(kPannerParam_Elevation, inValue); }
230         /*! @method SetDistance */
231         void                                            SetDistance(Float32 inValue)    { SetParameter(kPannerParam_Distance, inValue); }
232         /*! @method SetCoordScale */
233         void                                            SetCoordScale(Float32 inValue)  { SetParameter(kPannerParam_CoordScale, inValue); }
234         /*! @method SetRefDistance */
235         void                                            SetRefDistance(Float32 inValue) { SetParameter(kPannerParam_RefDistance, inValue); }
236         
237 protected:
238         /*! @method ShouldBypassEffect */
239         // This is used in the render call to see if an effect is bypassed
240         // It can return a different status than IsBypassEffect (though it MUST take that into account)
241         virtual bool                            ShouldBypassEffect () { return IsBypassEffect(); }
242
243         /*! @method AllocBypassMatrix */
244         void                                            AllocBypassMatrix();
245
246         /*! @method UpdateBypassMatrix */
247         OSStatus                                        UpdateBypassMatrix();
248
249         /*! @method SetDefaultChannelLayoutsIfNone */
250         OSStatus                                        SetDefaultChannelLayoutsIfNone();
251         
252         /*! @method ChannelLayoutTagIsSupported */
253         bool                                            ChannelLayoutTagIsSupported(    AudioUnitScope                  inScope, 
254                                                                                                                                 AudioUnitElement                inElement, 
255                                                                                                                                 AudioChannelLayoutTag   inTag);
256         
257         const AudioChannelLayout&       GetInputLayout() const { return mInputLayout.Layout(); }
258         const AudioChannelLayout&       GetOutputLayout() const { return mOutputLayout.Layout(); }
259         
260 private:
261         
262         /*! @var UpdateBypassMatrix */
263         bool mBypassEffect;
264         /*! @var mBypassMatrix */
265         CAAutoFree<Float32> mBypassMatrix;
266         /*! @var mInputLayout */
267         CAAudioChannelLayout mInputLayout;
268         /*! @var mOutputLayout */
269         CAAudioChannelLayout mOutputLayout;
270 };
271
272 #endif /* __AUPannerBase_h__ */