MIDI.js icon indicating copy to clipboard operation
MIDI.js copied to clipboard

Consuming a lot of ram

Open om3g4zell opened this issue 6 years ago • 5 comments

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 ?

om3g4zell avatar Jan 31 '19 23:01 om3g4zell

Chrome tab*

om3g4zell avatar Feb 01 '19 17:02 om3g4zell

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 avatar Feb 03 '19 22:02 hmoffatt

@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.

shivrajsa avatar Apr 19 '19 03:04 shivrajsa

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.

hmoffatt avatar Apr 23 '19 02:04 hmoffatt

Thank you @hmoffatt

shivrajsa avatar Apr 25 '19 08:04 shivrajsa