
/* Maelstrom Sound Mixer class

	-Sam Lantinga			(5/5/95)
*/

#include "sound_cmds.h"
#include "sample.h"

#ifdef linux
#define _PATH_DEV_DSP	"/dev/dsp"
#else
#define _PATH_DEV_DSP	"/dev/audio"
#endif /* linux */

/* 0002 = 2 fragments */
/* 000a = 2^a (1024) bytes/fragment (lower this for faster reaction time) */
#define FRAG_SPEC	0x0002000a

/* Woah!  The CLASS! :) */
class Mixer {

public:
	Mixer(char *device, unsigned short initvolume);
	~Mixer();

	int  SetVolume(unsigned short Volume);
	int  SoundID(unsigned short channel);
	int  Play_Sample(unsigned short channel, Sample *sample);
	void Play(void);
	void Halt(unsigned short channel);
	void HaltAll(void);

private:
	void PlaySleep(void);		// Sleep instead of play sound
	int  DSPopen(void);		// Open the sound device
	void DSPclose(void);		// Close the sound device

	char *dsp_device;		// The pathname of the sound device
	int   dsp_fd;			// The sound device file descriptor
	int   speed;			// The recording speed of the samples
	int   frag_size;		// The fragment size

	float volume;			// Current volume of playing samples

	/* Some channels and the sound data to play */
	struct Channel {
		int   position;		// Offset into current sample
		int   in_use;		// Is this channel in use?
		Sample *sample;		// Current sample on this channel
		} channels[NUM_CHANNELS];

	unsigned char *clipped;		// Sound data to play
	unsigned char *silence;		// Just plain silence

	int unclipped;			// Unclipped raw data 
};
