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