AeBookAsset.c++ 2.01 KB
/*****************************************************************************
 *  File:  AeADPCMBookAsset.c++ 
 *
 *  AeADPCMBookAsset Class Implementations
 *
 ****************************************************************************/
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

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


AeADPCMBookAsset::AeADPCMBookAsset(const char * name,
				   int order,
				   int npredictors,
				   int vsize,
				   short * bookData)
    : AeAsset (name, kADPCMBookType)
{
    fNBookItems = 0;
    fBookData = NULL;

    SetBook (order, npredictors, vsize, bookData);
}

AeADPCMBookAsset::~AeADPCMBookAsset()
{
    if(fBookData)
        free (fBookData);

    if (fParentList)
    {
	AeAsset *	parent;
	int		i;

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

void
AeADPCMBookAsset::SetBook(int order, int npredictors, int vsize, short * bookData)
{
    int   bookItems;

    fOrder = order;
    fNpredictors = npredictors;
    fVSize = vsize;

    bookItems = npredictors * order * vsize;

    if (bookItems && bookData)
    {
	if (bookItems != fNBookItems)
	{
	    if (fBookData)
		free (fBookData);

	    fNBookItems = bookItems;
	    fBookData = (short *)malloc(bookItems * sizeof (short));

	    FailNIL (fBookData);
	}

	memcpy (fBookData, bookData, fNBookItems * sizeof (short));
    }
}

int
AeADPCMBookAsset::GetOrderProc(AeAsset * asset)
{
    assert (asset);
    return ((AeADPCMBookAsset *)asset)->GetOrder ();
}

int
AeADPCMBookAsset::GetNPredictorsProc (AeAsset * asset)
{
    assert (asset);
    return ((AeADPCMBookAsset *)asset)->GetNPredictors ();
}

int
AeADPCMBookAsset::GetBookData (short * bookData)
{
    if(!fBookData)
        return 0;
    
    assert (fNBookItems);

    memcpy (bookData, fBookData, fNBookItems * sizeof(short));
    
    return fNBookItems;
}