Skip to content

Commit 81695a8

Browse files
committed
feat: add changing voices in JS
1 parent 4de9fd5 commit 81695a8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

audioengine.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ static tsf *g_TinySoundFont = NULL;
1111

1212
static bool run;
1313
int volume = 100;
14+
int voices = 200;
1415

1516
static bool renderAudio(int numInputs, const AudioSampleFrame *inputs,
1617
int numOutputs, AudioSampleFrame *outputs,
@@ -39,7 +40,7 @@ void load(uintptr_t data, int length)
3940
if (recreating)
4041
{
4142
tsf_set_output(g_TinySoundFont, TSF_MONO, 44100, 0);
42-
tsf_set_max_voices(g_TinySoundFont, 200);
43+
tsf_set_max_voices(g_TinySoundFont, voices);
4344
tsf_set_volume(g_TinySoundFont, volume / 100.0f);
4445
}
4546
}
@@ -117,12 +118,22 @@ void set_volume(int vol)
117118
tsf_set_volume(g_TinySoundFont, vol / 100.0f);
118119
}
119120

121+
void set_voices(int voicez) {
122+
voices = voicez;
123+
tsf_set_max_voices(g_TinySoundFont, voicez);
124+
}
125+
126+
int get_voices() {
127+
return voices;
128+
}
129+
120130
int start()
121131
{
122132
printf("AudioEngine has been started.\n");
123133

124134
tsf_set_output(g_TinySoundFont, TSF_MONO, 44100, 0);
125-
tsf_set_max_voices(g_TinySoundFont, 200);
135+
tsf_set_max_voices(g_TinySoundFont, voices);
136+
tsf_set_volume(g_TinySoundFont, volume / 100.0f);
126137
EmscriptenWebAudioCreateAttributes attr = {
127138
.latencyHint = "playback",
128139
.sampleRate = 44100};
@@ -141,4 +152,6 @@ EMSCRIPTEN_BINDINGS(my_module)
141152
emscripten::function("note_on", note_on);
142153
emscripten::function("set_volume", set_volume);
143154
emscripten::function("get_volume", get_volume);
155+
emscripten::function("set_voices", set_voices);
156+
emscripten::function("get_voices", get_voices);
144157
}

0 commit comments

Comments
 (0)