Open spessasus opened 4 months ago
I will delay a bit the work on the sf2 / sf3 parser since I need more time to do and test it:
When clicking on a sample in the tree, I'll also add a checkbox (which will be also a warning) so that we can decide if we want the compressed or raw version of the waveform.
Hi Davy,
I have a slightly different idea on handling the samples. Instead of a modified attribute, I think a sample would have a compressed
boolean. And two data arrays: compressed data and uncompressed data. When polyphone loads the soundfont, it loads the compressed data and decompresses it into another table and uses it for playback. For the uncompressed samples, the compressed data table is empty.
When I open a sample in Polyphone, it could show at the bottom "sample type: compressed" or something like that. It would not decompress the sample.
Once the user clicks yes, the compressed flag is set to false and the compressed array gets deleted, leaving only the uncompressed array.
When saving the soundfont, simply check for the compressed boolean. If true, copy the compressed data (and adjust the sample index and loop points) and add the compressed flag to sampleType. If the boolean is false, copy the uncompressed data and save as an usual sf2 sample (and always zero the 4th bit of sampleType because the sample might've been compressed)
I've implemented this logic in my soundfont code
This function returns the "raw data" which gets directly copied into the file. As you can see, it copies the compressed data if the sample is compressed and uncompressed data otherwise.
Let me know what you think about my version and thanks for considering this feature!
The Issue
SF3 uses Ogg Vorbis compression, which is lossy. This poses a problem because loading an SF3 into Polyphone and saving it again decompresses and then recompresses the samples, leading to a loss in quality.
The Solution
I propose that Polyphone should preserve compressed samples instead of decompressing them. With issue #201 now fixed, here’s how the logic could be adjusted:
Loading an .sf3 Soundfont
Exporting an .sf3 Soundfont
When Exporting .sf3
When Exporting .sf2
ifil
to 2 and adjustsampleType
to remove the compression flag.This approach avoids unnecessary decompression and recompression, thus preserving sample quality.
Let me know what you think!