rnd-20100313-1-src
[rocksndiamonds.git] / src / libgame / sound.h
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1994-2006 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 "system.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 #define AUDIO_FRAGMENT_SIZE_32768       32768
41
42 #define AUDIO_NUM_CHANNELS_MONO         1
43 #define AUDIO_NUM_CHANNELS_STEREO       2
44
45 #define AUDIO_FORMAT_UNKNOWN            (0)
46 #define AUDIO_FORMAT_U8                 (1 << 0)
47 #define AUDIO_FORMAT_S16                (1 << 1)
48 #define AUDIO_FORMAT_LE                 (1 << 2)
49 #define AUDIO_FORMAT_BE                 (1 << 3)
50
51 #if defined(AUDIO_UNIX_NATIVE) && !defined(AUDIO_STREAMING_DSP)
52 #define DEFAULT_AUDIO_SAMPLE_RATE       AUDIO_SAMPLE_RATE_8000
53 #else
54 #define DEFAULT_AUDIO_SAMPLE_RATE       AUDIO_SAMPLE_RATE_22050
55 #endif
56
57 #if defined(PLATFORM_HPUX)
58 #define DEFAULT_AUDIO_FRAGMENT_SIZE     AUDIO_FRAGMENT_SIZE_32768
59 #elif defined(PLATFORM_WIN32)
60 #define DEFAULT_AUDIO_FRAGMENT_SIZE     AUDIO_FRAGMENT_SIZE_1024
61 #else
62 #define DEFAULT_AUDIO_FRAGMENT_SIZE     AUDIO_FRAGMENT_SIZE_512
63 #endif
64
65 #if defined(TARGET_SDL)
66 #define NUM_MIXER_CHANNELS              MIX_CHANNELS
67 #else
68 #define NUM_MIXER_CHANNELS              8
69 #endif
70
71 #define MUSIC_CHANNEL                   0
72 #define FIRST_SOUND_CHANNEL             1
73
74
75 /* values for PlaySound(), StopSound() and friends */
76 #define SND_CTRL_NONE                   (0)
77 #define SND_CTRL_MUSIC                  (1 << 0)
78 #define SND_CTRL_LOOP                   (1 << 1)
79 #define SND_CTRL_FADE                   (1 << 2)
80 #define SND_CTRL_STOP                   (1 << 3)
81 #define SND_CTRL_ALL_SOUNDS             (1 << 4)
82 #define SND_CTRL_RELOAD_SOUNDS          (1 << 5)
83 #define SND_CTRL_RELOAD_MUSIC           (1 << 6)
84
85 #define SND_CTRL_PLAY_SOUND             (SND_CTRL_NONE)
86 #define SND_CTRL_PLAY_LOOP              (SND_CTRL_LOOP)
87 #define SND_CTRL_PLAY_MUSIC             (SND_CTRL_LOOP | SND_CTRL_MUSIC)
88
89 #define SND_CTRL_FADE_SOUND             (SND_CTRL_FADE)
90 #define SND_CTRL_FADE_MUSIC             (SND_CTRL_FADE | SND_CTRL_MUSIC)
91 #define SND_CTRL_FADE_ALL               (SND_CTRL_FADE | SND_CTRL_ALL_SOUNDS)
92
93 #define SND_CTRL_STOP_SOUND             (SND_CTRL_STOP)
94 #define SND_CTRL_STOP_MUSIC             (SND_CTRL_STOP | SND_CTRL_MUSIC)
95 #define SND_CTRL_STOP_ALL               (SND_CTRL_STOP | SND_CTRL_ALL_SOUNDS)
96
97 #define IS_MUSIC(x)                     ((x).state & SND_CTRL_MUSIC)
98 #define IS_LOOP(x)                      ((x).state & SND_CTRL_LOOP)
99 #define IS_FADING(x)                    ((x).state & SND_CTRL_FADE)
100 #define IS_STOPPING(x)                  ((x).state & SND_CTRL_STOP)
101 #define IS_RELOADING(x)                 ((x).state & (SND_CTRL_RELOAD_SOUNDS |\
102                                                       SND_CTRL_RELOAD_MUSIC))
103 #define ALL_SOUNDS(x)                   ((x).state & SND_CTRL_ALL_SOUNDS)
104
105 #define MAP_NOCONF_MUSIC(x)             (-((x) + 1))
106 #define UNMAP_NOCONF_MUSIC(x)           MAP_NOCONF_MUSIC(x)
107
108
109 #define SOUND_MIN_VOLUME                0
110 #if defined(TARGET_SDL)
111 #define SOUND_MAX_VOLUME                SDL_MIX_MAXVOLUME
112 #elif defined(TARGET_ALLEGRO)
113 #define SOUND_MAX_VOLUME                255
114 #else
115 #define SOUND_MAX_VOLUME                128
116 #endif
117
118 #define SOUND_MAX_LEFT                  0
119 #define SOUND_MAX_RIGHT                 255
120 #define SOUND_MAX_LEFT2RIGHT            255
121 #define SOUND_MIDDLE                    (SOUND_MAX_LEFT2RIGHT / 2)
122
123
124 /* general sound functions */
125 void UnixOpenAudio(void);
126 void UnixCloseAudio(void);
127
128 /* mixer functions */ 
129 void Mixer_InitChannels(void);
130 void StartMixer(void);
131
132 /* sound client functions */
133 void PlayMusic(int);
134 void PlaySound(int);
135 void PlaySoundStereo(int, int);
136 void PlaySoundLoop(int);
137 void PlaySoundMusic(int);
138 void PlaySoundExt(int, int, int, int);
139 void FadeMusic(void);
140 void FadeSound(int);
141 void FadeSounds(void);
142 void FadeSoundsAndMusic(void);
143 void StopMusic(void);
144 void StopSound(int);
145 void StopSounds(void);
146 void StopSoundExt(int, int);
147
148 int getSoundListSize();
149 int getMusicListSize();
150 struct FileInfo *getSoundListEntry(int);
151 struct FileInfo *getMusicListEntry(int);
152 int getSoundListPropertyMappingSize();
153 int getMusicListPropertyMappingSize();
154 struct PropertyMapping *getSoundListPropertyMapping();
155 struct PropertyMapping *getMusicListPropertyMapping();
156 void InitSoundList(struct ConfigInfo *, int, struct ConfigTypeInfo *,
157                    char **, char **, char **, char **, char **);
158 void InitMusicList(struct ConfigInfo *, int, struct ConfigTypeInfo *,
159                    char **, char **, char **, char **, char **);
160 void InitReloadCustomSounds(char *);
161 void InitReloadCustomMusic(char *);
162 void FreeAllSounds(void);
163 void FreeAllMusic(void);
164
165 #endif