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 Unload a sound effect.
110
111 This function unloads a previously loaded sound effect, and frees the memory
112 associated with it.
113
114 \param idx A handle to the sound effect to unload.
115*/
117
118/** \brief Unload all loaded sound effects.
119
120 This function unloads all previously loaded sound effect, and frees the
121 memory associated with them.
122*/
124
125/** \brief Play a sound effect.
126
127 This function plays a loaded sound effect with the specified volume (for
128 both stereo or mono) and panning values (for mono sounds only).
129
130 \param idx The handle to the sound effect to play.
131 \param vol The volume to play at (between 0 and 255).
132 \param pan The panning value of the sound effect. 0 is all the
133 way to the left, 128 is center, 255 is all the way
134 to the right.
135
136 \return The channel used to play the sound effect (or the
137 left channel in the case of a stereo sound, the
138 right channel will be the next one) on success, or
139 -1 on failure.
140*/
141int snd_sfx_play(sfxhnd_t idx, int vol, int pan);
142
143/** \brief Play a sound effect on a specific channel.
144
145 This function works similar to snd_sfx_play(), but allows you to specify the
146 channel to play on. No error checking is done with regard to the channel, so
147 be sure its safe to play on that channel before trying.
148
149 \param chn The channel to play on (or in the case of stereo,
150 the left channel).
151 \param idx The handle to the sound effect to play.
152 \param vol The volume to play at (between 0 and 255).
153 \param pan The panning value of the sound effect. 0 is all the
154 way to the left, 128 is center, 255 is all the way
155 to the right.
156
157 \return chn
158*/
159int snd_sfx_play_chn(int chn, sfxhnd_t idx, int vol, int pan);
160
161/** \brief Stop a single channel of sound.
162
163 This function stops the specified channel of sound from playing. It does no
164 checking to make sure that a sound effect is playing on the channel
165 specified, and thus can be used even if you're using the channel for some
166 other purpose than sound effects.
167
168 \param chn The channel to stop.
169*/
170void snd_sfx_stop(int chn);
171
172/** \brief Stop all channels playing sound effects.
173
174 This function stops all channels currently allocated to sound effects from
175 playing. It does not affect channels allocated for use by something other
176 than sound effects..
177*/
179
180/** \brief Allocate a sound channel for use outside the sound effect system.
181
182 This function finds and allocates a channel for use for things other than
183 sound effects. This is useful for, for instance, the streaming code.
184
185 \returns The allocated channel on success, -1 on failure.
186*/
188
189/** \brief Free a previously allocated channel.
190
191 This function frees a channel that was allocated with snd_sfx_chn_alloc(),
192 returning it to the pool of available channels for sound effect use.
193
194 \param chn The channel to free.
195*/
196void snd_sfx_chn_free(int chn);
197
198/** @} */
199
200__END_DECLS
201
202#endif /* __DC_SOUND_SFXMGR_H */
203
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.
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(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.