-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio_test.c
95 lines (53 loc) · 1.63 KB
/
audio_test.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
#ifdef __APPLE__
#define MA_NO_RUNTIME_LINKING
#endif
#define MINIAUDIO_IMPLEMENTATION
#include "audio_test.h"
/*
NOTICE: This audio backend is still under development! All code here is unfinished and may cause your project to crash
*/
ma_engine engine;
int mini_init(void) {
ma_result result;
result = ma_engine_init(NULL, &engine);
if (result != MA_SUCCESS) {
return -1;
}
return 0;
}
ma_sound *mini_load(char *audio_path) {
static ma_sound sound;
char exec_path[strlen(SDL_GetBasePath()) + 1];
strcpy(exec_path, SDL_GetBasePath());
char asset_path[256];
strcpy(asset_path, audio_path);
char file[strlen(exec_path) + strlen(asset_path) + 1];
strncat(exec_path, asset_path, 512);
strcpy(file, exec_path);
printf("audio loaded: %s\n", file);
ma_sound_init_from_file(&engine, file, 0, NULL, NULL, &sound);
return &sound;
}
void mini_play_file(ma_sound *sound) {
ma_result result;
result = ma_sound_start(sound);
if (result != MA_SUCCESS) {
printf("%d", result);
}
}
int mini_play(void) {
char exec_path[strlen(SDL_GetBasePath()) + 1];
strcpy(exec_path, SDL_GetBasePath());
char asset_path[256];
strcpy(asset_path, "assets/audio/test.wav");
char file[strlen(exec_path) + strlen(asset_path) + 1];
strncat(exec_path, asset_path, 512);
strcpy(file, exec_path);
ma_engine_play_sound(&engine, file, NULL);
return 0;
}
void mini_stop(ma_sound *sound) { ma_sound_stop(sound); }
bool mini_ended(ma_sound *sound) { return ma_sound_at_end(sound); }
void mini_unload(void) {
ma_engine_uninit(&engine);
}