KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
sfxmgr.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/sound/sfxmgr.h
4 Copyright (C) 2002 Megan Potter
5 Copyright (C) 2023, 2024 Ruslan Rostovtsev
6 Copyright (C) 2023 Andy Barajas
7
8*/
9
10/** \file dc/sound/sfxmgr.h
11 \brief Basic sound effect support.
12 \ingroup audio_sfx
13
14 This file contains declarations for doing simple sound effects. This code is
15 only usable for simple WAV files containing either 8-bit or 16-bit samples (stereo
16 or mono) or Yamaha ADPCM (4-bits, stereo or mono). Also, all sounds played in
17 this manner must be at most 65534 samples in length, as this does not handle
18 buffer chaining or anything else complex. For more interesting stuff, you
19 should probably look at the sound stream stuff instead.
20
21 \author Megan Potter
22 \author Ruslan Rostovtsev
23 \author Andy Barajas
24*/
25
26#ifndef __DC_SOUND_SFXMGR_H
27#define __DC_SOUND_SFXMGR_H
28
29#include <sys/cdefs.h>
30__BEGIN_DECLS
31
32#include <arch/types.h>
33#include <kos/fs.h>
34#include <stdint.h>
35
36/** \defgroup audio_sfx Sound Effects
37 \brief Sound Effect Playback and Management
38 \ingroup audio
39
40 @{
41*/
42
43/** \brief Sound effect handle type.
44
45 Each loaded sound effect will be assigned one of these, which is to be used
46 for operations related to the effect, including playing it or unloading it.
47*/
48typedef uint32_t sfxhnd_t;
49
50/** \brief Invalid sound effect handle value.
51
52 If a sound effect cannot be loaded, this value will be returned as the error
53 condition.
54*/
55#define SFXHND_INVALID 0
56
57/** \brief Load a sound effect.
58
59 This function loads a sound effect from a WAV file and returns a handle to
60 it. The sound effect can be either stereo or mono, and must either be 8-bit
61 or 16-bit uncompressed PCM samples, or 4-bit Yamaha ADPCM.
62
63 \warning The sound effect you are loading must be at most 65534 samples
64 in length.
65
66 \param fn The file to load.
67 \return A handle to the sound effect on success. On error,
68 SFXHND_INVALID is returned.
69*/
70sfxhnd_t snd_sfx_load(const char *fn);
71
72/** \brief Load a sound effect without wav header.
73
74 This function loads a sound effect from a RAW file and returns a handle to
75 it. The sound effect can be either stereo or mono, and must either be 8-bit
76 or 16-bit uncompressed PCM samples, or 4-bit Yamaha ADPCM.
77
78 \warning The sound effect you are loading must be at most 65534 samples
79 in length and multiple by 32 bytes for each channel.
80
81 \param fn The file to load.
82 \param rate The frequency of the sound.
83 \param bitsize The sample size (bits per sample).
84 \param channels Number of channels.
85 \return A handle to the sound effect on success. On error,
86 SFXHND_INVALID is returned.
87*/
88sfxhnd_t snd_sfx_load_ex(const char *fn, uint32_t rate, uint16_t bitsize, uint16_t channels);
89
90/** \brief Load a sound effect without wav header by file handler.
91
92 This function loads a sound effect from a RAW file and returns a handle to
93 it. The sound effect can be either stereo or mono, and must either be 8-bit
94 or 16-bit uncompressed PCM samples, or 4-bit Yamaha ADPCM.
95
96 \warning The sound effect you are loading must be at most 65534 samples
97 in length and multiple by 32 bytes for each channel.
98
99 \param fd The file handler.
100 \param len The file length.
101 \param rate The frequency of the sound.
102 \param bitsize The sample size (bits per sample).
103 \param channels Number of channels.
104 \return A handle to the sound effect on success. On error,
105 SFXHND_INVALID is returned.
106*/
107sfxhnd_t snd_sfx_load_fd(file_t fd, size_t len, uint32_t rate, uint16_t bitsize, uint16_t channels);
108
109/** \brief Load a sound effect.
110
111 This function loads a sound effect from a WAV file contained in memory and
112 returns a handle to it. The sound effect can be either stereo or mono, and
113 must either be 8-bit or 16-bit uncompressed PCM samples, or 4-bit Yamaha
114 ADPCM.
115
116 \warning The sound effect you are loading must be at most 65534 samples
117 in length.
118
119 \param buf The buffer to load.
120 \return A handle to the sound effect on success. On error,
121 SFXHND_INVALID is returned.
122*/
124
125/** \brief Load a sound effect without wav header from buffer.
126
127 This function loads a sound effect from raw data contained in memory and
128 returns a handle to it. The sound effect can be either stereo or mono, and
129 must either be 8-bit or 16-bit uncompressed PCM samples, or 4-bit Yamaha
130 ADPCM.
131
132 \warning The sound effect you are loading must be at most 65534 samples
133 in length and multiple by 32 bytes for each channel.
134
135 \param buf The buffer.
136 \param len The file length.
137 \param rate The frequency of the sound.
138 \param bitsize The sample size (bits per sample).
139 \param channels Number of channels.
140 \return A handle to the sound effect on success. On error,
141 SFXHND_INVALID is returned.
142*/
143sfxhnd_t snd_sfx_load_raw_buf(char *buf, size_t len, uint32_t rate, uint16_t bitsize, uint16_t channels);
144
145/** \brief Unload a sound effect.
146
147 This function unloads a previously loaded sound effect, and frees the memory
148 associated with it.
149
150 \param idx A handle to the sound effect to unload.
151*/
153
154/** \brief Unload all loaded sound effects.
155
156 This function unloads all previously loaded sound effect, and frees the
157 memory associated with them.
158*/
160
161/** \brief Play a sound effect.
162
163 This function plays a loaded sound effect with the specified volume (for
164 both stereo or mono) and panning values (for mono sounds only).
165
166 \param idx The handle to the sound effect to play.
167 \param vol The volume to play at (between 0 and 255).
168 \param pan The panning value of the sound effect. 0 is all the
169 way to the left, 128 is center, 255 is all the way
170 to the right.
171
172 \return The channel used to play the sound effect (or the
173 left channel in the case of a stereo sound, the
174 right channel will be the next one) on success, or
175 -1 on failure.
176*/
177int snd_sfx_play(sfxhnd_t idx, int vol, int pan);
178
179/** \brief Play a sound effect on a specific channel.
180
181 This function works similar to snd_sfx_play(), but allows you to specify the
182 channel to play on. No error checking is done with regard to the channel, so
183 be sure its safe to play on that channel before trying.
184
185 \param chn The channel to play on (or in the case of stereo,
186 the left channel).
187 \param idx The handle to the sound effect to play.
188 \param vol The volume to play at (between 0 and 255).
189 \param pan The panning value of the sound effect. 0 is all the
190 way to the left, 128 is center, 255 is all the way
191 to the right.
192
193 \return chn
194*/
195int snd_sfx_play_chn(int chn, sfxhnd_t idx, int vol, int pan);
196
197/** \brief Stop a single channel of sound.
198
199 This function stops the specified channel of sound from playing. It does no
200 checking to make sure that a sound effect is playing on the channel
201 specified, and thus can be used even if you're using the channel for some
202 other purpose than sound effects.
203
204 \param chn The channel to stop.
205*/
206void snd_sfx_stop(int chn);
207
208/** \brief Stop all channels playing sound effects.
209
210 This function stops all channels currently allocated to sound effects from
211 playing. It does not affect channels allocated for use by something other
212 than sound effects..
213*/
215
216/** \brief Allocate a sound channel for use outside the sound effect system.
217
218 This function finds and allocates a channel for use for things other than
219 sound effects. This is useful for, for instance, the streaming code.
220
221 \returns The allocated channel on success, -1 on failure.
222*/
224
225/** \brief Free a previously allocated channel.
226
227 This function frees a channel that was allocated with snd_sfx_chn_alloc(),
228 returning it to the pool of available channels for sound effect use.
229
230 \param chn The channel to free.
231*/
232void snd_sfx_chn_free(int chn);
233
234/** @} */
235
236__END_DECLS
237
238#endif /* __DC_SOUND_SFXMGR_H */
239
Virtual filesystem support.
void snd_sfx_chn_free(int chn)
Free a previously allocated channel.
sfxhnd_t snd_sfx_load_fd(file_t fd, size_t len, uint32_t rate, uint16_t bitsize, uint16_t channels)
Load a sound effect without wav header by file handler.
void snd_sfx_stop(int chn)
Stop a single channel of sound.
int snd_sfx_play_chn(int chn, sfxhnd_t idx, int vol, int pan)
Play a sound effect on a specific channel.
int snd_sfx_play(sfxhnd_t idx, int vol, int pan)
Play a sound effect.
uint32_t sfxhnd_t
Sound effect handle type.
Definition sfxmgr.h:48
int snd_sfx_chn_alloc(void)
Allocate a sound channel for use outside the sound effect system.
void snd_sfx_stop_all(void)
Stop all channels playing sound effects.
sfxhnd_t snd_sfx_load_buf(char *buf)
Load a sound effect.
void snd_sfx_unload_all(void)
Unload all loaded sound effects.
sfxhnd_t snd_sfx_load_ex(const char *fn, uint32_t rate, uint16_t bitsize, uint16_t channels)
Load a sound effect without wav header.
sfxhnd_t snd_sfx_load_raw_buf(char *buf, size_t len, uint32_t rate, uint16_t bitsize, uint16_t channels)
Load a sound effect without wav header from buffer.
sfxhnd_t snd_sfx_load(const char *fn)
Load a sound effect.
void snd_sfx_unload(sfxhnd_t idx)
Unload a sound effect.
int file_t
File descriptor type.
Definition fs.h:94
Common integer types.