/******************************************************************************

This is a tidy-up of the code used in MetalMame.

This version (c) 2010 written by Robbbert for Misfitmame 0.128.

Note that since it uses a closed-source DLL, it can only run in Windows.

The testing was done with fmod.dll ver 3.7.1.0 date 2003.

******************************************************************************/


/* NINO FMOD IMPLEMENTATION START */

#include "fmod.h"
#include "fmoddyn.h"
#include "fmod_errors.h"


/* Play a sample file using the FMOD lib ... mp2 mp3 wav ogg wma asf
   PlayFile(filename, looping, start point, end point); */

void PlayFile(int channel, int fsoundvolume, const char file[500], int looping, int start, int stop)
{
	static int fsoundinit = 0;
	FSOUND_STREAM *stream;

	if (!fsoundinit)
	{
		fsoundinit = FSOUND_Init(44100, 16, 0);
		FSOUND_SetVolume(-3, fsoundvolume);
	}

	if (looping)
	{
		stream = FSOUND_Stream_Open(file, FSOUND_LOOP_NORMAL , 0, 0);
		FSOUND_Stream_SetLoopPoints(stream, start, stop);
	}
	else
		stream = FSOUND_Stream_Open(file, FSOUND_LOOP_OFF, 0, 0);

	FSOUND_Stream_Play(channel, stream);

	FSOUND_SetVolume(channel, fsoundvolume);
}



/* StopFile(channel to be stopped) */

signed char StopFile(int channel)
{
	return FSOUND_StopSound(channel);
}

signed char PauseFile(int channel, signed char paused)
{
	return FSOUND_SetPaused(channel,  paused );
}

signed char FMODReset(void)
{
	return FSOUND_Init(44100, 16, 0);
}

signed char FMODVolume(int channel, int vol)
{
	return FSOUND_SetVolume(channel,vol);
}

int FMODGetVolume(int channel)
{
	return FSOUND_GetVolume(channel);
}

/* NINO FMOD IMPLEMENTATION END */
