rnd-20001201-1-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 <sys/ioctl.h>
18 #include <math.h>
19
20 #define SND_BLOCKSIZE 4096
21
22 #if defined(PLATFORM_LINUX)
23 #include <linux/soundcard.h>
24 #elif defined(PLATFORM_FREEBSD)
25 #include <machine/soundcard.h>
26 #elif defined(PLATFORM_HPUX)
27 #include <sys/audio.h>
28 #undef  SND_BLOCKSIZE
29 #define SND_BLOCKSIZE 32768
30 #endif
31
32 #include "libgame.h"
33
34 #if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD) || defined(VOXWARE)
35 #define AUDIO_STREAMING_DSP
36 #endif
37
38 #if !defined(PLATFORM_MSDOS)
39 #define MAX_SOUNDS_PLAYING      16
40 #else
41 #define MAX_SOUNDS_PLAYING      8
42 #endif
43
44 /* some values for PlaySound(), StopSound() and friends */
45 #if !defined(PLATFORM_MSDOS)
46 #define PSND_SILENCE            0
47 #define PSND_MAX_VOLUME_BITS    7
48 #define PSND_MIN_VOLUME         0
49 #define PSND_MAX_VOLUME         (1 << PSND_MAX_VOLUME_BITS)
50 #define PSND_NO_LOOP            0
51 #define PSND_LOOP               1
52 #define PSND_MIDDLE             0
53 #define PSND_MAX_STEREO_BITS    7
54 #define PSND_MAX_STEREO         (1 << PSND_MAX_STEREO_BITS)
55 #define PSND_MAX_LEFT           (-PSND_MAX_STEREO)
56 #define PSND_MAX_RIGHT          (+PSND_MAX_STEREO)
57 #define PSND_MAX_LEFT2RIGHT_BITS (PSND_MAX_STEREO_BITS+1)
58 #define PSND_MAX_LEFT2RIGHT     (1 << PSND_MAX_LEFT2RIGHT_BITS)
59 #else
60 #define PSND_SILENCE            0
61 #define PSND_MIN_VOLUME         0
62 #define PSND_MAX_VOLUME         255
63 #define PSND_NO_LOOP            0
64 #define PSND_LOOP               1
65 #define PSND_MAX_LEFT           0
66 #define PSND_MAX_RIGHT          255
67 #define PSND_MIDDLE             128
68 #endif
69
70 #define SSND_FADE_SOUND         (1<<0)
71 #define SSND_FADE_ALL_SOUNDS    (1<<1)
72 #define SSND_FADING(x)          (x & (SSND_FADE_SOUND | SSND_FADE_ALL_SOUNDS))
73 #define SSND_STOP_SOUND         (1<<2)
74 #define SSND_STOP_ALL_SOUNDS    (1<<3)
75 #define SSND_STOPPING(x)        (x & (SSND_STOP_SOUND | SSND_STOP_ALL_SOUNDS))
76 #define SSND_ALL(x)             (x&(SSND_FADE_ALL_SOUNDS|SSND_STOP_ALL_SOUNDS))
77
78 /* settings for sound path, sound device, etc. */
79 #ifndef SND_PATH
80 #define SND_PATH        "./sounds"
81 #endif
82
83 #define DEVICENAME_DSP          "/dev/dsp"
84 #define DEVICENAME_AUDIO        "/dev/audio"
85 #define DEVICENAME_AUDIOCTL     "/dev/audioCtl"
86
87 #if 0
88 #if defined(AUDIO_STREAMING_DSP)
89 #define AUDIO_DEVICE    DEVICENAME_DSP
90 #else
91 #define AUDIO_DEVICE    DEVICENAME_AUDIO
92 #endif
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