AeLoopAsset.c++ 1.86 KB
/*****************************************************************************
 *  File:  AeLoopAsset.c++ 
 *
 *  AeLoopAsset Class Implementations
 *
 ****************************************************************************/
#include <assert.h>
#include <stdlib.h>

#include "AeAsset.h"
#include "GList.h"


AeLoopAsset::AeLoopAsset (const char * name, int start, int end, int count)
    : AeAsset (name, kLoopType)
{
    fStart = start;
    fEnd = end;
    fCount = count;
}

AeLoopAsset::~AeLoopAsset()
{
    if (fParentList)
    {
	AeAsset *	parent;
	int		i;

	// nullify any references to this asset
	fParentList->Start (i, kReverse);
	while (fParentList->Prev (i, parent))
	{
	    if (((AeWaveAsset *)parent)->GetLoop () == this)
		((AeWaveAsset *)parent)->SetLoop (NULL);	
	}
    }
}


////////////////////////////////////////
//
//	ADPCM Loop Class
//
////////////////////////////////////////


AeADPCMLoopAsset::AeADPCMLoopAsset (const char * name,
				    int start, int end, int count,
				    int stateSize, short * stateArray)
    : AeLoopAsset (name, start, end, count)
{
    fStateSize = 0;
    fStateArray = NULL;

    if (stateSize && stateArray)
	SetStateData (fStateSize, stateArray);
}

AeADPCMLoopAsset::~AeADPCMLoopAsset()
{
    if (fStateArray)
	free (fStateArray);
}


void
AeADPCMLoopAsset::SetStateData (int stateSize, short * stateArray)
{
    int i;
    
    assert (stateSize);
    assert (stateArray != NULL);

    if (stateSize != fStateSize)
    {
	void * ptr;

	fStateSize = stateSize;
	if ((ptr = realloc (fStateArray, fStateSize * sizeof(short))) != NULL)
	    fStateArray = (short *)ptr;
    }

    for (i=0; i<fStateSize; i++)
        fStateArray[i] = stateArray[i];
}

void
AeADPCMLoopAsset::GetStateData (int & stateSize, short * stateArray)
{
    int i;
    
    stateSize = fStateSize;

    for (i=0; i<fStateSize; i++)
        stateArray[i] = fStateArray[i];
}