ryohey / signal

Online MIDI Editor: signal
https://signal.vercel.app
MIT License
1.22k stars 137 forks source link

Wario Master of Disguise soundfont doesnt work #290

Closed ExGuestCJ closed 1 month ago

ExGuestCJ commented 7 months ago

Describe the bug This soundfont doesnt work, when i add it and open it, theres a message saying "todo" and then it doesnt let me use it

Expected behavior Being able to use the soundfont

Screenshots image

robertnhart commented 4 months ago

It looks like Signal can't handle a soundfont with 24-bit samples.

As a workaround, you might be able to use a soundfont editor to make a 16-bit version of the soundfont.

For example, in the Polyphone soundfont editor, you can open the soundfont, change the "Samples" dropdown box from "24 bits" to "16 bits", then save as a new soundfont. That seems to make it into a 16-bit soundfont which works in Signal.

polyphone-16-bit

robertnhart commented 2 months ago

I did a quick look at the sf2 format by reading this document:

SoundFont2 Structure - sdta Chunk

It looks like an sf2 file can store either 16-bit sounds or 24-bit sounds. When 24-bit sounds are used, it looks like they are actually stored as 16-bit sounds plus data for the additional 8 bits.

The "TODO" error message comes the following place in this file:

node_modules\@ryohey\sf2parser\src\Parser.ts

function parseSdtaList(chunk: Chunk, data: Uint8Array): Chunk {
  const chunkList = getChunkList(chunk, data, "LIST", "sdta")

  if (chunkList.length !== 1) {
    throw new Error("TODO")
  }

  return chunkList[0]
}

(see source code at npm @ryohey/sf2parser Code src/Parser.ts or GitHub ryohey/sf2synth.js Parser.ts)

According to my tests, it looks like you can remove if (chunkList.length !== 1) { throw new Error("TODO") } so this function will always return chunkList[0] and it seems to just use the highest 16 bits of 24-bit sounds.

If you want to try out this change, I wrote some code you can use to patch Signal using the browser console or a JavaScript bookmark: Signal Customizations

ryohey commented 2 months ago

thanks @robertnhart I will fix it.

we can ignore 8bit lsb as you say i can find some real codes which handles correctly. I might do same thing that treats samples as 32bit

https://github.com/FluidSynth/fluidsynth/blob/master/src/sfloader/fluid_sffile.c#L2206

https://github.com/FluidSynth/fluidsynth/blob/f9bde410216766c1117cd07b349740e9804773ca/src/rvoice/fluid_rvoice.h#L228