LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_audio.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2024
3  * All rights reserved
4  */
5 
6 #ifndef LG_AUDIO_H
7 #define LG_AUDIO_H
8 
9 /*
10  * From: https://github.com/libsdl-org/SDL_mixer/blob/SDL2/include/SDL_mixer.h
11  *
12  * The audio device frequency is specified in Hz; in modern times, 48000 is
13  * often a reasonable default.
14  *
15  * The audio device format is one of SDL's AUDIO_* constants. AUDIO_S16SYS
16  * (16-bit audio) is probably a safe default. More modern systems may prefer
17  * AUDIO_F32SYS (32-bit floating point audio).
18  *
19  * The audio device channels are generally 1 for mono output, or 2 for stereo,
20  * but the brave can try surround sound configs with 4 (quad), 6 (5.1), 7
21  * (6.1) or 8 (7.1).
22  *
23  * The audio device's chunk size is the number of sample frames (one sample
24  * per frame for mono output, two samples per frame in a stereo setup, etc)
25  * that are fed to the device at once. The lower the number, the lower the
26  * latency, but you risk dropouts if it gets too low. 2048 is often a
27  * reasonable default, but your app might want to experiment with 1024 or
28  * 4096.
29  */
30 
31 #define LG_AUDIO_FREQ 48000 /* High values reduce latency - previously 44100 */
32 #define LG_AUDIO_FORMAT AUDIO_S16SYS /* Previously AUDIO_F32SYS */
33 #define LG_AUDIO_N_CHANNELS 2
34 #define LG_AUDIO_BUF_SIZE (2 * 1024) /* Low values reduce latency - previously 1024 */
35 
36 #define LG_AUDIO_MAX_VOL MIX_MAX_VOLUME
37 
38 #define SOUND_FILENAME_MAXLEN (64 - 1)
39 
40 typedef struct {
41  char file_name[SOUND_FILENAME_MAXLEN + 1];
42  Mix_Chunk *sample;
43  int channel;
44 } LG_Sound;
45 
46 typedef enum {
47  LG_PLAY, LG_REPEAT, LG_WAIT, LG_STOP
48 } lg_play_mode;
49 
51 
52 int lg_init_audio(int, uint16_t, int, int);
53 
54 void lg_free_audio();
55 
56 int lg_load_play_music(const char *, int);
57 
58 zboolean lg_music_is_playing();
59 
60 void lg_pause_music();
61 
62 void lg_resume_music();
63 
64 void lg_stop_music();
65 
66 void lg_free_music();
67 
68 LG_Sound *lg_sound_new(const char *);
69 
71 
73 
74 int lg_sound_play(lg_play_mode, LG_Sound *);
75 
76 zboolean lg_sound_is_playing(LG_Sound *);
77 
78 // === EXPERIMENTAL ===
80 
81 // === EXPERIMENTAL ===
83 
84 void lg_sound_free(LG_Sound *);
85 
86 void lg_audio_set_global_volume(float);
87 
88 void lg_audio_set_music_volume(float);
89 
90 void lg_audio_set_sounds_volume(float);
91 
92 #endif /* LG_AUDIO_H */
lg_load_play_music
int lg_load_play_music(const char *file_name, int loops)
Definition: lg_audio.c:72
lg_sound_channel_get_volume
float lg_sound_channel_get_volume(LG_Sound *sound)
Definition: lg_audio.c:309
lg_sound_new
LG_Sound * lg_sound_new(const char *file_name)
Definition: lg_audio.c:143
lg_enable_cant_play_audio_file
void lg_enable_cant_play_audio_file()
Definition: lg_audio.c:177
LG_Sound
Definition: lg_audio.h:40
lg_resume_music
void lg_resume_music()
Definition: lg_audio.c:108
lg_disable_cant_play_audio_file
void lg_disable_cant_play_audio_file()
Definition: lg_audio.c:167
lg_init_audio_to_defaults
int lg_init_audio_to_defaults()
Definition: lg_audio.c:25
lg_music_is_playing
zboolean lg_music_is_playing()
Definition: lg_audio.c:90
lg_sound_free
void lg_sound_free(LG_Sound *sound)
Definition: lg_audio.c:323
lg_pause_music
void lg_pause_music()
Definition: lg_audio.c:98
lg_init_audio
int lg_init_audio(int freq, uint16_t format, int n_channels, int buffer_size)
Definition: lg_audio.c:45
lg_free_audio
void lg_free_audio()
Definition: lg_audio.c:60
lg_free_music
void lg_free_music()
Definition: lg_audio.c:128
lg_stop_music
void lg_stop_music()
Definition: lg_audio.c:118
lg_sound_is_playing
zboolean lg_sound_is_playing(LG_Sound *sound)
Definition: lg_audio.c:274
lg_sound_play
int lg_sound_play(lg_play_mode mode, LG_Sound *sound)
Definition: lg_audio.c:231
lg_sound_channel_set_volume
void lg_sound_channel_set_volume(LG_Sound *sound, float v)
Definition: lg_audio.c:292
lg_audio_set_sounds_volume
void lg_audio_set_sounds_volume(float v)
Definition: lg_audio.c:374
lg_audio_set_music_volume
void lg_audio_set_music_volume(float v)
Definition: lg_audio.c:357
lg_audio_set_global_volume
void lg_audio_set_global_volume(float v)
Definition: lg_audio.c:340