schellingb / TinySoundFont

SoundFont2 synthesizer library in a single C/C++ file
MIT License
608 stars 71 forks source link

Convert attenuation from centibels to decibels #85

Open spazzylemons opened 5 months ago

spazzylemons commented 5 months ago

Attenuation is currently used as a decibel value. However, the SoundFont Technical Specification describes initialAttenuation as being in centibels. Due to this, regions with a nonzero attenuation value are much quieter than they should be. This simple fix divides the attenuation by 10 when calculating note gain to perform the conversion.

Note how the lead organ in this MIDI (about 20 seconds in) is far quieter before the change, but after the change, it much more closely resembles FluidSynth's output.

Before fix:

https://github.com/schellingb/TinySoundFont/assets/25674682/2851a4cd-eeea-44b2-a0bb-c11af4cbc8eb

After fix:

https://github.com/schellingb/TinySoundFont/assets/25674682/6277b128-fb02-4e28-b452-48d0fc46b7f8

FluidSynth for reference:

https://github.com/schellingb/TinySoundFont/assets/25674682/eeeb8753-4b5a-4e01-a617-81aae3241e9e