wavetable.c++ 3.42 KB
//====================================================================
// wavetable.c++
//
// Synopsis:
//
// Author(s)
//  Steve Shepard
//
// Copyright 1993, Silicon Graphics, Inc.
// All Rights Reserved.
//
// This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
// the contents of this file may not be disclosed to third parties, copied or
// duplicated in any form, in whole or in part, without the prior written
// permission of Silicon Graphics, Inc.
//
// RESTRICTED RIGHTS LEGEND:
// Use, duplication or disclosure by the Government is subject to restrictions
// as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
// and Computer Software clause at DFARS 252.227-7013, and/or in similar or
// successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
// rights reserved under the Copyright Laws of the United States.
//====================================================================

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "libbank.h"

ICWave::ICWave()
{
    declclass = ICWAVE;
    size = sizeof(ALWaveTable);

    base        = 0;
    len         = 0;
    
    loop        = 0;
    book        = 0;
}

ICWave::~ICWave()
{
}

void ICWave::SetName(char *fname)
{
    char *n = (char *)malloc(strlen(fname));

    assert(n);
    strcpy(n,fname);
    declid->name = n;
}
void ICWave::SetTable(char *b, int l)
{
    base = b;
    len  = l;
}

void ICWave::SetLoop(ICLoop *l)
{
    FailIf(l->GetObjectClass() != ICLOOP, IC_TYPE_ERR);

    loop = l;
}

void ICWave::SetBook(ICBook *b)
{
    FailIf(b->GetObjectClass() != ICBOOK, IC_TYPE_ERR);

    book = b;
}
    
void ICWave::SetBase(char *b)
{
    base = b;
}

void ICWave::SetLen(int l)
{
    len = l;
}

void ICWave::SetType(int t)
{
    type = t;
}

void ICWave::Assemble()
{
    size = this->Size();
    
    ALWaveTable *w =(ALWaveTable *)calloc(1, size);
    assert(w);

    w->base     = (u8 *) base;
    w->len      = len;
    w->type     = type;

    switch (type){
        case (AL_ADPCM_WAVE):
            if (loop) {
                w->waveInfo.adpcmWave.loop = (ALADPCMloop *)loop->GetObjectOffset();
            } else {
                w->waveInfo.adpcmWave.loop = 0;
            }
    
            w->waveInfo.adpcmWave.book = (ALADPCMBook *)book->GetObjectOffset();
            break;
            
        case (AL_RAW16_WAVE):
            if (loop) {
                w->waveInfo.rawWave.loop = (ALRawLoop *)loop->GetObjectOffset();
            } else {
                w->waveInfo.rawWave.loop = 0;
            }
            break;

        default:
            printf("unsupported format\n");
            break;
            
    }
    wave = w;
    thing = wave;
}

void ICWave::Prune()
{
    this->IncRefCount();
    
    if (loop)
        loop->Prune();
    
    if (book)
        book->Prune();
}

void ICWave::MarkUsed(void)
{
    if(!usedFlag)
        usedFlag = TRUE;
    
    if (loop)
        loop->MarkUsed();
    
    if (book)
        book->MarkUsed();
}

void ICWave::Print()
{
    if (declid) {
        printf("Wave Table: %s\n", declid->name);
    } else {
        printf("Wave Table: \n");
    }
    
    ICObject::Print();
    
    printf("\tbase:\t\t= 0x%x\n", wave->base);
    printf("\tlen:\t\t= 0x%x\n", wave->len);
    printf("\ttype:\t\t= 0x%x\n", wave->type);
    printf("\tloop:\t\t= %x\n", wave->waveInfo.adpcmWave.loop);
    printf("\tbook:\t\t= %x\n", wave->waveInfo.adpcmWave.book);
    printf("\n");
}