// -------------------------------------------------------------------------
// raw.c
//
// this will play a RAW (.pcm) format file using the ac layer only, sort of an
// audio programmers hello world...
//
// COPYRIGHT (C) SEGA OF AMERICA, INC. 1998
// All rights reserved.
//
// Information and source code samples contained herein are 
// provided "as-is", without representations or warranties, and 
// are subject to change without notice.
//
// SEGA OF AMERICA, INC. cannot support modifications or 
// derivative works created from the sample source code provided. 
// Developers may use, reproduce, and modify portions or entire 
// sections of the sample source code for the purposes of creating
// Dreamcast applications.  
//
// Sample source code contained herein may not be appropriate 
// for use under all circumstances.  Please consult Developer 
// documentation provided along with your Dreamcast unit for
// additional information and suggestions.
//
// Author: 	Ralph "Cooksey" Thomas
//
// Tabs: 	4
//
// Rev:		04/09/99	This text header added
// -------------------------------------------------------------------------

#include <am.h>

#define RAW_FILENAME "glass.pcm"

void playRawSoundTest(void)
{
volatile KTU32 *firstFreeMemory;
KTU32			sizeOfSound;
ACFILE			fd				=	NULL;
KTU32			voiceChannel	=	0;
KTU32 			startOffset		=	0;

acPrintf("***************** START PLAY RAW SOUND TEST SEQUENCE **********************\n");

if(testInit()==KTFALSE)
	{
	acPrintf("Failed to initialize system\n");
	return;
	}

// get the beginning of free sound memory
firstFreeMemory	=	acSystemGetFirstFreeSoundMemory();

acPrintf("0x%x = acSystemGetFirstFreeSoundMemory() // get the first free sound memory address\n",firstFreeMemory);

// get the size of the sound
if(acFileGetSize(RAW_FILENAME,&sizeOfSound)==KTFALSE)
	{
	acPrintf("acFileGetSize(%s,%u)==FAIL\n",RAW_FILENAME,sizeOfSound);
	return;
	}
else
	{
	acPrintf("acFileGetSize(%s,%u) // get the size of the raw PCM sound",RAW_FILENAME,sizeOfSound);
	}

//load the raw PCM data
if(acFileLoad(RAW_FILENAME,firstFreeMemory)==KTFALSE)
	{
	acPrintf("acFileLoad(%s,0x%x)==FAIL\n",RAW_FILENAME,firstFreeMemory);
	return;
	}
else
	{
	acPrintf("acFileLoad(%s,0x%x) // load the raw PCM sound",RAW_FILENAME,firstFreeMemory);
	}

if(acDigiOpen(voiceChannel,(KTU32)firstFreeMemory,sizeOfSound,AC_16BIT,44100)==KTFALSE)
	{
	acPrintf("acDigiOpen(%u,0x%x,%u,%d,%d)==FAIL\n",voiceChannel,firstFreeMemory,sizeOfSound,AC_16BIT,44100);
	return;
	}
else
	{
	acPrintf("acDigiOpen(%u,0x%x,%u,%d,%d) // open a digital voice channel to play it through",voiceChannel,firstFreeMemory,sizeOfSound,AC_16BIT,44100);
	}

if(acDigiPlay(voiceChannel,startOffset,AC_LOOP_OFF)==KTFALSE)
	{
	acPrintf("acDigiPlay(0,0,AC_LOOP_OFF)==FAIL\n");
	return;
	}
else
	{
	acPrintf("acDigiPlay(0,0,AC_LOOP_OFF) // start the sound playing");
	}

acSystemDelay(100000000);

if(acDigiStop(voiceChannel)==KTFALSE)
	{
	acPrintf("acDigiStop(0)==FAIL\n");
	return;
	}
else
	{
	acPrintf("acDigiStop(0) // stop the sound (not really necessary here)");
	}

if(acDigiClose(voiceChannel)==KTFALSE)
	{
	acPrintf("acDigiClose(0)==FAIL\n");
	return;
	}
else
	{
	acPrintf("acDigiClose(0) // close the voice channel");
	}

testShutdown(); // bye!

acPrintf("***************** END PLAY RAW SOUND TEST SEQUENCE **********************\n");
}

