LibGame v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
Loading...
Searching...
No Matches
lg_audio.h
1/*
2 * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2026
3 * All rights reserved
4 */
5
6#ifndef LG_AUDIO_H
7#define LG_AUDIO_H
8
9/*
10 * See: https://wiki.libsdl.org/SDL2_mixer/CategoryAPI
11 *
12 * Plus, from: https://github.com/libsdl-org/SDL_mixer/blob/SDL2/include/SDL_mixer.h
13 *
14 * The audio device frequency is specified in Hz; in modern times, 48000 is
15 * often a reasonable default.
16 *
17 * The audio device format is one of SDL's AUDIO_* constants. AUDIO_S16SYS
18 * (16-bit audio) is probably a safe default. More modern systems may prefer
19 * AUDIO_F32SYS (32-bit floating point audio).
20 *
21 * The audio device channels are generally 1 for mono output, or 2 for stereo,
22 * but the brave can try surround sound configs with 4 (quad), 6 (5.1), 7
23 * (6.1) or 8 (7.1).
24 *
25 * The audio device's chunk size is the number of sample frames (one sample
26 * per frame for mono output, two samples per frame in a stereo setup, etc)
27 * that are fed to the device at once. The lower the number, the lower the
28 * latency, but you risk dropouts if it gets too low. 2048 is often a
29 * reasonable default, but your app might want to experiment with 1024 or
30 * 4096.
31 */
32
33#define LG_AUDIO_FREQ 48000 /* High values reduce latency - previously 44100 */
34#define LG_AUDIO_FORMAT AUDIO_S16SYS /* Previously AUDIO_F32SYS */
35#define LG_AUDIO_N_CHANNELS 2
36#define LG_AUDIO_BUF_SIZE (2 * 1024) /* Low values reduce latency - previously 1024 */
37
38#define LG_AUDIO_MAX_VOL MIX_MAX_VOLUME
39
40#define SOUND_FILENAME_MAXLEN (64 - 1)
41
42typedef struct {
43 char file_name[SOUND_FILENAME_MAXLEN + 1];
44 Mix_Chunk *sample; /* sample->volume in range [0, 128] */
45 int channel; /* 8 available channels */
46} LG_Sound;
47
48typedef enum {
49 LG_PLAY, LG_REPEAT, LG_WAIT, LG_STOP, LG_PAUSE, LG_RESUME
50} lg_play_mode;
51
53
54int lg_audio_init(int, uint16_t, int, int);
55
56void lg_audio_free();
57
59
61
63
64void lg_audio_pause();
65
66void lg_audio_resume();
67
68void lg_audio_stop();
69
71
73
75
76LG_Sound *lg_sound_new(const char *);
77
78int lg_sound_play(lg_play_mode, LG_Sound *);
79
81
83
85
87
88int lg_music_load_and_play(const char *, int);
89
90zboolean lg_music_is_playing();
91
92void lg_music_pause();
93
94void lg_music_resume();
95
96void lg_music_stop();
97
98void lg_music_free();
99
100#endif /* LG_AUDIO_H */
float lg_sound_channel_get_volume(LG_Sound *sound)
Definition lg_audio.c:325
void lg_music_pause()
Definition lg_audio.c:382
void lg_audio_resume()
Definition lg_audio.c:131
void lg_audio_set_music_volume(float v)
Definition lg_audio.c:91
int lg_audio_init_to_defaults()
Definition lg_audio.c:27
int lg_music_load_and_play(const char *file_name, int loops)
Definition lg_audio.c:356
void lg_sound_channel_set_volume(LG_Sound *sound, float v)
Definition lg_audio.c:308
void lg_music_free()
Definition lg_audio.c:414
int lg_sound_play(lg_play_mode mode, LG_Sound *sound)
Definition lg_audio.c:245
void lg_audio_set_sounds_volume(float v)
Definition lg_audio.c:108
void lg_music_resume()
Definition lg_audio.c:392
LG_Sound * lg_sound_new(const char *file_name)
Definition lg_audio.c:178
void lg_audio_free()
Definition lg_audio.c:62
void lg_music_stop()
Definition lg_audio.c:402
void lg_audio_disable_cant_play_file()
Definition lg_audio.c:157
void lg_sound_free(LG_Sound *sound)
Definition lg_audio.c:339
void lg_audio_enable_cant_play_file()
Definition lg_audio.c:167
int lg_audio_init(int freq, uint16_t format, int n_channels, int buffer_size)
Definition lg_audio.c:47
void lg_audio_pause()
Definition lg_audio.c:123
void lg_audio_stop()
Definition lg_audio.c:139
zboolean lg_music_is_playing()
Definition lg_audio.c:374
void lg_audio_set_global_volume(float v)
Definition lg_audio.c:74
int lg_audio_get_n_channels()
Definition lg_audio.c:149
zboolean lg_sound_is_playing(LG_Sound *sound)
Definition lg_audio.c:291
Definition lg_audio.h:42