test5.c 5.38 KB
/*====================================================================
 * test5.c
 *
 * Synopsis:
 *
 * Random sound player tester.
 *
 * 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 <libaudio.h>
#include "audio.h"
#include "audiotest.h"

#define REV_INST_SND    15

#define TEST5_STOPPED 	0
#define TEST5_RUNNING	1
#define TEST5_STOPPING  2
#define TEST5_DONE      3

static void startTest5();
static void stopTest5();
static void doRetrace();
static void ButtProc5(u16 oldButton,u16 newButton);

test_cntrl Test5 = {
    &startTest5,
    &stopTest5,
    &ButtProc5,      /* button proc */
    &doRetrace,
    NULL,            /* void *retraceData */
    1                /* u32  numSubTests */
};

extern u32      gTestDone;
extern ALHeap   gHeapRec;
extern u8       gHeapBuf[AUDIO_HEAP_SIZE];

static ALSndPlayer     *sndp;
static ALInstrument    *sfxInst;
static u32             test5State;
static ALSndId         sfxID;    
static f32             engPitch;
static ALPan           engPan;
static u8              engFXMix;
static s16             engVol;

/***********************************************************************
 * Test interface routines
 ***********************************************************************/
static void startTest5() 
{
    ALSynConfig         c;
    u32                 bankLen;
    ALBankFile          *bankPtr;
    ALBank              *bank;
    amConfig            amc;
    ALSndpConfig        SPConfig;

    alHeapInit(&gHeapRec, gHeapBuf, sizeof(gHeapBuf));    

    /**** Load the bank file from ROM ****/
    bankLen = _sfxbankSegmentRomEnd - _sfxbankSegmentRomStart;
    bankPtr = alHeapAlloc(&gHeapRec, 1, bankLen);
    romCopy(_sfxbankSegmentRomStart, (char *)bankPtr, bankLen);

    alBnkfNew(bankPtr, (u8 *) _sfxtableSegmentRomStart);
    bank = bankPtr->bankArray[0];
    sfxInst = bank->instArray[0];
    
    /**** Create the Audio Manager ****/
    c.maxVVoices = MAX_SYNTH_VVOICES;
    c.maxPVoices = MAX_SYNTH_PVOICES;
    c.maxUpdates = MAX_SYNTH_UPDATES;
    c.dmaproc    = 0;                  /* audio mgr will fill this in */
    c.fxType     = AL_FX_SMALLROOM; 
    c.heap       = &gHeapRec;
    
    amc.outputRate = 44100;
    amc.framesPerField = NUM_FIELDS;
    amc.maxACMDSize = MAX_RSP_CMDS;
    amCreateAudioMgr(&c, AUDIO_PRIORITY, &amc);

    /*** Initialize the soundplayer  ****/
    sndp = alHeapAlloc(&gHeapRec, 1, sizeof(ALSndPlayer));
    SPConfig.maxSounds = MAX_SNDP_VOICES;
    SPConfig.maxEvents = MAX_SNDP_EVENTS;
    SPConfig.heap  = &gHeapRec;

    alSndpNew(sndp, &SPConfig);
    test5State = TEST5_STOPPED;
    engPitch = 0.5f;
    engPan = 64;
    engFXMix = 0;
    engVol = 0x3FFF;
}

static void stopTest5() 
{
    int i;

    PRINTF("Stopped test5\n");

    alSndpDelete(sndp);
    amDestroyAM();  
}


static void doRetrace() 
{
    switch(test5State)
    {
	case TEST5_STOPPED:
	    sfxID = alSndpAllocate(sndp,sfxInst->soundArray[REV_INST_SND]);
	    alSndpSetSound(sndp,sfxID);
	    alSndpSetPitch(sndp,engPitch);
	    alSndpSetPan(sndp,engPan);
	    alSndpSetVol(sndp,engVol);
	    alSndpSetFXMix(sndp,engFXMix);
	    alSndpPlay(sndp);
	    test5State = TEST5_RUNNING;
	    PRINTF("Engine Rev Test.\n");
	    PRINTF("Use the joypad to control volume and pitch\n");
	    PRINTF("Use the L & R buttons to control pan\n");
	    PRINTF("Press the start button to stop and go to next test\n");
	    break;
	case TEST5_RUNNING:
	    break;
	case TEST5_STOPPING:
	    if(alSndpGetState(sndp) == AL_STOPPED)
	    {
		alSndpDeallocate(sndp,sfxID);
		test5State = TEST5_DONE;
	    }
	    break;
	case TEST5_DONE:
	    gTestDone = TRUE;
	    break;
    }

}


static void ButtProc5(u16 oldButton,u16 newButton)
{

    if(test5State == TEST5_RUNNING)
    {
	if(newButton & CONT_START)
	{
	    test5State = TEST5_STOPPING;
	    alSndpStop(sndp);
	    return;
	}
	
	if (newButton & CONT_UP)
	{
	    if((engPitch+0.01f) < 2.0f)
		engPitch += 0.01f;
	    else
		engPitch = 2.0f;
	    alSndpSetPitch(sndp,engPitch);
	}
	
	if (newButton & CONT_DOWN)
	{
	    if((engPitch-0.01f) > 0.0f)
		engPitch -= 0.01f;
	    else
		engPitch = 0.01f;
	    alSndpSetPitch(sndp,engPitch);
	}
	
	if(newButton & CONT_LEFT)
	{
	    if((engVol - 0x40) > 0)
		engVol -= 0x40;
	    else
		engVol = 0;
	
	    alSndpSetVol(sndp,engVol);
	}
	
	if(newButton & CONT_RIGHT)
	{
	    if((u16)(engVol + 0x40) < 0x7FFF)
		engVol += 0x40;
	    else
		engVol = 0x7FFF;
	    
	    alSndpSetVol(sndp,engVol);
	}
	
	if(newButton & CONT_L)
	{
	    if((engPan - 1) > 0)
		engPan -= 1;
	    else
		engPan = 0;
	    alSndpSetPan(sndp,engPan);
	}
	
	if(newButton & CONT_R)
	{
	    if((engPan + 1) < 127)
		engPan += 1;
	    else
		engPan = 127;
	    alSndpSetPan(sndp,engPan);
	}
    }
}