/*  SpiralSynth
 *  Copyleft (C) 2000 David Griffiths <dave@pawfal.org>
 *
 *  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 2 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, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ 

#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#if defined (__FreeBSD__)
	#include <machine/soundcard.h>
#else
#if defined (__NetBSD__) || defined (__OpenBSD__)
	#include <soundcard.h>            /* OSS emulation */
#undef ioctl
#else 	                              /* BSDI, Linux, Solaris */
	#include <sys/soundcard.h>
#endif                                /* __NetBSD__ or __OpenBSD__ */
#endif                                /* __FreeBSD__ */
#include <sys/ioctl.h>
#include <limits.h>

#include "SpiralInfo.h"
#include "RiffWav.h"

#ifndef SOUND_MANAGER
#define SOUND_MANAGER


inline float Linear(float bot,float top,float pos,float val1,float val2) 
{ 
    float t=(pos-bot)/(top-bot); 
    return val1*t + val2*(1.0f-t); 
} 

class Output
{
public:
	Output();
	~Output() {close(m_Dspfd); delete[] m_Buffer;}
	void Send(short *data);
	void SetVolume(float s) {m_Amp=s;}
	float GetVolume() {return m_Amp;}
	void Play();
	void ClearBuffer();
	void WavOpen(char* name) {m_Wav.Open(name,WavFile::WRITE);}
	void WavClose() {m_Wav.Close();}
	short *GetBuffer() {return m_Buffer;}
	
private:
	void Init();

	short *m_Buffer;

	int m_Dspfd;
	float m_Amp;
	WavFile m_Wav;
};

#endif
