Consuming a lot of ram
Hi,
Is there another way to load an instrument than :
MIDI.loadResource({
instrument: instrumentid,
onprogress: function (state, percent) {
console.log(state, percent);
},
onsuccess: function () {
console.log("onSuccess : " + instrumentid);
MIDI.programChange(channel, instrumentid);
}
});
Because each time I load an instrument the google tab has an increase of 100Mb of ram. If there is no other way to load them can we unload instruments ?
Chrome tab*
On load it decompresses all the samples back to raw PCM audio. The sound fonts (if generated with the included soundfont builder script) have 3 seconds of stereo audio for 80+ notes.. that is where your 100Mb+ per instrument comes from.
I reduced it in my application by trimming silence in the sound fonts so that they are not all 3 seconds. That will help for any instrument sound that decays, like a piano, or drums. It helps for drums especially because some of the notes do not even have a sound - with the original script you have 3 seconds of silence loaded!
@hmoffatt , Could you please share how you have managed to trim silence in the audio file ? Is there any quick way to process all samples in single operation ? please guide.
I modified the converter (soundfont_builder.rb) to run sox before encoding in order to strip off the silence. The extra line is
run_command "#{SOX} #{target}.orig.wav #{target} reverse silence 1 0.1 0 pad 0.0001@0 reverse channels 1"
I haven't published my whole modified script anywhere as it has other unrelated changes but you get the idea from the above.
Thank you @hmoffatt