Jo Engine  2024.04.28
Jo Sega Saturn Engine
audio.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2024, 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 */
35 #ifndef __JO_AUDIO_H__
36 # define __JO_AUDIO_H__
37 
38 #ifdef JO_COMPILE_WITH_AUDIO_SUPPORT
39 
40 # define JO_SOUND_MAX_CHANNEL (6)
41 
42 typedef enum
43 {
44  JoSoundMono8Bit = (0x00 | 0x10),
45  JoSoundMono16Bit = (0x00 | 0x00),
46  JoSoundStereo8Bit = (0x80 | 0x10),
47  JoSoundStereo16Bit = (0x80 | 0x00)
49 
50 typedef struct
51 {
52  char *data;
53  unsigned int data_length;
55  unsigned char current_playing_channel;
56  unsigned short sample_rate; // Set sampling rate from 8000 to 44100 kHz
57  unsigned char volume; // Change volume: 0 (JO_MIN_AUDIO_VOLUME) -> 127 (JO_MAX_AUDIO_VOLUME)
58  char pan; // Adjust stereo: -128 (left speaker) -> 127 (right speaker)
59 } jo_sound;
60 
62 # define JO_DEFAULT_AUDIO_VOLUME (127)
63 
64 # define JO_MAX_AUDIO_VOLUME (127)
65 
66 # define JO_MIN_AUDIO_VOLUME (0)
67 
73 void jo_audio_play_cd_track(const int from_track, const int to_track, const bool repeat_infinitely);
74 
78 void jo_audio_set_volume(const unsigned char vol);
79 
82 void jo_audio_stop_cd(void);
83 
88 void jo_audio_play_sound_on_channel(jo_sound * const sound, const unsigned char channel);
89 
93 void jo_audio_play_sound(jo_sound * const sound);
94 
98 void jo_audio_stop_sound(const jo_sound * const sound);
99 
100 #ifdef JO_COMPILE_WITH_FS_SUPPORT
101 
111 bool jo_audio_load_pcm(const char * const filename, const jo_sound_mode mode, jo_sound *sound);
112 
122 bool jo_audio_load_pcm_async(const char * const filename, const jo_sound_mode mode, jo_sound *sound);
123 
124 #endif
125 
130 
136 
137 #endif /* !JO_COMPILE_WITH_AUDIO_SUPPORT */
138 
139 #endif /* !__JO_AUDIO_H__ */
140 
141 /*
142 ** END OF FILE
143 */
jo_sound::pan
char pan
Definition: audio.h:58
jo_audio_usage_percent
int jo_audio_usage_percent(void)
Get audio channel usage.
jo_audio_stop_sound
void jo_audio_stop_sound(const jo_sound *const sound)
Stop a sound.
jo_sound::data_length
unsigned int data_length
Definition: audio.h:53
JoSoundStereo8Bit
@ JoSoundStereo8Bit
Definition: audio.h:46
jo_audio_play_sound_on_channel
void jo_audio_play_sound_on_channel(jo_sound *const sound, const unsigned char channel)
Play a sound on a specific channel.
jo_sound::volume
unsigned char volume
Definition: audio.h:57
JoSoundMono8Bit
@ JoSoundMono8Bit
Definition: audio.h:44
jo_sound
Definition: audio.h:51
JoSoundStereo16Bit
@ JoSoundStereo16Bit
Definition: audio.h:47
jo_sound::data
char * data
Definition: audio.h:52
jo_audio_free_pcm
void jo_audio_free_pcm(jo_sound *sound)
Free pcm sound loaded with jo_audio_load_pcm()
jo_audio_play_sound
void jo_audio_play_sound(jo_sound *const sound)
Play a sound on first available channel.
jo_audio_load_pcm_async
bool jo_audio_load_pcm_async(const char *const filename, const jo_sound_mode mode, jo_sound *sound)
Load PCM file from CD asynchronously.
jo_sound::current_playing_channel
unsigned char current_playing_channel
Definition: audio.h:55
JoSoundMono16Bit
@ JoSoundMono16Bit
Definition: audio.h:45
jo_sound::sample_rate
unsigned short sample_rate
Definition: audio.h:56
jo_audio_play_cd_track
void jo_audio_play_cd_track(const int from_track, const int to_track, const bool repeat_infinitely)
Play a track from the CD.
jo_audio_load_pcm
bool jo_audio_load_pcm(const char *const filename, const jo_sound_mode mode, jo_sound *sound)
Load PCM file from CD.
jo_audio_stop_cd
void jo_audio_stop_cd(void)
Stop playing audio track.
jo_sound_mode
jo_sound_mode
Definition: audio.h:43
jo_sound::mode
jo_sound_mode mode
Definition: audio.h:54
jo_audio_set_volume
void jo_audio_set_volume(const unsigned char vol)
Set the audio volume.