46 #include "CAAudioChannelLayout.h"
47 #include "CAAutoDisposer.h"
55 AudioChannelLayout* CAAudioChannelLayout::Create(UInt32 inNumberChannelDescriptions)
57 UInt32 theSize = CalculateByteSize(inNumberChannelDescriptions);
58 AudioChannelLayout* theAnswer =
static_cast<AudioChannelLayout*
>(CA_calloc(1, theSize));
61 SetAllToUnknown(*theAnswer, inNumberChannelDescriptions);
66 void CAAudioChannelLayout::Destroy(AudioChannelLayout* inChannelLayout)
68 free(inChannelLayout);
71 void CAAudioChannelLayout::SetAllToUnknown(AudioChannelLayout& outChannelLayout, UInt32 inNumberChannelDescriptions)
73 outChannelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
74 outChannelLayout.mChannelBitmap = 0;
75 outChannelLayout.mNumberChannelDescriptions = inNumberChannelDescriptions;
76 for(UInt32 theChannelIndex = 0; theChannelIndex < inNumberChannelDescriptions; ++theChannelIndex)
78 outChannelLayout.mChannelDescriptions[theChannelIndex].mChannelLabel = kAudioChannelLabel_Unknown;
79 outChannelLayout.mChannelDescriptions[theChannelIndex].mChannelFlags = 0;
80 outChannelLayout.mChannelDescriptions[theChannelIndex].mCoordinates[0] = 0;
81 outChannelLayout.mChannelDescriptions[theChannelIndex].mCoordinates[1] = 0;
82 outChannelLayout.mChannelDescriptions[theChannelIndex].mCoordinates[2] = 0;
86 bool operator== (
const AudioChannelLayout &x,
const AudioChannelLayout &y)
90 UInt32 theSize1 = CAAudioChannelLayout::CalculateByteSize(x.mNumberChannelDescriptions);
91 UInt32 theSize2 = CAAudioChannelLayout::CalculateByteSize(y.mNumberChannelDescriptions);
93 if (theSize1 != theSize2)
96 return !memcmp (&x, &y, theSize1);
100 inline UInt32 CountOnes(UInt32 x)
104 x = x - ((x >> 1) & 0x55555555);
105 t = ((x >> 2) & 0x33333333);
106 x = (x & 0x33333333) + t;
107 x = (x + (x >> 4)) & 0x0F0F0F0F;
113 UInt32 CAAudioChannelLayout::NumberChannels (
const AudioChannelLayout& inLayout)
115 if (inLayout.mChannelLayoutTag == kAudioChannelLayoutTag_UseChannelDescriptions)
116 return inLayout.mNumberChannelDescriptions;
118 if (inLayout.mChannelLayoutTag == kAudioChannelLayoutTag_UseChannelBitmap)
119 return CountOnes (inLayout.mChannelBitmap);
121 return AudioChannelLayoutTag_GetNumberOfChannels(inLayout.mChannelLayoutTag);
124 void CAShowAudioChannelLayout (FILE* file,
const AudioChannelLayout *layout)
128 fprintf (file,
"\tNULL layout\n");
131 fprintf (file,
"\tTag=0x%X, ", (
int)layout->mChannelLayoutTag);
132 if (layout->mChannelLayoutTag == kAudioChannelLayoutTag_UseChannelBitmap)
133 fprintf (file,
"Using Bitmap:0x%X\n", (
int)layout->mChannelBitmap);
135 fprintf (file,
"Num Chan Descs=%d\n", (
int)layout->mNumberChannelDescriptions);
136 const AudioChannelDescription *desc = layout->mChannelDescriptions;
137 for (
unsigned int i = 0; i < layout->mNumberChannelDescriptions; ++i, ++desc) {
138 fprintf (file,
"\t\tLabel=%d, Flags=0x%X, ", (
int)desc->mChannelLabel, (
int)desc->mChannelFlags);
139 fprintf (file,
"[az=%f,el=%f,dist=%f]\n", desc->mCoordinates[0], desc->mCoordinates[1], desc->mCoordinates[2]);
bool TTFOUNDATION_EXPORT operator==(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for equality.