fixed bug with playing "timeout" and "player dies" sounds in SP engine
[rocksndiamonds.git] / src / libgame / sound.h
1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
5 //                  Holger Schemel
6 //                  info@artsoft.org
7 //                  http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
9 // sound.h
10 // ============================================================================
11
12 #ifndef SOUND_H
13 #define SOUND_H
14
15 #include "system.h"
16
17
18 /* values for platform specific sound initialization */
19 #define AUDIO_SAMPLE_RATE_22050         22050
20
21 #define AUDIO_FRAGMENT_SIZE_512         512
22 #define AUDIO_FRAGMENT_SIZE_1024        1024
23 #define AUDIO_FRAGMENT_SIZE_2048        2048
24 #define AUDIO_FRAGMENT_SIZE_4096        4096
25 #define AUDIO_FRAGMENT_SIZE_32768       32768
26
27 #define AUDIO_NUM_CHANNELS_MONO         1
28 #define AUDIO_NUM_CHANNELS_STEREO       2
29
30 #define AUDIO_FORMAT_UNKNOWN            (0)
31 #define AUDIO_FORMAT_U8                 (1 << 0)
32 #define AUDIO_FORMAT_S16                (1 << 1)
33 #define AUDIO_FORMAT_LE                 (1 << 2)
34 #define AUDIO_FORMAT_BE                 (1 << 3)
35
36 #define DEFAULT_AUDIO_SAMPLE_RATE       AUDIO_SAMPLE_RATE_22050
37
38 #if defined(PLATFORM_WIN32)
39 #define DEFAULT_AUDIO_FRAGMENT_SIZE     AUDIO_FRAGMENT_SIZE_1024
40 #else
41 #define DEFAULT_AUDIO_FRAGMENT_SIZE     AUDIO_FRAGMENT_SIZE_512
42 #endif
43
44 #define NUM_MIXER_CHANNELS              MIX_CHANNELS
45
46 #define MUSIC_CHANNEL                   0
47 #define FIRST_SOUND_CHANNEL             1
48
49
50 /* values for PlaySound(), StopSound() and friends */
51 #define SND_CTRL_NONE                   (0)
52 #define SND_CTRL_MUSIC                  (1 << 0)
53 #define SND_CTRL_LOOP                   (1 << 1)
54 #define SND_CTRL_FADE                   (1 << 2)
55 #define SND_CTRL_STOP                   (1 << 3)
56 #define SND_CTRL_ALL_SOUNDS             (1 << 4)
57 #define SND_CTRL_RELOAD_SOUNDS          (1 << 5)
58 #define SND_CTRL_RELOAD_MUSIC           (1 << 6)
59 #define SND_CTRL_EXPIRE_LOOPS           (1 << 7)
60
61 #define SND_CTRL_PLAY_SOUND             (SND_CTRL_NONE)
62 #define SND_CTRL_PLAY_LOOP              (SND_CTRL_LOOP)
63 #define SND_CTRL_PLAY_MUSIC             (SND_CTRL_LOOP | SND_CTRL_MUSIC)
64
65 #define SND_CTRL_FADE_SOUND             (SND_CTRL_FADE)
66 #define SND_CTRL_FADE_MUSIC             (SND_CTRL_FADE | SND_CTRL_MUSIC)
67 #define SND_CTRL_FADE_ALL               (SND_CTRL_FADE | SND_CTRL_ALL_SOUNDS)
68
69 #define SND_CTRL_STOP_SOUND             (SND_CTRL_STOP)
70 #define SND_CTRL_STOP_MUSIC             (SND_CTRL_STOP | SND_CTRL_MUSIC)
71 #define SND_CTRL_STOP_ALL               (SND_CTRL_STOP | SND_CTRL_ALL_SOUNDS)
72
73 #define IS_MUSIC(x)                     ((x).state & SND_CTRL_MUSIC)
74 #define IS_LOOP(x)                      ((x).state & SND_CTRL_LOOP)
75 #define IS_FADING(x)                    ((x).state & SND_CTRL_FADE)
76 #define IS_STOPPING(x)                  ((x).state & SND_CTRL_STOP)
77 #define IS_RELOADING(x)                 ((x).state & (SND_CTRL_RELOAD_SOUNDS |\
78                                                       SND_CTRL_RELOAD_MUSIC))
79 #define ALL_SOUNDS(x)                   ((x).state & SND_CTRL_ALL_SOUNDS)
80 #define SET_EXPIRE_LOOPS(x)             ((x).state & SND_CTRL_EXPIRE_LOOPS)
81
82 #define MAP_NOCONF_MUSIC(x)             (-((x) + 1))
83 #define UNMAP_NOCONF_MUSIC(x)           MAP_NOCONF_MUSIC(x)
84
85
86 #define SOUND_MIN_VOLUME                0
87 #define SOUND_MAX_VOLUME                SDL_MIX_MAXVOLUME
88
89 #define SOUND_MAX_LEFT                  0
90 #define SOUND_MAX_RIGHT                 255
91 #define SOUND_MAX_LEFT2RIGHT            255
92 #define SOUND_MIDDLE                    (SOUND_MAX_LEFT2RIGHT / 2)
93
94
95 /* general sound functions */
96 void UnixOpenAudio(void);
97 void UnixCloseAudio(void);
98
99 /* mixer functions */ 
100 void Mixer_InitChannels(void);
101 void StartMixer(void);
102
103 /* sound client functions */
104 void PlayMusic(int);
105 void PlaySound(int);
106 void PlaySoundStereo(int, int);
107 void PlaySoundLoop(int);
108 void PlaySoundMusic(int);
109 void PlaySoundExt(int, int, int, int);
110 void FadeMusic(void);
111 void FadeSound(int);
112 void FadeSounds(void);
113 void FadeSoundsAndMusic(void);
114 void StopMusic(void);
115 void StopSound(int);
116 void StopSounds(void);
117 void StopSoundExt(int, int);
118 void ExpireSoundLoops(boolean);
119
120 int getSoundListSize();
121 int getMusicListSize();
122 struct FileInfo *getSoundListEntry(int);
123 struct FileInfo *getMusicListEntry(int);
124 char *getMusicInfoEntryFilename(int);
125 char *getCurrentlyPlayingMusicFilename();
126 int getSoundListPropertyMappingSize();
127 int getMusicListPropertyMappingSize();
128 struct PropertyMapping *getSoundListPropertyMapping();
129 struct PropertyMapping *getMusicListPropertyMapping();
130 void InitSoundList(struct ConfigInfo *, int, struct ConfigTypeInfo *,
131                    char **, char **, char **, char **, char **);
132 void InitMusicList(struct ConfigInfo *, int, struct ConfigTypeInfo *,
133                    char **, char **, char **, char **, char **);
134 void InitReloadCustomSounds(char *);
135 void InitReloadCustomMusic(char *);
136 void FreeAllSounds(void);
137 void FreeAllMusic(void);
138
139 #endif