Jamoma API  0.6.0.a19
CAVolumeCurve.h
1 /* Copyright © 2007 Apple Inc. All Rights Reserved.
2 
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.
9 
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.
25 
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.
31 
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.
40 */
41 #if !defined(__CAVolumeCurve_h__)
42 #define __CAVolumeCurve_h__
43 
44 //=============================================================================
45 // Includes
46 //=============================================================================
47 
48 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
49  #include <CoreAudio/CoreAudioTypes.h>
50 #else
51  #include <CoreAudioTypes.h>
52 #endif
53 #include <map>
54 
55 //=============================================================================
56 // Types
57 //=============================================================================
58 
59 struct CARawPoint
60 {
61  SInt32 mMinimum;
62  SInt32 mMaximum;
63 
64  CARawPoint() : mMinimum(0), mMaximum(0) {}
65  CARawPoint(const CARawPoint& inPoint) : mMinimum(inPoint.mMinimum), mMaximum(inPoint.mMaximum) {}
66  CARawPoint(SInt32 inMinimum, SInt32 inMaximum) : mMinimum(inMinimum), mMaximum(inMaximum) {}
67  CARawPoint& operator=(const CARawPoint& inPoint) { mMinimum = inPoint.mMinimum; mMaximum = inPoint.mMaximum; return *this; }
68 
69  static bool Overlap(const CARawPoint& x, const CARawPoint& y) { return (x.mMinimum < y.mMaximum) && (x.mMaximum > y.mMinimum); }
70 };
71 
72 inline bool operator<(const CARawPoint& x, const CARawPoint& y) { return x.mMinimum < y.mMinimum; }
73 inline bool operator==(const CARawPoint& x, const CARawPoint& y) { return (x.mMinimum == y.mMinimum) && (x.mMaximum == y.mMaximum); }
74 inline bool operator!=(const CARawPoint& x, const CARawPoint& y) { return !(x == y); }
75 inline bool operator<=(const CARawPoint& x, const CARawPoint& y) { return (x < y) || (x == y); }
76 inline bool operator>=(const CARawPoint& x, const CARawPoint& y) { return !(x < y); }
77 inline bool operator>(const CARawPoint& x, const CARawPoint& y) { return !((x < y) || (x == y)); }
78 
79 struct CADBPoint
80 {
81  Float64 mMinimum;
82  Float64 mMaximum;
83 
84  CADBPoint() : mMinimum(0), mMaximum(0) {}
85  CADBPoint(const CADBPoint& inPoint) : mMinimum(inPoint.mMinimum), mMaximum(inPoint.mMaximum) {}
86  CADBPoint(Float64 inMinimum, Float64 inMaximum) : mMinimum(inMinimum), mMaximum(inMaximum) {}
87  CADBPoint& operator=(const CADBPoint& inPoint) { mMinimum = inPoint.mMinimum; mMaximum = inPoint.mMaximum; return *this; }
88 
89  static bool Overlap(const CADBPoint& x, const CADBPoint& y) { return (x.mMinimum < y.mMaximum) && (x.mMaximum >= y.mMinimum); }
90 };
91 
92 inline bool operator<(const CADBPoint& x, const CADBPoint& y) { return x.mMinimum < y.mMinimum; }
93 inline bool operator==(const CADBPoint& x, const CADBPoint& y) { return (x.mMinimum == y.mMinimum) && (x.mMaximum == y.mMaximum); }
94 inline bool operator!=(const CADBPoint& x, const CADBPoint& y) { return !(x == y); }
95 inline bool operator<=(const CADBPoint& x, const CADBPoint& y) { return (x < y) || (x == y); }
96 inline bool operator>=(const CADBPoint& x, const CADBPoint& y) { return !(x < y); }
97 inline bool operator>(const CADBPoint& x, const CADBPoint& y) { return !((x < y) || (x == y)); }
98 
99 //=============================================================================
100 // CAVolumeCurve
101 //=============================================================================
102 
103 class CAVolumeCurve
104 {
105 
106 // Constants
107 public:
108  enum
109  {
110  kLinearCurve = 0,
111  kPow1Over3Curve = 1,
112  kPow1Over2Curve = 2,
113  kPow3Over4Curve = 3,
114  kPow3Over2Curve = 4,
115  kPow2Over1Curve = 5,
116  kPow3Over1Curve = 6,
117  kPow4Over1Curve = 7,
118  kPow5Over1Curve = 8,
119  kPow6Over1Curve = 9,
120  kPow7Over1Curve = 10,
121  kPow8Over1Curve = 11,
122  kPow9Over1Curve = 12,
123  kPow10Over1Curve = 13,
124  kPow11Over1Curve = 14,
125  kPow12Over1Curve = 15
126  };
127 
128 // Construction/Destruction
129 public:
130  CAVolumeCurve();
131  virtual ~CAVolumeCurve();
132 
133 // Attributes
134 public:
135  UInt32 GetTag() const { return mTag; }
136  void SetTag(UInt32 inTag) { mTag = inTag; }
137  SInt32 GetMinimumRaw() const;
138  SInt32 GetMaximumRaw() const;
139  Float64 GetMinimumDB() const;
140  Float64 GetMaximumDB() const;
141 
142  void SetIsApplyingTransferFunction(bool inIsApplyingTransferFunction) { mIsApplyingTransferFunction = inIsApplyingTransferFunction; }
143  int GetTransferFunction() const { return mTransferFunction; }
144  void SetTransferFunction(int inTransferFunction);
145 
146 // Operations
147 public:
148  void AddRange(SInt32 mMinRaw, SInt32 mMaxRaw, Float64 inMinDB, Float64 inMaxDB);
149  void ResetRange();
150  bool CheckForContinuity() const;
151 
152  SInt32 ConvertDBToRaw(Float64 inDB) const;
153  Float64 ConvertRawToDB(SInt32 inRaw) const;
154  Float64 ConvertRawToScalar(SInt32 inRaw) const;
155  Float64 ConvertDBToScalar(Float64 inDB) const;
156  SInt32 ConvertScalarToRaw(Float64 inScalar) const;
157  Float64 ConvertScalarToDB(Float64 inScalar) const;
158 
159 // Implementation
160 private:
161  typedef std::map<CARawPoint, CADBPoint> CurveMap;
162 
163  UInt32 mTag;
164  CurveMap mCurveMap;
165  bool mIsApplyingTransferFunction;
166  UInt32 mTransferFunction;
167  Float64 mRawToScalarExponentNumerator;
168  Float64 mRawToScalarExponentDenominator;
169 
170 };
171 
172 #endif
bool TTFOUNDATION_EXPORT operator!=(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for inequality.
Definition: TTObject.cpp:173
bool TTFOUNDATION_EXPORT operator==(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for equality.
Definition: TTObject.cpp:167