Jo Engine 2026.11.1
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
audio.h
Go to the documentation of this file.
1/*
2** Jo Sega Saturn Engine
3** Copyright (c) 2012-2026, Johannes Fetz (johannesfetz@gmail.com)
4** All rights reserved.
5**
6** Redistribution and use in source and binary forms, with or without
7** modification, are permitted provided that the following conditions are met:
8** * Redistributions of source code must retain the above copyright
9** notice, this list of conditions and the following disclaimer.
10** * Redistributions in binary form must reproduce the above copyright
11** notice, this list of conditions and the following disclaimer in the
12** documentation and/or other materials provided with the distribution.
13** * Neither the name of the Johannes Fetz nor the
14** names of its contributors may be used to endorse or promote products
15** derived from this software without specific prior written permission.
16**
17** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY
21** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
34
35#ifndef __JO_AUDIO_H__
36# define __JO_AUDIO_H__
37
38#ifdef JO_COMPILE_WITH_AUDIO_SUPPORT
39
41# define JO_SOUND_MAX_CHANNEL (14)
42
43typedef enum
44{
45 JoSoundMono8Bit = (0x00 | 0x10),
46 JoSoundMono16Bit = (0x00 | 0x00),
47 JoSoundStereo8Bit = (0x80 | 0x10),
48 JoSoundStereo16Bit = (0x80 | 0x00)
50
51typedef struct
52{
53 char *data;
54 unsigned int data_length;
57 unsigned short sample_rate; // Set sampling rate from 8000 to 44100 kHz
58 unsigned char volume; // Change volume: 0 (JO_MIN_AUDIO_VOLUME) -> 127 (JO_MAX_AUDIO_VOLUME)
59 char pan; // Adjust stereo: -128 (left speaker) -> 127 (right speaker)
60 unsigned int resident; // Kept in the sound RAM (jo_audio_make_resident()): its offset there + 1, 0: not resident
61 unsigned char reverb; // Its send to the reverberation (JO_COMPILE_WITH_AUDIO_DSP_MODULE): 0 (none), 1 to 7 (-36 to 0 dB, 6 dB steps)
62} jo_sound;
63
65# define JO_DEFAULT_AUDIO_VOLUME (127)
67# define JO_MAX_AUDIO_VOLUME (127)
69# define JO_MIN_AUDIO_VOLUME (0)
70
71#ifdef JO_COMPILE_WITH_FS_SUPPORT
72
79void jo_audio_play_cd_track(const int from_track, const int to_track, const bool repeat_infinitely);
80
85
92
99
105
113
114#endif
115
119void jo_audio_set_volume(const unsigned char vol);
120
122# define JO_AUDIO_CD_VOLUME_MAX (7)
123
128void jo_audio_set_cd_volume(const unsigned char level);
129
134bool jo_audio_is_channel_playing(const unsigned char channel);
135
141void jo_audio_play_sound_on_channel(jo_sound * const sound, const unsigned char channel);
142
149void jo_audio_play_sound_loop_on_channel(jo_sound * const sound, const unsigned char channel);
150
155void jo_audio_set_channel_sample_rate(const unsigned char channel, const unsigned short sample_rate);
156
161void jo_audio_set_channel_volume(const unsigned char channel, const unsigned char volume);
162
167void jo_audio_set_channel_reverb(const unsigned char channel, const unsigned char level);
168
169#ifdef JO_COMPILE_WITH_AUDIO_DSP_SUPPORT
170
172typedef struct
173{
174 unsigned short decay_ms; // The tail falls by 60 dB in this time (the low frequencies): 50 to 10000 ms
175 unsigned char damping; // The high frequencies die faster: 0 (as the low ones) to 127 (much faster: a soft room)
176 unsigned char early; // The level of the early reflections (the walls: 9 to 23 ms): 0 to 127
177 unsigned char tail; // The level of the tail: 0 to 127
178} jo_audio_reverb;
179
186void jo_audio_set_reverb(const jo_audio_reverb * const reverb);
187
188#endif
189
190#ifdef JO_COMPILE_WITH_AUDIO_DRIVER_SUPPORT
191
193typedef enum
194{
195 JoToneSine = 0,
196 JoToneNoise = 1
197} jo_tone_waveform;
198
200typedef struct
201{
202 unsigned short frequency; // Hz (20 to 8000)
203 unsigned short end_frequency; // The pitch glides to this frequency (Hz, 0: no glide)
204 unsigned short glide_ms; // The time of the glide: 63 % of the way in this time
205 unsigned short decay_ms; // The tone falls by 60 dB in this time (0: it plays until the channel is stopped)
206 unsigned char volume; // 0 (JO_MIN_AUDIO_VOLUME) -> 127 (JO_MAX_AUDIO_VOLUME)
207 char pan; // -128 (left speaker) -> 127 (right speaker)
208 unsigned char reverb; // Send to the reverberation (JO_COMPILE_WITH_AUDIO_DSP_MODULE): 0 to 7
209 unsigned char modulation; // FM: the index x 16 (16: 1 radian, 0: no FM); the second slot of the channel is the modulator
210 unsigned char modulator_ratio; // FM: the frequency of the modulator / the frequency x 4 (4: the same frequency, 8: twice)
211 unsigned char tremolo; // The depth of the tremolo (the amplitude LFO): 0 (none) to 7
212 unsigned char tremolo_rate; // Its frequency: 0 to 31 (LFOF of the SCSP: 0.17 Hz to 96 Hz; 28: 38 Hz)
213 jo_tone_waveform waveform;
214} jo_audio_tone;
215
223void jo_audio_play_tone(const jo_audio_tone * const tone, const unsigned char channel);
224
225#endif
226
230void jo_audio_play_sound(jo_sound * const sound);
231
235void jo_audio_stop_sound(const jo_sound * const sound);
236
242void jo_audio_stop_channel(const unsigned char channel);
243
244#ifdef JO_COMPILE_WITH_FS_SUPPORT
245
255bool jo_audio_load_pcm(const char * const filename, const jo_sound_mode mode, jo_sound *sound);
256
266bool jo_audio_load_pcm_async(const char * const filename, const jo_sound_mode mode, jo_sound *sound);
267
277bool jo_audio_load_wav(const char * const filename, jo_sound *sound);
278
279#endif
280
288
293
298
304
305#endif /* !JO_COMPILE_WITH_AUDIO_SUPPORT */
306
307#endif /* !__JO_AUDIO_H__ */
308
309/*
310** END OF FILE
311*/
void jo_audio_free_resident(void)
Forget all the resident sounds (a new level): their room in the sound RAM is free again.
void jo_audio_play_cd_track(const int from_track, const int to_track, const bool repeat_infinitely)
Play a track from the CD.
void jo_audio_stop_channel(const unsigned char channel)
Stop the sound played on a channel.
jo_sound_mode mode
Definition audio.h:55
jo_sound_mode
Definition audio.h:44
@ JoSoundStereo16Bit
Definition audio.h:48
@ JoSoundMono8Bit
Definition audio.h:45
@ JoSoundStereo8Bit
Definition audio.h:47
@ JoSoundMono16Bit
Definition audio.h:46
bool jo_audio_load_pcm_async(const char *const filename, const jo_sound_mode mode, jo_sound *sound)
Load PCM file from CD asynchronously.
bool jo_audio_load_pcm(const char *const filename, const jo_sound_mode mode, jo_sound *sound)
Load PCM file from CD.
void jo_audio_set_channel_volume(const unsigned char channel, const unsigned char volume)
Change the volume of the sound played on a channel.
void jo_audio_set_cd_volume(const unsigned char level)
Set the level of the CD audio in the mix (the music tracks of the CD, see jo_audio_play_cd_track()).
unsigned char reverb
Definition audio.h:61
unsigned int resident
Definition audio.h:60
void jo_audio_free_pcm(jo_sound *sound)
Free pcm sound loaded with jo_audio_load_pcm().
bool jo_audio_is_cd_paused(void)
Check if the CD audio is paused (see jo_audio_pause_cd()).
void jo_audio_set_channel_reverb(const unsigned char channel, const unsigned char level)
Change the send of the sound played on a channel to the reverberation (JO_COMPILE_WITH_AUDIO_DSP_MODU...
int jo_audio_usage_percent(void)
Get audio channel usage.
bool jo_audio_is_cd_playing(void)
Check if the CD drive is playing.
unsigned int data_length
Definition audio.h:54
void jo_audio_set_volume(const unsigned char vol)
Set the audio volume.
void jo_audio_play_sound(jo_sound *const sound)
Play a sound on first available channel.
void jo_audio_pause_cd(void)
Pause the audio track played by jo_audio_play_cd_track().
char * data
Definition audio.h:53
void jo_audio_play_sound_on_channel(jo_sound *const sound, const unsigned char channel)
Play a sound on a specific channel.
bool jo_audio_is_channel_playing(const unsigned char channel)
Checks whether a given audio channel is currently playing a sound.
void jo_audio_stop_sound(const jo_sound *const sound)
Stop a sound.
void jo_audio_set_channel_sample_rate(const unsigned char channel, const unsigned short sample_rate)
Change the sampling rate of the sound played on a channel (its pitch: a faster engine for instance).
char pan
Definition audio.h:59
unsigned char current_playing_channel
Definition audio.h:56
void jo_audio_play_sound_loop_on_channel(jo_sound *const sound, const unsigned char channel)
Play a sound again and again on a specific channel, until the channel is stopped (an engine for insta...
unsigned char volume
Definition audio.h:58
void jo_audio_resume_cd(void)
Resume the audio track paused by jo_audio_pause_cd().
void jo_audio_stop_cd(void)
Stop playing audio track.
bool jo_audio_load_wav(const char *const filename, jo_sound *sound)
Load a WAV file from CD (PCM, 8 or 16 bits, mono or stereo, any sample rate: the sound gets its mode ...
bool jo_audio_make_resident(jo_sound *sound)
Keep a sound in the sound RAM (512 KB) and free its copy in the work RAM (the jo_malloc() memory).
unsigned short sample_rate
Definition audio.h:57
Definition audio.h:52