sound.c++ 3.35 KB
//====================================================================
// sound.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 <stdlib.h>
#include "libbank.h"

ICSound::ICSound()
{
    declclass = ICSOUND;
    size = sizeof(ALSound);
    
    samplePan           = AL_PAN_CENTER;
    sampleVolume        = AL_VOL_FULL;
    sound               = 0;
    wave                = 0;
    envelope            = 0;
    keymap              = 0;    
}

void ICSound::SetPan(int pan) 
{
    FailIf(((pan < AL_PAN_LEFT) || (pan > AL_PAN_RIGHT)), IC_PARAMETER_ERR);

    samplePan = pan;
}

void ICSound::SetVol(int vol)
{
    FailIf( (vol < 0) || (vol > AL_VOL_FULL), IC_PARAMETER_ERR);

    sampleVolume = vol;
}

void ICSound::SetKeyMap(ICKeyMap *map)
{
    FailIf(map->GetObjectClass() != ICKEYMAP, IC_TYPE_ERR);

    keymap = map;
}

void ICSound::SetEnvelope(ICEnvelope *env)
{
    FailIf(env->GetObjectClass() != ICENVELOPE, IC_TYPE_ERR);

    envelope = env;
}

void ICSound::SetWaveTable(ICWave *w)
{
    FailIf(w->GetObjectClass() != ICWAVE, IC_TYPE_ERR);
    wave = w;
}

void ICSound::Assemble()
{
    char msg[256];

    FailIfMsg(!declid, IC_INTERNAL_ERR, "undeclared sound");

    FailIfMsg(!keymap, IC_MISC_ERR,
              icErrStr(msg, declid->name, " must have a keymap\n"));

    FailIfMsg(!envelope, IC_MISC_ERR,
              icErrStr(msg, declid->name, " must have an envelope\n"));

    FailIfMsg(!wave, IC_MISC_ERR,
              icErrStr(msg, declid->name,
                       " must have at least one wavetable\n"));

    size = Size();

    ALSound *s = (ALSound *)calloc(1, size);
    FailIf(!s, IC_INTERNAL_ERR);

    s->samplePan        = samplePan;
    s->sampleVolume     = sampleVolume;
    s->keyMap           = (ALKeyMap *)keymap->GetObjectOffset();
    s->envelope         = (ALEnvelope *)envelope->GetObjectOffset();
    s->wavetable        = (ALWaveTable *)wave->GetObjectOffset();

    sound = s;
    thing = sound;
}

void ICSound::Prune()
{
    this->IncRefCount();

    keymap->Prune();
    envelope->Prune();
    wave->Prune();
}

void ICSound::MarkUsed(void)
{
    if(!usedFlag)
        usedFlag = TRUE;

    keymap->MarkUsed();
    envelope->MarkUsed();
    wave->MarkUsed();
}
void ICSound::Print()
{
    printf("Sound: %s\n", declid->name);

    ICObject::Print();
    
    printf("\twavetable:\t= %x\n", sound->wavetable);
    printf("\tenvelope:\t= %x\n", sound->envelope);
    printf("\tkey map:\t= %x\n", sound->keyMap);
    printf("\tsamplePan:\t= %x\n", sound->samplePan);
    printf("\tsampleVolume:\t= %x\n", sound->sampleVolume);
    printf("\n");
}