-
Notifications
You must be signed in to change notification settings - Fork 11
Converting Between Formats
spessasus edited this page Oct 15, 2024
·
2 revisions
This guide demonstrates how to convert various file formats using spessasynth_lib
.
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.
Note
This example uses soundfont3 compression. Make sure you've read this
const sfont = loadSoundFont(input);
const output = sfont.write({
compress: true,
compressionQuality: 0.5, // adjust this to your liking
compressionFunction: EncodeVorbisFunction // make sure to obtain the function for compression
});
const sfont = loadSoundFont(input);
const output = sfont.write();
const RMID = new MIDI(input);
const output = writeMIDIFile(RMID);
const RMID = new MIDI(input);
const sfont = loadSoundFont(RMID.embeddedSoundFont);
const output = sfont.write();
This uses two inputs, input1
for MIDI and input2
for SoundFont.
const mid = new MIDI(input1);
const sfont = loadSoundFont(input2);
// compress this if you want
const sfontBinary = sfont.write();
const output = writeRMIDI(
sfontBinary,
mid,
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 file
name: mid.midiName,
copyright: mid.copyright,
engineer: sfont.soundFontInfo["IENG"],
},
true // adjust program changes: recommended for self-contained files
);
const dlsRMID = new MIDI(input);
const sfont = loadSoundFont(dlsRMID.embeddedSoundFont);
const sfontBinary = sfont.write();
const output = writeRMIDI(
sfontBinary,
dlsRMID,
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 MIDI
name: dlsRMID.RMIDInfo["INAM"] || dlsRMID.midiName,
copyright: dlsRMID.RMIDInfo["ICOP"] || dlsRMID.copyright,
engineer: sfont.soundFontInfo["IENG"],
artist: dlsRMID.RMIDInfo["IART"],
// both IPRD and IALB represent album name
album: dlsRMID.RMIDInfo["IPRD"] || dlsRMID.RMIDInfo["IALB"],
genre: dlsRMID.RMIDInfo["IGNR"],
comment: dlsRMID.RMIDInfo["ICMT"],
// either use the embedded one or today
creationDate: dlsRMID.RMIDInfo["ICRD"] || new Date().toDateString()
},
false // adjust program changes: recommend false for that one
);
Tip
If you encounter any errors in this documentation, please open an issue!
Warning
Make sure you always update worklet_processor.min.js
along with the npm package!