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