-
Notifications
You must be signed in to change notification settings - Fork 265
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
Default synth.gain for 2.4.0 and higher of 0.6 is too high #1405
Comments
I meant 2.3.6 composer to 2.4.0 |
ogg format does not clip with 0.6 but for wav, flac, mp3 clipping happens |
Thanks Reinhold for investigating! It seems that using @es20490446e You have introduced the new gain in #1287, any preference of using
OGG is a special case as it uses floats inside libsndfile, which are scaled as postprocessing step to prevent most clippings. |
Thanks for the immediate response. Yes, 0.3 is fine |
I chose 0.6 because it provided a good balanced between foreground dialogs and effects, and background music, when using Fluidsynth on old games. The previous setting of 0.2 made the background music mostly inaudible, and weirdly low when played through the media played compared with non midi music. So I made the volume just a bit lower than non midi files. That didn't result in any clipping I could perceive. Either in the VLC media player, DosBox or Wine. This is by using GeneralUserGs, which samples are a bit quieter than those from the Fluid sound-font. I took GeneralUserGs as reference because I think it's more balanced, realistic and intended for a broader user case. I have tried reproducing the clipping, but I have been unable to. See the used code here: Fluidsynth.zip I have tried:
My system is:
I suspect that my audio processor (Pipewire) or my sound chip (Realtek) prevent the clipping all together. We would need to bisect this. Please:
Also I think that lowering the gain to a very quiet level is really solving nothing. It's just a work-around, and many consumer software will raise the gain to a louder level anyway. |
As said, clipping with gain 0.6 only happens for "audio.driver", "file". Clipping only happens for the audio formats wav, and wav converted to mp3 (with lame), flac (with libFLAC etc). No clipping for ogg (libogg etc). Any other driver like Directsound, WASAPI + exclusive, portaudio + ASIO, Jack is OK. For these other ones I use 0.7 w/o clipping. Arch: Windows 10 latest update With regards to sharing the Dance.mid audio samples I have my concerns. Not sure that these are w/o property rights. In order to be on the safe side I now use the gain setting for "synth.gain" to be initialized for my needs. The problem is now solved for me. My point is that 0.2 has been the default value since ever, at least for the past 10 years. Increasing the default now to 0.6 - all of a sudden with 2.4.0 - causes clipping where I ran into. This could have been avoided. |
I have tested it with:
But the clipping didn't occur. I will need to keep discarding factors. By the way, what is your sound card? |
I did not mention the sound card because for "audio.driver", "file" IMHO the sound card is irrelevant. We hear clipping by a gain of 0.6 on all of the different PC types in our lab: from a 2008 old Intel Core 2 P8400 PC with Windows, on the PC mentioned above, on Linux Wine installations as well as on a Mac with macOS Sequoia running our x64 app on top of Wine on an Apple M-processor where the object code is converted by Rosetta 2 (which is still unbelievable fast). We have our app in thousands of installations in the market since almost 10 years and never had any complain by a customer with the default gain 0.2. Of course, the gain can be modified. But 0.6 is definitely to high. @es20490446e : I respectfully disagree your point that "...lowering the gain to a very quiet level is really solving nothing." It resolves the clipping, definitely. In my view 0.2 is not "very quiet". It is more quiet than 0.6. For me, 0.3 is a very good value. To me a "default value" should cover most of the cases. Changing a default value which is in place for so long due to a special configuration (old games, Linux, Pipewire etc.) is not the right step. In such as case the gain should be set by fluid_settings_setnum(s_settings, "synth.gain", 0.6f); as you did it in your examples (when I read them correctly) but not by changing the "default value" in the fluidsynth code. As said above, the problem is resolved for us. We initialize the value in the future for our needs. @derselbst: in case of a change from 0.2 to something new please do not forget to change print_help in fluidsynth.c "Set the master gain [0 < gain < 10, default = 0.2]" |
That's why I'm asking you if you could provide some recorded file where you hear clipping, and that I can try rendering on my machine too. So if I notice a difference between the two resulting files, to figure out why I'm not hearing any clipping at all. In general I'm against changing anything that will break retrocompatibility, but I suspect that in this instance we are rather exposing a defect that needs to be addressed in a different fashion. |
For the moment being I have been unable to reproduce it on Arch Linux with pipewire, or Ubuntu with PulseAudio. I tried testing it on Windows, but it took several hours to set up and I finally gave up. |
To reproduce, just grab GeneralUser v2 and exec:
No, the clipping isn't really audible, yet it's there at around 40s: I can confirm that the sound card doesn't play a role in case of file rendering.
Oh, it's hardcoded - good point! |
By using these:
I got this:
Hence my opinion is:
|
The point is that doing so would be a conscious user decision. And if clipping is audible, the user will know how to mitigate it. I consider it more important to set the gain to a default value that will work in all circumstances rather than producing a rendered file that contains potentially clipped audio. I don't think it's worth to haggle about Yet, thanks to both of you @es20490446e and @ReinholdH for looking into this!
Agreed. PR welcome. |
Well, the difference between What I see is that:
This is all I have to say. The choice is yours. |
I always use a gain of 0.4 or 0.5, and have been recommending people set their gain to 0.5 when using GeneralUser GS as a compromise between volume and clipping. I find the clipping at 0.5 to not be audibly noticeable, and the reality is that MIDI files vary wildly in their overall dynamic output, so I try to find a reasonable middle ground. When rendering to audio, I always use 32-bit floating point which avoids actually clipping the audio—I just need to attenuate and trim the file a bit before exporting to its final format. |
Do you notice problems with 0.6? |
Just more clipping. In the past I always used 0.4, but when testing for recommended values for GeneralUser GS, 0.5 seemed the best compromise for casual MIDI playback. It results in a good volume level, and any clipping isn't really noticeable to the ear, though I'm sure there's some MIDI file out there that will slam all CC7 = 127, all velocity = 127 & a bazillion notes, which will lead to significant clipping. On the other hand, I found many MIDI files that run rather quiet even at 0.5 gain. |
One other thought: adding a properly-configured limiter to the end of the audio signal path would be one way to avoid clipping, acknowledging that the dynamic range would be affected by the use of a limiter. As an example of how this would sound, have a listen to the audio renderings of the MIDI files included with GeneralUser GS 2.0, which are in a subfolder of the MIDI files. All of these files were rendered to 32-bit FP WAV using FluidSynth, in some cases amplified a bit, and then a limiter was applied to tame the peaks to -0.5 dB (to allow dynamic headroom for conversion to OGG), allowing the volume of each MIDI file to be enjoyably loud. |
I would say that slightly compressing the dynamic range is even desirable, as it allows sounds to be noticeable at not so loud volumes. In the last months I have been working on an audio system. After plenty of listening sessions what I noticed is that it was better to configure the audio processor to have a subtly compressed dynamic range, rather than a sound that was as deep and natural as real life. Because a slightly compressed audio allows you to listen to content without disturbing your family and neighbors. |
Personally, I wouldn't implement more than a peak limiter, as many people would be averse to messing too much with the dynamic range of the MIDI files (myself included). For good results, a compressor really should be set up differently depending on the type and level of the music playing (this is why you can't really automate the mastering process). A peak limiter, however, could be set to a reasonable default and would have minimal impact on the dynamic range of the music, only serving to prevent clipping in those moments where the sound is too hot to handle. In some sense, GeneralUser GS uses a different form of "compression", as the bottom dynamic range of most instruments is reduced from the default 96 dB velocity-to-attenuation curve to 70-80 dB instead, allowing for a more controlled dynamic experience than you usually get with General MIDI playback. This also helps offset some of the volume lost due to the lowpass filter used on many instruments at lower velocities (to simulate how most real instruments get mellower when played quietly). |
I mean that if the peak limiter generates a slight compression, probably it won't be a major concern. |
Thanks for your input guys! I have reverted the default gain to its previous safe value 0.2 . |
FluidSynth version
master (as of Sun. Oct. 13th, 2024) to become 2.4.0
Describe the bug
Default "synth.gain" for 2.4.0 and higher of 0.6 is too high
Expected behavior
Some midi files run into clipping now with "audio.driver", "file"
Steps to reproduce
Use Dance.mid from https://schristiancollins.com/generaluser.php which is part of the GeneralUser GS 2.0.0. Clipping happens at ~40 sec.
Additional context
For 2.4.0 and higher the default synth gain is planned to change from 0.2 to 0.6 (see https://www.fluidsynth.org/api/settings_synth.html#settings_synth_gain). I have been doing intensive testing with the upcoming 2.4.0 and ran into this issue. Of course, the gain can be initialized with fluid_synth_set_gain. But going from 2.6.3 to 2.4.0 requires a code change now. It took me quite some time to find out why Dance.mid is now clipping in audio export files but is not in 2.6.3.
Of course, using fluid_synth_set_gain to initialize the gain is always a good idea.
The text was updated successfully, but these errors were encountered: