Jamoma API  0.6.0.a19
CAAudioChannelLayoutObject.cpp
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 #include "CAAudioChannelLayout.h"
42 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
43  #include <AudioToolbox/AudioFormat.h>
44 #else
45  #include <AudioFormat.h>
46 #endif
47 
48 CAAudioChannelLayout::CAAudioChannelLayout ()
49 {
50  mLayout = RefCountedLayout::CreateWithNumberChannelDescriptions(0);
51 }
52 
53 //=============================================================================
54 // CAAudioChannelLayout::CAAudioChannelLayout
55 //=============================================================================
56 CAAudioChannelLayout::CAAudioChannelLayout (UInt32 inNumberChannels, bool inChooseSurround)
57 {
58  // this chooses default layouts based on the number of channels...
59  AudioChannelLayoutTag tag;
60 
61  switch (inNumberChannels)
62  {
63  default:
64  // here we have a "broken" layout, in the sense that we haven't any idea how to lay this out
65  mLayout = RefCountedLayout::CreateWithNumberChannelDescriptions(inNumberChannels);
66  SetAllToUnknown(*mLayout->GetLayout(), inNumberChannels);
67  return; // don't fall into the tag case
68  case 1:
69  tag = kAudioChannelLayoutTag_Mono;
70  break;
71  case 2:
72  tag = inChooseSurround ? kAudioChannelLayoutTag_Binaural : kAudioChannelLayoutTag_Stereo;
73  break;
74  case 4:
75  tag = inChooseSurround ? kAudioChannelLayoutTag_Ambisonic_B_Format : kAudioChannelLayoutTag_AudioUnit_4;
76  break;
77  case 5:
78  tag = inChooseSurround ? kAudioChannelLayoutTag_AudioUnit_5_0 : kAudioChannelLayoutTag_AudioUnit_5;
79  break;
80  case 6:
81  tag = inChooseSurround ? kAudioChannelLayoutTag_AudioUnit_6_0 : kAudioChannelLayoutTag_AudioUnit_6;
82  break;
83  case 7:
84  tag = kAudioChannelLayoutTag_AudioUnit_7_0;
85  break;
86  case 8:
87  tag = kAudioChannelLayoutTag_AudioUnit_8;
88  break;
89  }
90 
91  mLayout = RefCountedLayout::CreateWithLayoutTag(tag);
92 }
93 
94 //=============================================================================
95 // CAAudioChannelLayout::CAAudioChannelLayout
96 //=============================================================================
97 CAAudioChannelLayout::CAAudioChannelLayout (AudioChannelLayoutTag inLayoutTag)
98  : mLayout(NULL)
99 {
100  SetWithTag(inLayoutTag);
101 }
102 
103 //=============================================================================
104 // CAAudioChannelLayout::CAAudioChannelLayout
105 //=============================================================================
106 CAAudioChannelLayout::CAAudioChannelLayout (const CAAudioChannelLayout &c)
107  : mLayout(NULL)
108 {
109  *this = c;
110 }
111 
112 
113 //=============================================================================
114 // CAAudioChannelLayout::AudioChannelLayout
115 //=============================================================================
116 CAAudioChannelLayout::CAAudioChannelLayout (const AudioChannelLayout* inChannelLayout)
117  : mLayout(NULL)
118 {
119  *this = inChannelLayout;
120 }
121 
122 //=============================================================================
123 // CAAudioChannelLayout::~CAAudioChannelLayout
124 //=============================================================================
125 CAAudioChannelLayout::~CAAudioChannelLayout ()
126 {
127  if (mLayout) {
128  mLayout->release();
129  mLayout = NULL;
130  }
131 }
132 
133 //=============================================================================
134 // CAAudioChannelLayout::CAAudioChannelLayout
135 //=============================================================================
136 CAAudioChannelLayout& CAAudioChannelLayout::operator= (const CAAudioChannelLayout &c)
137 {
138  if (mLayout != c.mLayout) {
139  if (mLayout)
140  mLayout->release();
141 
142  if ((mLayout = c.mLayout) != NULL)
143  mLayout->retain();
144  }
145 
146  return *this;
147 }
148 
149 CAAudioChannelLayout& CAAudioChannelLayout::operator= (const AudioChannelLayout* inChannelLayout)
150 {
151  if (mLayout && &mLayout->Layout() == inChannelLayout)
152  return *this;
153 
154  if (mLayout)
155  mLayout->release();
156 
157  if (inChannelLayout == NULL)
158  {
159  mLayout = RefCountedLayout::CreateWithNumberChannelDescriptions(0);
160  }
161  else
162  {
163  mLayout = RefCountedLayout::CreateWithLayout(inChannelLayout);
164  }
165  return *this;
166 }
167 
168 void CAAudioChannelLayout::SetWithTag(AudioChannelLayoutTag inTag)
169 {
170  if (mLayout)
171  mLayout->release();
172 
173  mLayout = RefCountedLayout::CreateWithLayoutTag(inTag);
174 }
175 
176 //=============================================================================
177 // CAAudioChannelLayout::operator==
178 //=============================================================================
179 bool CAAudioChannelLayout::operator== (const CAAudioChannelLayout &c) const
180 {
181  if (mLayout == c.mLayout)
182  return true;
183  return Layout() == c.Layout();
184 }
185 
186 //=============================================================================
187 // CAAudioChannelLayout::Print
188 //=============================================================================
189 void CAAudioChannelLayout::Print (FILE* file) const
190 {
191  CAShowAudioChannelLayout (file, &Layout());
192 }
193 
bool TTFOUNDATION_EXPORT operator==(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for equality.
Definition: TTObject.cpp:167