rnd-19981114-1
[rocksndiamonds.git] / src / sound.h
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  (c) 1995-98 Artsoft Entertainment                       *
5 *              Holger Schemel                              *
6 *              Oststrasse 11a                              *
7 *              33604 Bielefeld                             *
8 *              phone: ++49 +521 290471                     *
9 *              email: aeglos@valinor.owl.de                *
10 *----------------------------------------------------------*
11 *  sound.c                                                 *
12 ***********************************************************/
13
14 #ifndef SOUND_H
15 #define SOUND_H
16
17 #include <math.h>
18 #include "main.h"
19
20 #ifdef linux
21 #include <linux/soundcard.h>
22 #ifndef VOXWARE
23 #define VOXWARE
24 #endif
25 /* where is the right declaration for 'ioctl'? */
26 extern void ioctl(long, long, void *);
27 #endif
28
29 #ifdef __FreeBSD__
30 #include <machine/soundcard.h>
31 #endif
32
33 #define SND_BLOCKSIZE 4096
34
35 #ifdef _HPUX_SOURCE
36 #include <sys/audio.h>
37 #undef  SND_BLOCKSIZE
38 #define SND_BLOCKSIZE 32768
39 #define HPUX_AUDIO
40 #endif /* _HPUX_SOURCE */
41
42 #ifndef MSDOS
43 #define MAX_SOUNDS_PLAYING      16
44 #else
45 #define MAX_SOUNDS_PLAYING      8
46 #endif
47
48 /* some values for PlaySound(), StopSound() and friends */
49 #ifndef MSDOS
50 #define PSND_SILENCE            0
51 #define PSND_MAX_VOLUME_BITS    7
52 #define PSND_MIN_VOLUME         0
53 #define PSND_MAX_VOLUME         (1 << PSND_MAX_VOLUME_BITS)
54 #define PSND_NO_LOOP            0
55 #define PSND_LOOP               1
56 #define PSND_MIDDLE             0
57 #define PSND_MAX_STEREO_BITS    7
58 #define PSND_MAX_STEREO         (1 << PSND_MAX_STEREO_BITS)
59 #define PSND_MAX_LEFT           (-PSND_MAX_STEREO)
60 #define PSND_MAX_RIGHT          (+PSND_MAX_STEREO)
61 #define PSND_MAX_LEFT2RIGHT_BITS (PSND_MAX_STEREO_BITS+1)
62 #define PSND_MAX_LEFT2RIGHT     (1 << PSND_MAX_LEFT2RIGHT_BITS)
63 #else
64 #define PSND_SILENCE            0
65 #define PSND_MIN_VOLUME         0
66 #define PSND_MAX_VOLUME         255
67 #define PSND_NO_LOOP            0
68 #define PSND_LOOP               1
69 #define PSND_MAX_LEFT           0
70 #define PSND_MAX_RIGHT          255
71 #define PSND_MIDDLE             128
72 #endif
73
74 #define SSND_FADE_SOUND         (1<<0)
75 #define SSND_FADE_ALL_SOUNDS    (1<<1)
76 #define SSND_FADING(x)          (x & (SSND_FADE_SOUND | SSND_FADE_ALL_SOUNDS))
77 #define SSND_STOP_SOUND         (1<<2)
78 #define SSND_STOP_ALL_SOUNDS    (1<<3)
79 #define SSND_STOPPING(x)        (x & (SSND_STOP_SOUND | SSND_STOP_ALL_SOUNDS))
80 #define SSND_ALL(x)             (x&(SSND_FADE_ALL_SOUNDS|SSND_STOP_ALL_SOUNDS))
81
82 #define TRUE    1
83 #define FALSE   0
84
85 /* settings for sound path, sound device, etc. */
86 #ifndef SND_PATH
87 #define SND_PATH        "./sounds"
88 #endif
89
90 #define DEV_AUDIO       "/dev/audio"
91 #define DEV_DSP         "/dev/dsp"
92
93 #ifdef  VOXWARE
94 #define SOUND_DEVICE    DEV_DSP
95 #else
96 #define SOUND_DEVICE    DEV_AUDIO
97 #endif
98
99 #define SOUND_OFF       0
100 #define SOUND_AVAILABLE 1
101
102 #ifdef NO_SOUNDS
103 #define SOUND_STATUS    SOUND_OFF
104 #else
105 #define SOUND_STATUS    SOUND_AVAILABLE
106 #endif
107
108 struct SoundHeader_SUN
109 {
110   unsigned long magic;
111   unsigned long hdr_size;
112   unsigned long data_size;
113   unsigned long encoding;
114   unsigned long sample_rate;
115   unsigned long channels;
116 };
117
118 struct SoundHeader_8SVX
119 {
120   char magic_FORM[4];
121   unsigned long chunk_size;
122   char magic_8SVX[4];
123 };
124
125 struct SoundHeader_WAV
126 {
127   char magic_RIFF[4];
128   unsigned long header_size;
129   char magic_WAVE[4];
130   char some_stuff[24];
131   char magic_DATA[4];
132   unsigned long data_size;
133 };
134
135 struct SoundInfo
136
137   unsigned char *name;
138   unsigned char *file_ptr;
139   char *data_ptr;
140   long file_len, data_len;
141 #ifdef MSDOS
142   SAMPLE *sample_ptr;
143 #endif
144 };
145
146 struct SoundControl
147 {
148   int nr;
149   int volume;
150   int stereo;
151   boolean active;
152   boolean loop;
153   boolean fade_sound;
154   boolean stop_sound;
155   boolean stop_all_sounds;
156   int playingtime;
157   long playingpos;
158   long data_len;
159   char *data_ptr;
160 #ifdef MSDOS
161   int voice;
162 #endif
163 };
164
165 /* sound server functions */
166 void SoundServer(void);
167 void SoundServer_InsertNewSound(struct SoundControl);
168 void SoundServer_StopSound(int);
169 void SoundServer_StopAllSounds(void);
170 void HPUX_Audio_Control(void);
171 unsigned char linear_to_ulaw(int);
172 int ulaw_to_linear(unsigned char);
173
174 /* application functions */
175 boolean LoadSound(struct SoundInfo *);
176 void PlaySound(int);
177 void PlaySoundStereo(int, int);
178 void PlaySoundLoop(int);
179 void PlaySoundExt(int, int, int, boolean);
180 void FadeSound(int);
181 void FadeSounds(void);
182 void StopSound(int);
183 void StopSounds(void);
184 void StopSoundExt(int, int);
185 void FreeSounds(int);
186
187 #endif