This guide demonstrates how to convert various file formats using spessasynth_core.
Whether you're working with SoundFont files (SF2, SF3),
Downloadable Sounds (DLS), or MIDI-related formats (RMI, MIDI), these examples will help you perform conversions quickly
and efficiently.
Important
The input file binary is named input
and the output binary file is named output
in the examples.
constsfont=SoundBankLoader.fromArrayBuffer(input);awaitsfont.setSampleFormat({format:"compressed",compressionFunction:SampleEncodingFunction// make sure to get the function for compression});constoutput=sfont.writeSF2();
constmid=BasicMIDI.fromArrayBuffer(input1);constsfont=SoundBankLoader.fromArrayBuffer(input2);// compress this if you wantconstsfontBinary=sfont.writeSF2();constoutput=mid.writeRMIDI(sfontBinary,sfont,0,// bank offset: adjust this if necessary"utf-8",// encoding: utf-8 recommended{// all the values below are examples, showing how to copy MIDI data to the RMI filename:mid.getName(),copyright:mid.getExtraMetadata(),engineer:sfont.soundBankInfo.engineer},true// adjust program changes: recommended for self-contained files);
constdlsRMID=BasicMIDI.fromArrayBuffer(input);constsfont=SoundBankLoader.fromArrayBuffer(dlsRMID.embeddedSoundBank);constsfontBinary=sfont.writeSF2();constoutput=dlsRMID.writeRMIDI(sfontBinary,sfont,dlsRMID.bankOffset,// bank offset gets detected for DLS rmi"utf-8",// encoding: utf-8 recommended{// here we try to extract the metadata from the file, then fall back to embedded MIDIname:dlsRMID.getName(),copyright:dlsRMID.rmidiInfo.copyright||dlsRMID.getExtraMetadata(),engineer:sfont.soundBankInfo.engineer,artist:dlsRMID.getRMIDInfo("artist"),album:dlsRMID.getRMIDInfo("album"),genre:dlsRMID.getRMIDInfo("genre"),comment:dlsRMID.getRMIDInfo("comment"),// either use the embedded one or todaycreationDate:dlsRMID.getRMIDInfo("creationDate")??newDate()},false// adjust program changes: I recommend false for that one);