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