コード例 #1
0
void CChannels::AllocateData(void)
{
	int		iSize;

	iSize = CalculateByteSize(miBitStride, miSize);
	FreeData();
	mabData.Allocate(&gcSystemAllocator, iSize);
}
コード例 #2
0
AudioBufferList*	CAAudioBufferList::Create(UInt32 inNumberBuffers)
{
	UInt32 theSize = CalculateByteSize(inNumberBuffers);
	AudioBufferList* theAnswer = static_cast<AudioBufferList*>(calloc(1, theSize));
	if(theAnswer != NULL)
	{
		theAnswer->mNumberBuffers = inNumberBuffers;
	}
	return theAnswer;
}
コード例 #3
0
CAAudioChannelLayout&	CAAudioChannelLayout::operator= (const AudioChannelLayout* inChannelLayout)
{
	if (mLayoutHolder)
		mLayoutHolder->release();

	UInt32 theSize = CalculateByteSize (inChannelLayout->mNumberChannelDescriptions);

	mLayoutHolder = new ACLRefCounter (theSize);

	memcpy(mLayoutHolder->mLayout, inChannelLayout, theSize);
	return *this;
}
コード例 #4
0
//=============================================================================
//	CAAudioChannelLayout::CAAudioChannelLayout
//=============================================================================
CAAudioChannelLayout::CAAudioChannelLayout (UInt32 inNumberChannels, bool inChooseSurround)
{
		// this chooses default layouts based on the number of channels...
	UInt32 theSize = CalculateByteSize (inNumberChannels);

	mLayoutHolder = new ACLRefCounter (theSize);

	AudioChannelLayout* layout = mLayoutHolder->GetLayout();

	layout->mNumberChannelDescriptions = inNumberChannels;

	switch (inNumberChannels)
	{
		case 1:
			layout->mChannelLayoutTag = kAudioChannelLayoutTag_Mono;
			break;
		case 2:
			layout->mChannelLayoutTag = inChooseSurround ? kAudioChannelLayoutTag_Binaural : kAudioChannelLayoutTag_Stereo;
			break;
		case 4:
			layout->mChannelLayoutTag = inChooseSurround ? kAudioChannelLayoutTag_Ambisonic_B_Format : kAudioChannelLayoutTag_AudioUnit_4;
			break;
		case 5:
			layout->mChannelLayoutTag = inChooseSurround ? kAudioChannelLayoutTag_AudioUnit_5_0 : kAudioChannelLayoutTag_AudioUnit_5;
			break;
		case 6:
			layout->mChannelLayoutTag = inChooseSurround ? kAudioChannelLayoutTag_AudioUnit_6_0 : kAudioChannelLayoutTag_AudioUnit_6;
			break;
		case 7:
			layout->mChannelLayoutTag = kAudioChannelLayoutTag_AudioUnit_7_0;
			break;
		case 8:
			layout->mChannelLayoutTag = kAudioChannelLayoutTag_AudioUnit_8;
			break;
		default:
			// here we have a "broken" layout, in the sense that we haven't any idea how to lay this out
			// the layout itself is all set to zeros
			// ### no longer true ###
			SetAllToUnknown(*layout, inNumberChannels);
			break;
	}
}
コード例 #5
0
BOOL CChannels::EndChange(void)
{
	int				i;
	SChannel*		psAddedChannel;
	SChannel*		psRemovedChannel;
	CChannel*		psChannel;
	int				iSize;
	int				iOffset;
	BOOL			bAnyAdded;
	int				iOldBitStride;
	int				iAddedBitStride;
	int				iOldByteStride;
	BOOL			bResult;

	//I don't think this handles the case where the channels have been re-ordered...
	//Which as there *IS* no way of re-ordering them shouldn't be a problem.

	bResult = TRUE;
	if (IsChanging())
	{
		if (mpvUserData != mpsChangingDesc->pvUserData)
		{
			//Switch between using mabData and mpvUserData.
			if ((mpvUserData == NULL) && (mpsChangingDesc->pvUserData != NULL))
			{
				FreeData();
			}
			else if ((mpvUserData != NULL) && (mpsChangingDesc->pvUserData == NULL))
			{
				AllocateData();
				//should copy from mpvUserData
			}
			mpvUserData = (char*)mpsChangingDesc->pvUserData;
		}

		if (!IsUserAllocated())
		{
			//We're using mabData and have already allocated it.
			if ((miBitStride != 0) && (miSize != 0))
			{
				//Remove
				for (i = 0; i < mpsChangingDesc->asRemovedChannels.NumElements(); i++)
				{
					psRemovedChannel = mpsChangingDesc->asRemovedChannels.Get(i);
					psChannel = GetChannel(psRemovedChannel->iChannel);
					if (psChannel->Is8BitAligned())
					{
						iOffset = psChannel->miByteOffset;
						iSize = psChannel->miByteSize;
						mabData.BatchRemoveElements(iOffset, iSize, miSize, miByteStride);
					}
					else
					{
						//Deal with bitty removal.
					}
					masChannelOffsets.RemoveAt(masChannelOffsets.GetIndex(psChannel), TRUE);
					Recalculate();
				}
			}

			//Add
			bAnyAdded = FALSE;
			for (i = 0; i < mpsChangingDesc->asAddedChannels.NumElements(); i++)
			{
				psAddedChannel = mpsChangingDesc->asAddedChannels.Get(i);

				psChannel = masChannelOffsets.Add();
				psChannel->Init(psAddedChannel->iChannel, psAddedChannel->eType, psAddedChannel->bReverse);
				bAnyAdded = TRUE;
			}

			if (bAnyAdded)
			{
				iOldBitStride = miBitStride;
				iOldByteStride = miByteStride;
				Recalculate();
				iAddedBitStride = miBitStride - iOldBitStride;
				if ((iAddedBitStride != 0) && (miSize != 0))
				{
					if (Is8BitAligned(iOldBitStride, iAddedBitStride))
					{
						iOffset = iOldByteStride;
						iSize = iAddedBitStride / 8;
						mabData.BatchInsertElements(iOffset, iSize, miSize, iOldByteStride);
					}
					else
					{
						//Deal with bitty addition.
					}
				}
			}

			//Change size due to size change.
			if (mpsChangingDesc->iSize != miSize)
			{
				miSize = mpsChangingDesc->iSize;
				iSize = CalculateByteSize(miBitStride, miSize);
				mabData.GrowToNumElements(iSize);
			}
		}
		else  //Using user allocated memory.
		{
			//This assumes the mpvUserData is *already* in the form being specified.
			for (i = 0; i < mpsChangingDesc->asRemovedChannels.NumElements(); i++)
			{
				psRemovedChannel = mpsChangingDesc->asRemovedChannels.Get(i);
				psChannel = GetChannel(psRemovedChannel->iChannel);
				masChannelOffsets.RemoveAt(masChannelOffsets.GetIndex(psChannel), TRUE);
			}

			for (i = 0; i < mpsChangingDesc->asAddedChannels.NumElements(); i++)
			{
				psAddedChannel = mpsChangingDesc->asAddedChannels.Get(i);

				psChannel = masChannelOffsets.Add();
				psChannel->Init(psAddedChannel->iChannel, psAddedChannel->eType, psAddedChannel->bReverse);
			}
			miSize = mpsChangingDesc->iSize;
			Recalculate();
		}

		mpsChangingDesc->Kill();
		free(mpsChangingDesc);
		mpsChangingDesc = NULL;
	}

	if (IsUserAllocated())
	{
		mpvDataCache = mpvUserData;
	}
	else
	{
		mpvDataCache = mabData.GetData();
	}
	return bResult;
}