Пример #1
0
static void	HP_PreferredChannels_ConstructDictionaryFromLayout(const AudioChannelLayout& inLayout, CACFDictionary& outLayoutDictionary)
{
	//	stick in the tag
	outLayoutDictionary.AddUInt32(CFSTR("channel layout tag"), inLayout.mChannelLayoutTag);
	
	//	stick in the bitmap
	outLayoutDictionary.AddUInt32(CFSTR("channel bitmap"), inLayout.mChannelBitmap);
	
	//	stick in the number channels
	outLayoutDictionary.AddUInt32(CFSTR("number channels"), inLayout.mNumberChannelDescriptions);
	
	//	add the channel descriptions, if necessary
	if(inLayout.mChannelLayoutTag == kAudioChannelLayoutTag_UseChannelDescriptions)
	{
		//	create an array to hold the channel descriptions
		CACFArray theChannelDescriptions(true);
		if(theChannelDescriptions.IsValid())
		{
			//	iterate through the descriptions and stick them in the array
			for(UInt32 theChannelIndex = 0; theChannelIndex < inLayout.mNumberChannelDescriptions; ++theChannelIndex)
			{
				//	create a dictionary to hold the description
				CACFDictionary theDescription(true);
				if(theDescription.IsValid())
				{
					//	stick in the easy values
					theDescription.AddUInt32(CFSTR("channel label"), inLayout.mChannelDescriptions[theChannelIndex].mChannelLabel);
					theDescription.AddUInt32(CFSTR("channel flags"), inLayout.mChannelDescriptions[theChannelIndex].mChannelFlags);
				
					//	create an array to hold the coordinates
					CACFArray theCoordinates(true);
					if(theCoordinates.IsValid())
					{
						//	add the coordinates to the array
						for(UInt32 theCoordinateIndex = 0; theCoordinateIndex < 3; ++theCoordinateIndex)
						{
							theCoordinates.AppendFloat32(inLayout.mChannelDescriptions[theChannelIndex].mCoordinates[theCoordinateIndex]);
						}
						
						//	add the array of coordinates to the description
						theDescription.AddArray(CFSTR("coordinates"), theCoordinates.GetCFArray());
					}
					
					//	add the description to the array of descriptions
					theChannelDescriptions.AppendDictionary(theDescription.GetCFDictionary());
				}
			}
			
			//	add the array of descriptions to the layout dictionary
			outLayoutDictionary.AddArray(CFSTR("channel descriptions"), theChannelDescriptions.GetCFArray());
		}
	}
}
Пример #2
0
OSStatus	CAAudioChannelLayout::Save (CFPropertyListRef *outData) const 
{
	const AudioChannelLayout& layout = Layout();

	CACFDictionary dict (false);
	if (!dict.AddUInt32 (kACLTagKey, layout.mChannelLayoutTag))
		goto badadd;
	if (layout.mChannelBitmap && !dict.AddUInt32 (kACLBitmapKey, layout.mChannelBitmap))
		goto badadd;
	
	if (layout.mNumberChannelDescriptions)
	{	
		CFMutableArrayRef descs = CFArrayCreateMutable (NULL, layout.mNumberChannelDescriptions, &kCFTypeArrayCallBacks);
		
		const AudioChannelDescription *desc = layout.mChannelDescriptions;
		for (unsigned int i = 0; i < layout.mNumberChannelDescriptions; ++i, ++desc) 
		{
			CACFDictionary descDict (true);
			if (!descDict.AddUInt32 (kACLLabelKey, desc->mChannelLabel))
				{ CFRelease (descs); goto badadd; }
			if (!descDict.AddUInt32 (kACLFlagsKey, desc->mChannelFlags))
				{ CFRelease (descs); goto badadd; }
			if (!descDict.AddFloat32 (kACLCoords0Key, desc->mCoordinates[0]))
				{ CFRelease (descs); goto badadd; }
			if (!descDict.AddFloat32 (kACLCoords1Key, desc->mCoordinates[1]))
				{ CFRelease (descs); goto badadd; }
			if (!descDict.AddFloat32 (kACLCoords2Key, desc->mCoordinates[2]))
				{ CFRelease (descs); goto badadd; }
			
			CFArrayAppendValue (descs, descDict.AsPropertyList());
		}
		dict.AddArray (kACLDescsKey, descs);
		
		CFRelease (descs);
	}
	
	*outData = dict.GetDict();	
	
	return noErr;
	
badadd:
	dict.ShouldRelease(true);
	return paramErr;
}