rnd-20020513-1-src
[rocksndiamonds.git] / src / libgame / sound.h
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1994-2001 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * sound.h                                                  *
12 ***********************************************************/
13
14 #ifndef SOUND_H
15 #define SOUND_H
16
17 #include "platform.h"
18
19
20 #if defined(PLATFORM_UNIX) && !defined(TARGET_SDL)
21 #define AUDIO_UNIX_NATIVE
22 #endif
23
24 #if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD) || defined(VOXWARE)
25 #define AUDIO_LINUX_IOCTL
26 #endif
27
28 #if defined(AUDIO_LINUX_IOCTL) || defined(PLATFORM_NETBSD)
29 #define AUDIO_STREAMING_DSP
30 #endif
31
32 /* values for platform specific sound initialization */
33 #define AUDIO_SAMPLE_RATE_8000          8000
34 #define AUDIO_SAMPLE_RATE_22050         22050
35
36 #define AUDIO_FRAGMENT_SIZE_512         512
37 #define AUDIO_FRAGMENT_SIZE_1024        1024
38 #define AUDIO_FRAGMENT_SIZE_2048        2048
39 #define AUDIO_FRAGMENT_SIZE_4096        4096
40
41 #define AUDIO_NUM_CHANNELS_MONO         1
42 #define AUDIO_NUM_CHANNELS_STEREO       2
43
44 #define AUDIO_FORMAT_UNKNOWN            (0)
45 #define AUDIO_FORMAT_U8                 (1 << 0)
46 #define AUDIO_FORMAT_S16                (1 << 1)
47 #define AUDIO_FORMAT_LE                 (1 << 2)
48 #define AUDIO_FORMAT_BE                 (1 << 3)
49
50 #if defined(AUDIO_UNIX_NATIVE) && !defined(AUDIO_STREAMING_DSP)
51 #define DEFAULT_AUDIO_SAMPLE_RATE       AUDIO_SAMPLE_RATE_8000
52 #else
53 #define DEFAULT_AUDIO_SAMPLE_RATE       AUDIO_SAMPLE_RATE_22050
54 #endif
55
56 #if defined(PLATFORM_WIN32)
57 #define DEFAULT_AUDIO_FRAGMENT_SIZE     AUDIO_FRAGMENT_SIZE_2048
58 #else
59 #define DEFAULT_AUDIO_FRAGMENT_SIZE     AUDIO_FRAGMENT_SIZE_512
60 #endif
61
62 #if defined(TARGET_SDL)
63 #define NUM_MIXER_CHANNELS              MIX_CHANNELS
64 #else
65 #define NUM_MIXER_CHANNELS              8
66 #endif
67
68 #define MUSIC_CHANNEL                   0
69 #define FIRST_SOUND_CHANNEL             1
70
71
72 /* values for PlaySound(), StopSound() and friends */
73 #define SND_CTRL_NONE           (0)
74 #define SND_CTRL_MUSIC          (1 << 0)
75 #define SND_CTRL_LOOP           (1 << 1)
76 #define SND_CTRL_FADE           (1 << 2)
77 #define SND_CTRL_STOP           (1 << 3)
78 #define SND_CTRL_ALL_SOUNDS     (1 << 4)
79 #define SND_CTRL_RELOAD_SOUNDS  (1 << 5)
80 #define SND_CTRL_RELOAD_MUSIC   (1 << 6)
81
82 #define SND_CTRL_PLAY_SOUND     (SND_CTRL_NONE)
83 #define SND_CTRL_PLAY_LOOP      (SND_CTRL_LOOP)
84 #define SND_CTRL_PLAY_MUSIC     (SND_CTRL_LOOP | SND_CTRL_MUSIC)
85
86 #define SND_CTRL_FADE_SOUND     (SND_CTRL_FADE)
87 #define SND_CTRL_FADE_MUSIC     (SND_CTRL_FADE | SND_CTRL_MUSIC)
88 #define SND_CTRL_FADE_ALL       (SND_CTRL_FADE | SND_CTRL_ALL_SOUNDS)
89
90 #define SND_CTRL_STOP_SOUND     (SND_CTRL_STOP)
91 #define SND_CTRL_STOP_MUSIC     (SND_CTRL_STOP | SND_CTRL_MUSIC)
92 #define SND_CTRL_STOP_ALL       (SND_CTRL_STOP | SND_CTRL_ALL_SOUNDS)
93
94 #define IS_MUSIC(x)             ((x).state & SND_CTRL_MUSIC)
95 #define IS_LOOP(x)              ((x).state & SND_CTRL_LOOP)
96 #define IS_FADING(x)            ((x).state & SND_CTRL_FADE)
97 #define IS_STOPPING(x)          ((x).state & SND_CTRL_STOP)
98 #define IS_RELOADING(x)         ((x).state & (SND_CTRL_RELOAD_SOUNDS | \
99                                               SND_CTRL_RELOAD_MUSIC))
100 #define ALL_SOUNDS(x)           ((x).state & SND_CTRL_ALL_SOUNDS)
101
102
103 #if !defined(TARGET_ALLEGRO)
104
105 #define PSND_SILENCE            0
106 #define PSND_MAX_VOLUME_BITS    15
107 #define PSND_MIN_VOLUME         0
108 #define PSND_MAX_VOLUME         (1 << PSND_MAX_VOLUME_BITS)
109 #define PSND_MIDDLE             0
110 #define PSND_MAX_STEREO_BITS    7
111 #define PSND_MAX_STEREO         (1 << PSND_MAX_STEREO_BITS)
112 #define PSND_MAX_LEFT           (-PSND_MAX_STEREO)
113 #define PSND_MAX_RIGHT          (+PSND_MAX_STEREO)
114 #define PSND_MAX_LEFT2RIGHT_BITS (PSND_MAX_STEREO_BITS+1)
115 #define PSND_MAX_LEFT2RIGHT     (1 << PSND_MAX_LEFT2RIGHT_BITS)
116
117 #else   /* TARGET_ALLEGRO */
118
119 #define PSND_SILENCE            0
120 #define PSND_MIN_VOLUME         0
121 #define PSND_MAX_VOLUME         255
122 #define PSND_MAX_LEFT           0
123 #define PSND_MAX_RIGHT          255
124 #define PSND_MIDDLE             128
125
126 #endif
127
128 /* value for undefined sound effect filename */
129 #define SND_FILE_UNDEFINED      "NONE"
130
131
132 struct SoundEffectInfo
133 {
134   char *text;
135   char *default_filename;
136   char *filename;
137 };
138
139
140 /* general sound functions */
141 void UnixOpenAudio(void);
142 void UnixCloseAudio(void);
143
144 /* mixer functions */ 
145 void Mixer_InitChannels(void);
146 void StartMixer(void);
147
148 /* sound client functions */
149 void PlayMusic(int);
150 void PlaySound(int);
151 void PlaySoundStereo(int, int);
152 void PlaySoundLoop(int);
153 void PlaySoundMusic(int);
154 void PlaySoundExt(int, int, int, int);
155 void FadeMusic(void);
156 void FadeSound(int);
157 void FadeSounds(void);
158 void StopMusic(void);
159 void StopSound(int);
160 void StopSounds(void);
161 void StopSoundExt(int, int);
162 void InitSoundList(struct SoundEffectInfo *, int);
163 void InitReloadSounds(char *);
164 void InitReloadMusic(char *);
165 void FreeAllSounds(void);
166 void FreeAllMusic(void);
167
168 #endif