-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfmaw_sound.fds
97 lines (74 loc) · 1.67 KB
/
fmaw_sound.fds
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
// Copyright 2015 FMAW
#include "./fmaw_sound.h"
#include <nds.h>
#include <maxmod9.h>
#include <map>
#include "./soundbank_bin.h"
namespace FMAW {
namespace Sound {
std::map<int, mm_sound_effect> specialEffects;
bool inited = false;
bool backgroundPlaying = false;
FX effectWithSoundID(int ID) {
FX effect;
effect.id = ID;
effect.rate = (static_cast<int>(1.0f * (1 << 10)));
effect.handle = 0;
effect.volume = 255;
effect.panning = 127;
return effect;
}
void init() {
if (!inited) {
inited = true;
mmInitDefaultMem((mm_addr)soundbank_bin);
mmSetModuleTempo(0x4FF);
}
}
int registerFX(FX fx) {
init();
mmLoadEffect(fx.id);
mm_sound_effect effect = {
{ fx.id },
fx.rate,
fx.handle,
fx.volume,
fx.panning
};
specialEffects[specialEffects.size()] = effect;
return specialEffects.size() - 1;
}
playID playEffect(int effectID) {
mm_sound_effect effect = specialEffects[effectID];
mm_sfxhand reproduction = mmEffectEx(&effect);
return -1;
}
bool stopEffect(playID reproductionID) {
return false;
}
void setBackgroundMusic(int musicID) {
mmLoad(musicID);
mmStart(musicID, MM_PLAY_LOOP);
backgroundPlaying = true;
}
void stopBackgroundMusic() {
backgroundPlaying = false;
mmStop();
}
void pauseBackgroundMusic() {
backgroundPlaying = false;
mmPause();
}
void resumeBackgroundMusic() {
backgroundPlaying = true;
mmResume();
}
void toggleBackgroundMusic() {
if (backgroundPlaying) {
pauseBackgroundMusic();
} else {
resumeBackgroundMusic();
}
}
} // namespace Sound
} // namespace FMAW