-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaudio_soloud.cpp
87 lines (73 loc) · 1.96 KB
/
audio_soloud.cpp
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
#ifdef HAVE_SOLOUD
#include <malloc.h>
#include <stdio.h>
#include "soloud.h"
#include "soloud_wav.h"
#include "soloud_wavstream.h"
#include "engine.h"
#include "games.h"
SoLoud::Soloud soloud;
extern "C" {
void audio_soloud_init() {
soloud.init(SoLoud::Soloud::CLIP_ROUNDOFF);
}
void audio_soloud_pause() {
soloud.setPauseAll(1);
}
void audio_soloud_resume() {
soloud.setPauseAll(0);
}
void *audio_soloud_track_play(const char *fname, int looping, float vol, int *handle) {
char path[256];
sprintf(path, "%s/%s.wav.ogg", AUDIO_FOLDER, fname);
auto *w = new SoLoud::WavStream;
w->load(path);
w->setVolume(vol);
w->setLooping(looping ? true : false);
int h = soloud.play(*w, vol * config.music_volume);
if (h)
*handle = h;
return w;
}
void *audio_soloud_voice_track_play(const char *fname, int looping, float vol, int *handle) {
char path[256];
sprintf(path, "%s/%s.wav.ogg", AUDIO_FOLDER, fname);
auto *w = new SoLoud::WavStream;
w->load(path);
w->setVolume(vol);
w->setLooping(looping ? true : false);
int h = soloud.play(*w, vol);
if (h)
*handle = h;
return w;
}
void audio_soloud_track_stop(void *s, int handle) {
auto *w = (SoLoud::WavStream *)s;
w->stop();
delete w;
}
void audio_soloud_track_set_volume(int h, float vol) {
soloud.setVolume(h, vol * config.music_volume);
}
float audio_soloud_track_fade(int h, float volume_start, float volume_end, uint32_t time_start, uint32_t time_end) {
float volume_delta = volume_end - volume_start;
float time_delta = time_end - time_start;
float delta = cur_delta - time_start;
float new_volume = volume_start + (delta / time_delta) * volume_delta;
soloud.setVolume(h, new_volume * config.music_volume);
return new_volume;
}
void *audio_soloud_sound_load(const char *fname) {
auto *w = new SoLoud::Wav;
w->load(fname);
return w;
}
void audio_soloud_sound_play(void *s) {
auto *w = (SoLoud::Wav *)s;
soloud.play(*w);
}
void audio_soloud_set_global_volume(float vol) {
soloud.setGlobalVolume(vol);
}
}
#endif