1 /* SpiralSynth
2 * Copyleft (C) 2000 David Griffiths <dave@pawfal.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #include <sys/types.h>
20 #include <stdio.h>
21 #include <fcntl.h>
22 #include <unistd.h>
23 #if defined (__FreeBSD__)
24 #include <sys/soundcard.h>
25 #else
26 #if defined (__NetBSD__) || defined (__OpenBSD__)
27 #include <soundcard.h> /* OSS emulation */
28 #undef ioctl
29 #else /* BSDI, Linux, Solaris */
30 #include <sys/soundcard.h>
31 #endif /* __NetBSD__ or __OpenBSD__ */
32 #endif /* __FreeBSD__ */
33 #include <sys/ioctl.h>
34 #include <limits.h>
35
36 #include "SpiralInfo.h"
37 #include "RiffWav.h"
38
39 #ifndef SOUND_MANAGER
40 #define SOUND_MANAGER
41
42
43 inline float Linear(float bot,float top,float pos,float val1,float val2)
44 {
45 float t=(pos-bot)/(top-bot);
46 return val1*t + val2*(1.0f-t);
47 }
48
49 class Output
error_callback(void * vdata ATTRIBUTE_UNUSED,const char * msg ATTRIBUTE_UNUSED,int errnum ATTRIBUTE_UNUSED)50 {
51 public:
52 Output();
53 ~Output() {close(m_Dspfd); delete[] m_Buffer;}
54 void Send(short *data);
55 void SetVolume(float s) {m_Amp=s;}
56 float GetVolume() {return m_Amp;}
57 void Play();
58 void ClearBuffer();
59 void WavOpen(char* name) {m_Wav.Open(name,WavFile::WRITE);}
60 void WavClose() {m_Wav.Close();}
61 short *GetBuffer() {return m_Buffer;}
62
63 private:
64 void Init();
65
66 short *m_Buffer;
67
68 int m_Dspfd;
69 float m_Amp;
70 WavFile m_Wav;
71 };
72
73 #endif
74