AEBook.c++ 1.88 KB
/*****************************************************************************
 *  File:  AEBook.c++ 
 *
 *  AEBook Class Implementations
 *
 ****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include "Assets.h"
#include "Mgrs.h"

/*****************************************************************************
 *
 *   Initialization Routines
 * 
 ****************************************************************************/

AEBook::AEBook()
{
    classType = AL_BOOK_CLASS;
    order = 0;
    npredictors = 0;
    bookData = 0;
    assert(theU64Dev->AllocHdwr(this,AL_BOOK_CLASS) == 0);
}

AEBook::~AEBook()
{
    if(bookData)
        free(bookData);
    theU64Dev->DeallocHdwr(this);
}

/*****************************************************************************
 *
 *    Asset's Methods
 *
 ****************************************************************************/

void AEBook::SetBook(int ord, int npds, short *data)
{
    int   c,bookSize;

    if(bookData)
        free(bookData);

    bookSize = npds*ord*ADPCMVSIZE*sizeof(s16);
    bookData = (short*)malloc(bookSize);
    if(!bookData)
    {
        fprintf(stderr,"unable to allocate memory for book data\n");
        return;
    }

    order = ord;
    npredictors = npds;
    bookSize /= 2;  /* copy using 16bit words */

    for(c = 0; c < bookSize; c++)
        bookData[c] = data[c];
}

int AEBook::GetOrder(void)
{
    return order;
}

int AEBook::GetNPredictors(void)
{
    return npredictors;
}

int AEBook::GetBookData(short *data)
{
    int    c,bookItems;

    if(!bookData)
        return 0;
    
    bookItems = npredictors*order*ADPCMVSIZE;

    for(c = 0; c < bookItems; c++)
        data[c] = bookData[c];

    return bookItems;  /* return the number of bookItems */
}

int AEBook::GetNumBookItems(void)
{
    return npredictors*order*ADPCMVSIZE;
}