rnd-19980930-3
[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 SoundInfo
126
127   unsigned char *name;
128   unsigned char *file_ptr;
129   char *data_ptr;
130   long file_len, data_len;
131 #ifdef MSDOS
132   SAMPLE *sample_ptr;
133 #endif
134 };
135
136 struct SoundControl
137 {
138   int nr;
139   int volume;
140   int stereo;
141   BOOL active;
142   BOOL loop;
143   BOOL fade_sound;
144   BOOL stop_sound;
145   BOOL stop_all_sounds;
146   int playingtime;
147   long playingpos;
148   long data_len;
149   char *data_ptr;
150 #ifdef MSDOS
151   int voice;
152 #endif
153 };
154
155 /* sound server functions */
156 void SoundServer(void);
157 void SoundServer_InsertNewSound(struct SoundControl);
158 void SoundServer_StopSound(int);
159 void SoundServer_StopAllSounds(void);
160 void HPUX_Audio_Control(void);
161 unsigned char linear_to_ulaw(int);
162 int ulaw_to_linear(unsigned char);
163
164 /* application functions */
165 BOOL LoadSound(struct SoundInfo *);
166 void PlaySound(int);
167 void PlaySoundStereo(int, int);
168 void PlaySoundLoop(int);
169 void PlaySoundExt(int, int, int, BOOL);
170 void FadeSound(int);
171 void FadeSounds(void);
172 void StopSound(int);
173 void StopSounds(void);
174 void StopSoundExt(int, int);
175 void FreeSounds(int);
176
177 #endif