Reputation: 45
I'm using MIDI.js to play accordion notes using a custom SoundFont mapped in accordion-mp3.js. The SoundFont appears to load successfully, but no sound is played when triggering notes with MIDI.noteOn and MIDI.noteOff. Additionally, no HTTP requests for individual .mp3 files are being made.
My Setup:
SoundFont Mapping in accordion-mp3.js:
window.Soundfont = window.Soundfont || {};
window.Soundfont["accordion"] = {
"C4": "/static/soundfont/accordion/C4.mp3",
"D4": "/static/soundfont/accordion/D4.mp3",
"E4": "/static/soundfont/accordion/E4.mp3",
// ... other mappings
};
MIDI.js Initialization:
MIDI.loadPlugin({
soundfontUrl: "/static/soundfont/",
instrument: "accordion",
targetFormat: "mp3", // Explicitly setting the format
onsuccess: function () {
console.log("SoundFont loaded successfully!");
MIDI.noteOn(0, 60, 127, 0); // Play Middle C
MIDI.noteOff(0, 60, 1); // Stop after 1 second
console.log("Test note played via MIDI.js.");
},
onerror: function (error) {
console.error("Error loading SoundFont:", error);
},
});
Expected Behavior:
MIDI.js should request .mp3 files from /static/soundfont/accordion/ (e.g., C4.mp3). Notes should play when MIDI.noteOn and MIDI.noteOff are called.
Actual Behavior:
The onsuccess callback logs that the SoundFont is loaded. No sound is played when calling MIDI.noteOn. No HTTP requests for .mp3 files are made.
Debugging Steps:
Verified that accordion-mp3.js is loaded, and MIDI.Soundfont["accordion"] exists:
console.log(MIDI.Soundfont["accordion"]); // Logs correct SoundFont object
Checked that MIDI.js is loaded:
console.log(window.MIDI ? "MIDI.js is loaded!" : "MIDI.js is not available."); // Logs: MIDI.js is loaded!
Confirmed that the Web Audio API is supported:
console.log(!!window.AudioContext); // Logs: true
Browser: Chrome 131 on macOS (Sequoia) MIDI.js: https://github.com/mudcube/MIDI.js
My Questions: Why isn't MIDI.js making requests for .mp3 files when calling MIDI.noteOn? How can I debug why no sound is being played?
Upvotes: 0
Views: 27