1 /***********************************************************
2 * Artsoft Retro-Game Library *
3 *----------------------------------------------------------*
4 * (c) 1994-2001 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
21 #if defined(PLATFORM_LINUX)
22 #include <sys/ioctl.h>
25 #if defined(PLATFORM_LINUX)
26 #include <linux/soundcard.h>
27 #elif defined(PLATFORM_FREEBSD)
28 #include <machine/soundcard.h>
29 #elif defined(PLATFORM_NETBSD)
30 #include <sys/ioctl.h>
31 #include <sys/audioio.h>
32 #elif defined(PLATFORM_HPUX)
33 #include <sys/audio.h>
39 #if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD) || defined(VOXWARE)
40 #define AUDIO_LINUX_IOCTL
43 #if defined(AUDIO_LINUX_IOCTL) || defined(PLATFORM_NETBSD)
44 #define AUDIO_STREAMING_DSP
47 #define AUDIO_SAMPLE_RATE_8000 8000
48 #define AUDIO_SAMPLE_RATE_22050 22050
50 #define AUDIO_FRAGMENT_SIZE_512 512
51 #define AUDIO_FRAGMENT_SIZE_1024 1024
52 #define AUDIO_FRAGMENT_SIZE_2048 2048
53 #define AUDIO_FRAGMENT_SIZE_4096 4096
55 #define AUDIO_NUM_CHANNELS_MONO 1
56 #define AUDIO_NUM_CHANNELS_STEREO 2
58 #define AUDIO_FORMAT_UNKNOWN (0)
59 #define AUDIO_FORMAT_U8 (1 << 0)
60 #define AUDIO_FORMAT_S16 (1 << 1)
61 #define AUDIO_FORMAT_LE (1 << 2)
62 #define AUDIO_FORMAT_BE (1 << 3)
64 #if defined(TARGET_SDL)
65 /* one second fading interval == 1000 ticks (milliseconds) */
66 #define SOUND_FADING_INTERVAL 1000
67 #define SOUND_MAX_VOLUME SDL_MIX_MAXVOLUME
70 #if defined(AUDIO_STREAMING_DSP)
71 #define SOUND_FADING_VOLUME_STEP (PSND_MAX_VOLUME / 40)
72 #define SOUND_FADING_VOLUME_THRESHOLD (SOUND_FADING_VOLUME_STEP * 2)
75 #if defined(AUDIO_STREAMING_DSP)
76 #define DEFAULT_AUDIO_SAMPLE_RATE AUDIO_SAMPLE_RATE_22050
78 #define DEFAULT_AUDIO_SAMPLE_RATE AUDIO_SAMPLE_RATE_8000
81 #define DEFAULT_AUDIO_FRAGMENT_SIZE_UNIX AUDIO_FRAGMENT_SIZE_512
82 #define DEFAULT_AUDIO_FRAGMENT_SIZE_WIN32 AUDIO_FRAGMENT_SIZE_2048
84 #if defined(PLATFORM_UNIX)
85 #define DEFAULT_AUDIO_FRAGMENT_SIZE DEFAULT_AUDIO_FRAGMENT_SIZE_UNIX
87 #define DEFAULT_AUDIO_FRAGMENT_SIZE DEFAULT_AUDIO_FRAGMENT_SIZE_WIN32
90 #if defined(TARGET_SDL)
91 #define NUM_MIXER_CHANNELS MIX_CHANNELS
93 #define NUM_MIXER_CHANNELS 8
96 #define MUSIC_CHANNEL 0
97 #define FIRST_SOUND_CHANNEL 1
99 #if !defined(PLATFORM_HPUX)
100 #define SND_BLOCKSIZE 4096
102 #define SND_BLOCKSIZE 32768
105 /* some values for PlaySound(), StopSound() and friends */
106 #if !defined(PLATFORM_MSDOS)
108 #define PSND_SILENCE 0
109 #define PSND_MAX_VOLUME_BITS 15
110 #define PSND_MIN_VOLUME 0
111 #define PSND_MAX_VOLUME (1 << PSND_MAX_VOLUME_BITS)
112 #define PSND_MIDDLE 0
113 #define PSND_MAX_STEREO_BITS 7
114 #define PSND_MAX_STEREO (1 << PSND_MAX_STEREO_BITS)
115 #define PSND_MAX_LEFT (-PSND_MAX_STEREO)
116 #define PSND_MAX_RIGHT (+PSND_MAX_STEREO)
117 #define PSND_MAX_LEFT2RIGHT_BITS (PSND_MAX_STEREO_BITS+1)
118 #define PSND_MAX_LEFT2RIGHT (1 << PSND_MAX_LEFT2RIGHT_BITS)
120 #else /* PLATFORM_MSDOS */
122 #define PSND_SILENCE 0
123 #define PSND_MIN_VOLUME 0
124 #define PSND_MAX_VOLUME 255
125 #define PSND_MAX_LEFT 0
126 #define PSND_MAX_RIGHT 255
127 #define PSND_MIDDLE 128
132 #define PSND_NO_LOOP 0
136 #define SSND_FADE_SOUND (1 << 0)
137 #define SSND_FADE_MUSIC (1 << 1)
138 #define SSND_FADE_ALL (1 << 2)
139 #define SSND_FADING (SSND_FADE_SOUND | \
142 #define SSND_STOP_SOUND (1 << 3)
143 #define SSND_STOP_MUSIC (1 << 4)
144 #define SSND_STOP_ALL (1 << 5)
145 #define SSND_STOPPING (SSND_STOP_SOUND | \
148 #define SSND_MUSIC (SSND_FADE_MUSIC | SSND_STOP_MUSIC)
149 #define SSND_ALL (SSND_FADE_ALL | SSND_STOP_ALL)
151 #define SND_RELOAD_SOUNDS 1
152 #define SND_RELOAD_MUSIC 2
155 #define SND_TYPE_NONE 0
156 #define SND_TYPE_WAV 1
158 #define MUS_TYPE_NONE 0
159 #define MUS_TYPE_WAV 1
160 #define MUS_TYPE_MOD 2
162 /* settings for sound path, sound device, etc. */
164 #define SND_PATH "./sounds"
167 #define DEVICENAME_DSP "/dev/dsp"
168 #define DEVICENAME_AUDIO "/dev/audio"
169 #define DEVICENAME_AUDIOCTL "/dev/audioCtl"
172 #if defined(AUDIO_STREAMING_DSP)
173 #define AUDIO_DEVICE DEVICENAME_DSP
175 #define AUDIO_DEVICE DEVICENAME_AUDIO
179 /* value for undefined sound effect filename */
180 #define SND_FILE_UNDEFINED "NONE"
184 struct SoundHeader_SUN
187 unsigned long hdr_size;
188 unsigned long data_size;
189 unsigned long encoding;
190 unsigned long sample_rate;
191 unsigned long channels;
194 struct SoundHeader_8SVX
197 unsigned long chunk_size;
202 struct AudioFormatInfo
204 boolean stereo; /* availability of stereo sound */
205 int format; /* size and endianess of sample data */
206 int sample_rate; /* sample frequency */
207 int fragment_size; /* audio device fragment size in bytes */
210 struct SoundEffectInfo
213 char *default_filename;
220 char *source_filename;
228 typedef struct SampleInfo SoundInfo;
229 typedef struct SampleInfo MusicInfo;
231 #define SND_CTRL_NONE (0)
232 #define SND_CTRL_MUSIC (1 << 0)
233 #define SND_CTRL_LOOP (1 << 1)
234 #define SND_CTRL_FADE (1 << 2)
235 #define SND_CTRL_STOP (1 << 3)
236 #define SND_CTRL_ALL_SOUNDS (1 << 4)
237 #define SND_CTRL_RELOAD_SOUNDS (1 << 5)
238 #define SND_CTRL_RELOAD_MUSIC (1 << 6)
240 #define SND_CTRL_PLAY_SOUND (SND_CTRL_NONE)
241 #define SND_CTRL_PLAY_LOOP (SND_CTRL_LOOP)
242 #define SND_CTRL_PLAY_MUSIC (SND_CTRL_LOOP | SND_CTRL_MUSIC)
244 #define SND_CTRL_FADE_SOUND (SND_CTRL_FADE)
245 #define SND_CTRL_FADE_MUSIC (SND_CTRL_FADE | SND_CTRL_MUSIC)
246 #define SND_CTRL_FADE_ALL (SND_CTRL_FADE | SND_CTRL_ALL_SOUNDS)
248 #define SND_CTRL_STOP_SOUND (SND_CTRL_STOP)
249 #define SND_CTRL_STOP_MUSIC (SND_CTRL_STOP | SND_CTRL_MUSIC)
250 #define SND_CTRL_STOP_ALL (SND_CTRL_STOP | SND_CTRL_ALL_SOUNDS)
252 #define IS_MUSIC(x) ((x).state & SND_CTRL_MUSIC)
253 #define IS_LOOP(x) ((x).state & SND_CTRL_LOOP)
254 #define IS_FADING(x) ((x).state & SND_CTRL_FADE)
255 #define IS_STOPPING(x) ((x).state & SND_CTRL_STOP)
256 #define IS_RELOADING(x) ((x).state & (SND_CTRL_RELOAD_SOUNDS | \
257 SND_CTRL_RELOAD_MUSIC))
258 #define ALL_SOUNDS(x) ((x).state & SND_CTRL_ALL_SOUNDS)
275 boolean stop_all_sounds;
276 boolean reload_sounds;
277 boolean reload_music;
287 #if defined(PLATFORM_MSDOS)
292 /* general sound functions */
293 void UnixOpenAudio(void);
294 void UnixCloseAudio(void);
296 /* mixer functions */
297 void Mixer_InitChannels(void);
298 void StartMixer(void);
300 /* sound client functions */
303 void PlaySoundStereo(int, int);
304 void PlaySoundLoop(int);
305 void PlaySoundMusic(int);
306 void PlaySoundExt(int, int, int, int);
307 void FadeMusic(void);
309 void FadeSounds(void);
310 void StopMusic(void);
312 void StopSounds(void);
313 void StopSoundExt(int, int);
314 void InitSoundList(struct SoundEffectInfo *, int);
315 void InitReloadSounds(char *);
316 void InitReloadMusic(char *);
317 void FreeAllSounds(void);
318 void FreeAllMusic(void);