back to the text
/*----------------------------------------------------
 * 
 * SOUND.c - sound variables and functions
 *           Marcus Thiebaux version
 * 
 *--------------------------------------------------*/

#include "INCLUDES.h"

static int dud;

/*--------------------------------------------------*/

AUDIOserver::AUDIOserver(void)
{
	dud = TRUE; // assume disabled
}

/*--------------------------------------------------*/

AUDIOserver::~AUDIOserver(void)
{
	if(dud) return;
	EndSoundServer();
	cout << "AUDIOserver destructed <<<<<< <<<<<< <<<<<< <<<<<<" << endl;
}

/*--------------------------------------------------*/

void AUDIOserver::enable(int E, int F)
{	
	if(E)
	{
	    if(CAVEMasterDisplay() || F)
		{
		if (!BeginSoundServer()
			{
		    cout << "AUDIOserver err : BeginSoundServer failed ////// ////// ////// //////" << endl;
		    dud = TRUE;
		    return;
		    }
		actorMessage(A_SetPrintCommands, "F", 1.0);
		cout << "AUDIOserver enabled >>>>>> >>>>>> >>>>>> >>>>>>" << endl;
		dud = FALSE;
		}
	}
}

/*--------------------------------------------------*/

AUDIOsample::AUDIOsample(void)
{
	actor = -1; 
	note = -1;
}

/*--------------------------------------------------*/

AUDIOsample::~AUDIOsample(void)
{	
	destroy();
}

/*--------------------------------------------------*/

void AUDIOsample::destroy(void)
{
	if(dud) return;
	loop(1.0, 1.0, SET_LOOP_OFF);
}

/*--------------------------------------------------*/

void AUDIOsample::create(char *dir, char *file)
{
    static float abrupt_envelope[7] = {0.0, 0.02, 1.0, -1.0, 1.0, 0.02, 0.0};
	
	if(!dud)
	{
	    if((actor = createActor(SampleActor)) == -1)
		{ 
			cout << "AUDIOsample::create err : createActor failed ////// ////// ////// //////" << endl;
			dud = TRUE;
			return;
		}
	    actorMessage(A_SetDirectory, "FS", actor, dir);
	    actorMessage(A_SetDefaultEnv, "FIA", actor, 7, abrupt_envelope);
	    actorMessage(A_UseFreqForPitchNum, "F", actor);
	    memcpy(sample, file, 128);
	}
}

/*--------------------------------------------------*/

void AUDIOsample::play(float freq, float ampl, int ctl)
{
	if(dud) return;
	if(ctl == SET_PLAY_CUT)
	{
	    if(note != -1) actorMessage(A_EndNote, "FF", actor, note);
	    note = actorMessage(A_BeginNote, "FFFS", actor, freq, ampl, sample);
	}
	else
	if(ctl == SET_PLAY_AMP)
	{
	    actorMessage(A_SetAmpl, "FFF", actor, note, ampl);
	}
	else
	    note = actorMessage(A_BeginNote, "FFFS", actor, freq, ampl, sample);
}

/*--------------------------------------------------*/

void AUDIOsample::loop(float freq, float ampl, int ctl)
{
	if(dud) return;
	if(ctl == SET_LOOP_ON)
	{
	    if(note != -1) actorMessage(A_EndNote, "FF", actor, note);
	    note = actorMessage(A_BeginNote, "FFFS", actor, freq, ampl, sample);
	    actorMessage(A_SetLoop, "FFF", actor, note, 1.0);
	}
	else
	if(ctl == SET_LOOP_AMP)
	{
	    actorMessage(A_SetAmpl, "FFF", actor, note, ampl);
	}
	else
	if(ctl == SET_LOOP_OFF)
	{
	    actorMessage(A_EndNote, "FF", actor, note);
	}
}

/*--------------------------------------------------*/