//	Sounds.h - Singleton to play sound effects.
//  ----------------------------------------------------------------------------
//	This file is part of 'Die, you Stupid Hurdlers!', a game for Ludum Dare 14.
//	Copyright (C) 2009  Niall Moody
//	
//	This program is free software: you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with this program.  If not, see <http://www.gnu.org/licenses/>.
//	----------------------------------------------------------------------------

#ifndef SOUNDS_H_
#define SOUNDS_H_

#include <string>
#include <stdint.h>
#include <vorbis/vorbisfile.h>

///	Singleton to play sound effects.
class Sounds
{
  public:
	///	Returns the sole instance of the class.
	static Sounds& getInstance();

	///	Enum listing the various types of sound which can be played.
	enum SoundType
	{
		Birth = 0,
		CapitalistCollision,
		CapitalistDeath,
		Death,
		DebilitationWave,
		PoliceCollision,
		TurnRevolutionary,

		NumSoundTypes
	};

	///	Triggers a sound to play.
	void playSound(SoundType sound);

	///	Fills a buffer with audio.
	void getAudio(float *buffer, int numSamples);

#ifdef WIN32
	~Sounds();
#endif
  private:
	///	Constructor.
	Sounds();
#ifndef WIN32
	///	Destructor.
	~Sounds();
#endif
	///	Struct representing a single sound.
	struct Sound
	{
		///	Constructor.
		Sound():
		data(0),
		size(0),
		index(0),
		active(false)
		{
			
		};

		///	The buffer containing the sound data.
		float *data;
		///	The size of the sound data.
		uint32_t size;
		///	The index within the data buffer.
		uint32_t index;
		///	Whether this Sound is currently active.
		bool active;
	};
	///	Struct representing a sound file.
	struct SoundFile
	{
		///	The buffer containing the sound data.
		float *data;
		///	The size of the sound data.
		uint32_t size;
	};

	///	Helper method to load an ogg file into a SoundFile struct.
	void loadFile(const std::string& tempstr, SoundFile *sf);

	///	Some constants.
	enum
	{
		NumSounds = 128
	};

	///	The various sound files which can be loaded.
	SoundFile soundFiles[NumSoundTypes];
	///	The sounds which can be played.
	Sound sounds[NumSounds];
	///	The number of active sounds.
	int activeSounds;
};

#endif
