rnd-20000718-1-src
[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
26 #if 0
27 /* where is the right declaration for 'ioctl'? */
28 extern void ioctl(long, long, void *);
29 #else
30 #include <sys/ioctl.h>
31 #endif
32
33 #endif
34
35 #ifdef __FreeBSD__
36 #include <machine/soundcard.h>
37 #endif
38
39 #define SND_BLOCKSIZE 4096
40
41 #ifdef _HPUX_SOURCE
42 #include <sys/audio.h>
43 #undef  SND_BLOCKSIZE
44 #define SND_BLOCKSIZE 32768
45 #define HPUX_AUDIO
46 #endif /* _HPUX_SOURCE */
47
48 #ifndef MSDOS
49 #define MAX_SOUNDS_PLAYING      16
50 #else
51 #define MAX_SOUNDS_PLAYING      8
52 #endif
53
54 /* some values for PlaySound(), StopSound() and friends */
55 #ifndef MSDOS
56 #define PSND_SILENCE            0
57 #define PSND_MAX_VOLUME_BITS    7
58 #define PSND_MIN_VOLUME         0
59 #define PSND_MAX_VOLUME         (1 << PSND_MAX_VOLUME_BITS)
60 #define PSND_NO_LOOP            0
61 #define PSND_LOOP               1
62 #define PSND_MIDDLE             0
63 #define PSND_MAX_STEREO_BITS    7
64 #define PSND_MAX_STEREO         (1 << PSND_MAX_STEREO_BITS)
65 #define PSND_MAX_LEFT           (-PSND_MAX_STEREO)
66 #define PSND_MAX_RIGHT          (+PSND_MAX_STEREO)
67 #define PSND_MAX_LEFT2RIGHT_BITS (PSND_MAX_STEREO_BITS+1)
68 #define PSND_MAX_LEFT2RIGHT     (1 << PSND_MAX_LEFT2RIGHT_BITS)
69 #else
70 #define PSND_SILENCE            0
71 #define PSND_MIN_VOLUME         0
72 #define PSND_MAX_VOLUME         255
73 #define PSND_NO_LOOP            0
74 #define PSND_LOOP               1
75 #define PSND_MAX_LEFT           0
76 #define PSND_MAX_RIGHT          255
77 #define PSND_MIDDLE             128
78 #endif
79
80 #define SSND_FADE_SOUND         (1<<0)
81 #define SSND_FADE_ALL_SOUNDS    (1<<1)
82 #define SSND_FADING(x)          (x & (SSND_FADE_SOUND | SSND_FADE_ALL_SOUNDS))
83 #define SSND_STOP_SOUND         (1<<2)
84 #define SSND_STOP_ALL_SOUNDS    (1<<3)
85 #define SSND_STOPPING(x)        (x & (SSND_STOP_SOUND | SSND_STOP_ALL_SOUNDS))
86 #define SSND_ALL(x)             (x&(SSND_FADE_ALL_SOUNDS|SSND_STOP_ALL_SOUNDS))
87
88 /* settings for sound path, sound device, etc. */
89 #ifndef SND_PATH
90 #define SND_PATH        "./sounds"
91 #endif
92
93 #define DEV_AUDIO       "/dev/audio"
94 #define DEV_DSP         "/dev/dsp"
95
96 #ifdef  VOXWARE
97 #define SOUND_DEVICE    DEV_DSP
98 #else
99 #define SOUND_DEVICE    DEV_AUDIO
100 #endif
101
102 #define SOUND_OFF       0
103 #define SOUND_AVAILABLE 1
104
105 #ifdef NO_SOUNDS
106 #define SOUND_STATUS    SOUND_OFF
107 #else
108 #define SOUND_STATUS    SOUND_AVAILABLE
109 #endif
110
111 struct SoundHeader_SUN
112 {
113   unsigned long magic;
114   unsigned long hdr_size;
115   unsigned long data_size;
116   unsigned long encoding;
117   unsigned long sample_rate;
118   unsigned long channels;
119 };
120
121 struct SoundHeader_8SVX
122 {
123   char magic_FORM[4];
124   unsigned long chunk_size;
125   char magic_8SVX[4];
126 };
127
128 struct SoundInfo
129
130   char *name;
131   byte *data_ptr;
132   long data_len;
133 #ifdef MSDOS
134   SAMPLE *sample_ptr;
135 #endif
136 };
137
138 struct SoundControl
139 {
140   int nr;
141   int volume;
142   int stereo;
143   boolean active;
144   boolean loop;
145   boolean fade_sound;
146   boolean stop_sound;
147   boolean stop_all_sounds;
148   int playingtime;
149   long playingpos;
150   long data_len;
151   byte *data_ptr;
152 #ifdef MSDOS
153   int voice;
154 #endif
155 };
156
157 /* start sound server */
158 void SoundServer(void);
159
160 /* client functions */
161 boolean LoadSound(struct SoundInfo *);
162 void PlaySound(int);
163 void PlaySoundStereo(int, int);
164 void PlaySoundLoop(int);
165 void PlaySoundExt(int, int, int, boolean);
166 void FadeSound(int);
167 void FadeSounds(void);
168 void StopSound(int);
169 void StopSounds(void);
170 void StopSoundExt(int, int);
171 void FreeSounds(int);
172
173 #endif