rnd-20020907-1-src
[rocksndiamonds.git] / src / libgame / sound.h
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1994-2002 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
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 #define SOUND_MIN_VOLUME                0
103 #if defined(TARGET_SDL)
104 #define SOUND_MAX_VOLUME                SDL_MIX_MAXVOLUME
105 #elif defined(TARGET_ALLEGRO)
106 #define SOUND_MAX_VOLUME                255
107 #else
108 #define SOUND_MAX_VOLUME                128
109 #endif
110
111 #define SOUND_MAX_LEFT                  0
112 #define SOUND_MAX_RIGHT                 255
113 #define SOUND_MAX_LEFT2RIGHT            255
114 #define SOUND_MIDDLE                    (SOUND_MAX_LEFT2RIGHT / 2)
115
116 /* value for undefined sound effect filename */
117 #define SND_FILE_UNDEFINED              UNDEFINED_FILENAME
118
119
120 /* general sound functions */
121 void UnixOpenAudio(void);
122 void UnixCloseAudio(void);
123
124 /* mixer functions */ 
125 void Mixer_InitChannels(void);
126 void StartMixer(void);
127
128 /* sound client functions */
129 void PlayMusic(int);
130 void PlaySound(int);
131 void PlaySoundStereo(int, int);
132 void PlaySoundLoop(int);
133 void PlaySoundMusic(int);
134 void PlaySoundExt(int, int, int, int);
135 void FadeMusic(void);
136 void FadeSound(int);
137 void FadeSounds(void);
138 void StopMusic(void);
139 void StopSound(int);
140 void StopSounds(void);
141 void StopSoundExt(int, int);
142 struct FileInfo *getCurrentSoundList();
143 void InitSoundList(struct ConfigInfo *, char **, int);
144 void InitReloadSounds(char *);
145 void InitReloadMusic(char *);
146 void FreeAllSounds(void);
147 void FreeAllMusic(void);
148
149 #endif