-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio.c
116 lines (66 loc) · 1.71 KB
/
audio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "audio.h"
// initializes sdl_mixer
void decaf_audio_init(void) {
if(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1) {
printf("SDL Error: %s", SDL_GetError());
}
}
// loads wav file from given path
Mix_Chunk *decaf_audio_loadSound(char *path) {
Mix_Chunk *sound = Mix_LoadWAV(path);
if(sound != NULL) {
printf("sound loaded: %s\n", path);
}
return sound;
}
// plays audio (does not loop)
void decaf_audio_playSound(Mix_Chunk *sound) {
Mix_PlayChannel(-1, sound, 0);
}
// loads music audio
Mix_Music *decaf_audio_loadMusic(char *path) {
Mix_Music *music = Mix_LoadMUS(path);
if(music != NULL) {
printf("music loaded: %s\n", path);
}
return music;
}
// plays music (is loop)
void decaf_audio_playMusic(Mix_Music *music) {
// checks if theres music currently playing
if(Mix_PlayingMusic() == 0) {
Mix_PlayMusic(music, -1);
}
}
// stops music thats currently playing
void decaf_audio_stopMusic(void) {
Mix_HaltMusic();
}
// pauses music thats currently playing
void decaf_audio_pauseMusic(void) {
Mix_PauseMusic();
}
// resumes music that was playing
void decaf_audio_resumeMusic(void) {
Mix_ResumeMusic();
}
// sets music volume
void decaf_audio_setMusicVolume(int volume) {
Mix_VolumeMusic(volume);
}
// sets sound audio
void decaf_audio_setSoundVolume(int volume) {
Mix_Volume(-1, volume);
}
// closes out sdl_mixer
void decaf_audio_quit(void) {
Mix_CloseAudio();
}
// frees sound from memory
void decaf_audio_destroySound(Mix_Chunk *sound) {
Mix_FreeChunk(sound);
}
// frees music from memory
void decaf_audio_destroyMusic(Mix_Music *music) {
Mix_FreeMusic(music);
}