Jamoma API  0.6.0.a19
CAAudioChannelLayout.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(__CAAudioChannelLayout_h__)
42 #define __CAAudioChannelLayout_h__
43 
44 //=============================================================================
45 // Includes
46 //=============================================================================
47 
48 // System Includes
49 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
50  #include <CoreAudio/CoreAudioTypes.h>
51  #include <CoreFoundation/CoreFoundation.h>
52 #else
53  #include <CoreAudioTypes.h>
54  #include <CoreFoundation.h>
55 #endif
56 #include <stdio.h>
57 #include <stdlib.h>
58 #include <string.h>
59 
60 #include "CADebugMacros.h"
61 #include "CAAutoDisposer.h"
62 
63 #if !HAL_Build
64  #include "CAReferenceCounted.h"
65 #endif
66 
67 //=============================================================================
68 // CAAudioChannelLayout
69 //=============================================================================
70 
71 bool operator== (const AudioChannelLayout &x, const AudioChannelLayout &y);
72 
73 extern "C" void CAShowAudioChannelLayout (FILE* file, const AudioChannelLayout *layout);
74 
75 class CAAudioChannelLayout
76 {
77 // static Construction/Destruction
78 public:
79  static AudioChannelLayout* Create(UInt32 inNumberChannelDescriptions);
80  static void Destroy(AudioChannelLayout* inChannelLayout);
81  static UInt32 CalculateByteSize(UInt32 inNumberChannelDescriptions) {
82  return OffsetOf32(AudioChannelLayout, mChannelDescriptions) + inNumberChannelDescriptions * SizeOf32(AudioChannelDescription);
83  }
84  static void SetAllToUnknown(AudioChannelLayout& outChannelLayout, UInt32 inNumberChannelDescriptions);
85  static UInt32 NumberChannels(const AudioChannelLayout& inLayout);
86 
87 #if !HAL_Build
88 // object methods
89 public:
90  CAAudioChannelLayout ();
91 
92  CAAudioChannelLayout (UInt32 inNumberChannels, bool inChooseSurround);
93  // if inChooseSurround is false, then symmetrical speaker arrangements
94  // are chosen in place of surround layouts if there is a choice
95  // This call chooses layouts based on the expected defaults in
96  // AudioUnit usage
97  CAAudioChannelLayout (AudioChannelLayoutTag inTag);
98  CAAudioChannelLayout (const CAAudioChannelLayout &c);
99  CAAudioChannelLayout (const AudioChannelLayout* inChannelLayout);
100  ~CAAudioChannelLayout();
101 
102  CAAudioChannelLayout& operator= (const AudioChannelLayout* inChannelLayout);
103  CAAudioChannelLayout& operator= (const CAAudioChannelLayout& c);
104  bool operator== (const CAAudioChannelLayout &c) const;
105 
106  void SetWithTag(AudioChannelLayoutTag inTag);
107 
108  bool IsValid() const { return NumberChannels() > 0; }
109  UInt32 Size() const { return mLayout ? mLayout->Size() : 0; }
110 
111  UInt32 NumberChannels() const { return mLayout ? mLayout->NumberChannels() : 0; }
112 
113  AudioChannelLayoutTag Tag() const { return Layout().mChannelLayoutTag; }
114  const AudioChannelLayout& Layout() const { return mLayout->Layout(); }
115  operator const AudioChannelLayout *() const { return &Layout(); }
116 
117  void Print () const { Print (stdout); }
118  void Print (FILE* file) const;
119 
120  OSStatus Save (CFPropertyListRef *outData) const;
121  OSStatus Restore (CFPropertyListRef &inData);
122 
123 private:
124  class RefCountedLayout : public CAReferenceCounted {
125  void * operator new(size_t size, size_t aclSize)
126  {
127  return CA_malloc(sizeof(RefCountedLayout) - sizeof(AudioChannelLayout) + aclSize);
128  }
129 
130  void operator delete(void *mem)
131  {
132  free(mem);
133  }
134 
135 
136  RefCountedLayout(UInt32 inDataSize) :
137  mByteSize(inDataSize)
138  {
139  memset(&mACL, 0, inDataSize);
140  }
141 
142  public:
143  static RefCountedLayout *CreateWithNumberChannelDescriptions(unsigned nChannels) {
144  size_t size = CAAudioChannelLayout::CalculateByteSize(nChannels);
145  return new(size) RefCountedLayout(size);
146  }
147 
148  static RefCountedLayout *CreateWithLayout(const AudioChannelLayout *layout) {
149  size_t size = CAAudioChannelLayout::CalculateByteSize(layout->mNumberChannelDescriptions);
150  RefCountedLayout *acl = new(size) RefCountedLayout(size);
151  memcpy(&acl->mACL, layout, size);
152  return acl;
153  }
154  static RefCountedLayout *CreateWithLayoutTag(AudioChannelLayoutTag layoutTag) {
155  RefCountedLayout *acl = CreateWithNumberChannelDescriptions(0);
156  acl->mACL.mChannelLayoutTag = layoutTag;
157  return acl;
158  }
159 
160  const AudioChannelLayout & Layout() const { return mACL; }
161 
162  UInt32 Size () const { return mByteSize; }
163 
164  UInt32 NumberChannels() { return CAAudioChannelLayout::NumberChannels(Layout()); }
165 
166  private:
167  const UInt32 mByteSize;
168  AudioChannelLayout mACL;
169  // * * * mACL is variable length and thus must be last * * *
170 
171  // only the constructors can change the actual state of the layout
172  friend CAAudioChannelLayout::CAAudioChannelLayout (UInt32 inNumberChannels, bool inChooseSurround);
173  friend OSStatus CAAudioChannelLayout::Restore (CFPropertyListRef &inData);
174  friend CAAudioChannelLayout& CAAudioChannelLayout::operator= (const AudioChannelLayout* inChannelLayout);
175  friend void CAAudioChannelLayout::SetWithTag(AudioChannelLayoutTag inTag);
176 
177  AudioChannelLayout * GetLayout() { return &mACL; }
178 
179  private:
180  // prohibited methods: private and unimplemented.
181  RefCountedLayout();
182  RefCountedLayout(const RefCountedLayout& c);
183  RefCountedLayout& operator=(const RefCountedLayout& c);
184  };
185 
186  RefCountedLayout *mLayout;
187 #endif // HAL_Build
188 
189 };
190 
191 #endif
bool TTFOUNDATION_EXPORT operator==(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for equality.
Definition: TTObject.cpp:167