Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] Support for more bitdepths #4

Open
sylvia-leaf opened this issue Feb 8, 2025 · 6 comments
Open

[FEATURE REQUEST] Support for more bitdepths #4

sylvia-leaf opened this issue Feb 8, 2025 · 6 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@sylvia-leaf
Copy link

Is your feature request related to a problem? Please describe.
Currently, SpessaSynth is fixed to 16-bit samples. This means that it cannot use SF2.04 and some SFe banks with full sound quality.

Is your feature related to the sound library or the app/website?
App/website

Describe the solution you'd like
Support for the sm24 and sm32 (SFe) sub-chunks. Additionally, 8-bit sample playback with the SFe-static (8-bit) bank type for SFe.

Describe alternatives you've considered
n/a

Additional context
n/a

@sylvia-leaf sylvia-leaf added the enhancement New feature or request label Feb 8, 2025
@sylvia-leaf sylvia-leaf moved this to Backlog in SFe 4 format Feb 8, 2025
@sylvia-leaf sylvia-leaf added this to the v3.24.1-SFe milestone Feb 8, 2025
@spessasus
Copy link

I think this is going to be relatively easy one, I think. Spessasynth currently stores the smpl chunk in memory and converts the samples to Float32 on-demand, so changing it to reference the original array (entire soundfont, which is also stored in memory) instead of just the smpl chunk and calculating the byte offset to find the correct bytes in the sm24 and 32 chunks to form the full number would work.

Linking the relevant code for reference:
https://github.com/spessasus/SpessaSynth/blob/f9d8050814e56be625885d2d9d3fc5241cef777e/src/spessasynth_lib/soundfont/read_sf2/samples.js#L175-L187

@sylvia-leaf
Copy link
Author

If I wanted to implement 32-bit PCM samples, would I also need to mess around with float64? I don't think that float64 would be required for 24-bit PCM, and for 8-bit PCM we would probably not even need float32.

The smaller the float numbers required, the better, as it improves the efficiency of the program, allowing more samples to be used for the same amount of memory usage.

@spessasus
Copy link

spessasus commented Feb 16, 2025

Spessasynth is a 32-bit float synth, and that cannot be changed. Though I think that 24-bit and 32-bit will both be easy since it's just a matter of adjusting the code I've linked above

@sylvia-leaf
Copy link
Author

So, there won't be any quality loss when converting 32-bit PCM to 32-bit float? This is good, because SFe 4.0 defines an sm32 sub-chunk. Of course we don't expect many people to be using it with 32-bit chunk headers, because it does use 33% more space for not much sound quality improvement, but when we add a large amount of 64-bit support, it will become more important.

To complete this, we will need to add code that:

  • loads the contents of sm24 and sm32
  • Add more code that combines smpl data with extra chunks
  • Convert the 24-bit or 32-bit data to float
  • Detect an SFty value of 8-bit and ignore smpl

@sylvia-leaf
Copy link
Author

I've made a few changes to the code that allows the loading of 24-bit data. However, it does not yet combine the data.

However, it's unclear to me whether the sampleDataArray that we slice into 16-bit samples is actually an array of 16-bit values, because everything says it's a Float32Array, but that doesn't make sense. Which one is it?

@spessasus
Copy link

Samples are 16-bit. By dividing them by 32768 (maximum value of 16-bit sample), we convert them to -1 to 1 range which float uses. The precision is still 16-bit, just the data type is float32. It's like converting 8 bit to 16:

byte << 8

So you essentially need to combine the samples to create a int32 (or 24bit) number and divide it by int32 max

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

2 participants