FluidSynth / fluidsynth

Software synthesizer based on the SoundFont 2 specifications
https://www.fluidsynth.org
GNU Lesser General Public License v2.1
1.89k stars 259 forks source link

Modulation envelope attack is linear instead of convex #153

Closed derselbst closed 5 years ago

derselbst commented 8 years ago

According to the 2.01/2.04 spec, both the volume and modulation envelopes should have a convex attack phase. FluidSynth correctly uses a convex attack for the volume envelope, but uses a linear attack for the modulation envelope.

You can hear the difference by comparing the two "modulation envelope test" OGG recordings (inside attached archive) between the Audigy 2 ZS and FluidSynth. In the recording, you will hear a single note playing through all stages of a modulation envelope that is mapped to the note's pitch. Hear the difference in the speed/curve of the initial rise in the note's pitch. The similarly-named .mid and .sf2 files can be used to test this yourself.

Reported by: mrbumpy409

Original Ticket: fluidsynth/tickets/155

derselbst commented 8 years ago

Hi,

The recording is a very good demonstration. We can hear easly the fluidsynth attack for the modulation enveloppe that sounds 'linear'.

For fluidsynth modulation enveloppe: After looking the code it works like you have experimented. (i.e linear attack instead of convex). In fact alls segments (attack,decay,release) are linear.

For fluidsynth amplitude enveloppe After looking the code

Conclusion: Attack for both enveloppes (modulation and amplitude)are not correct versus spec 2.01.

regards

Original comment by: jjceresa

derselbst commented 8 years ago

Actually, the amplitude envelope is correct, because the curves are being calculated in decibels.

If you view the output of the amplitude envelope in a wave editor, it will appear to have a linear attack and a concave decay and release: amp-envelope-normal

But if you view it on a decibel scale, you will see it is correct, with a convex attack and a linear decay and release: amp-envelope-dB

This output is correct to the spec, and matches the output of my Audigy 2 ZS as well.

Original comment by: mrbumpy409

derselbst commented 8 years ago

Hi, Now i understand want you mean. In fact the shape of the volume envelope described by the specs. is the shape of what we hear (i.e the logarithmic response of our ear). Effectively during attack this response is convex.

Now, for modulation envelope attack to get convex shape, do you think that the same kind of function (i.e logaritmic) is suitable ?

Original comment by: jjceresa

derselbst commented 8 years ago

I'm not sure, since I'm not a coder. Perhaps somebody else can answer this?

Original comment by: mrbumpy409

derselbst commented 8 years ago

Now that I have had time to experiment with this, I am finding that I prefer FluidSynth's current mod envelope attack (linear) vs. the spec (convex). A linear attack actually makes more sense for a modulation envelope. For example, if you set the mod envelope to a 1 sec. attack and 1 sec. decay to cause a note's pitch to rise and then fall, you would expect the rise and fall to be along a similar slope. Using a convex attack curve results in a very quick initial rise that slows down as it reaches the top, which sounds weird, in my opinion.

So our options are: 1) Keep the mod envelope attack linear, which makes more sense musically, but results in inaccurate rendering of some presets designed on SB hardware or other SoundFont synths. 2) Go for maximum compatibility with the spec, even if the result isn't as musically strong. This will increase compatibility with older SoundFonts.

Opinions?

Original comment by: mrbumpy409

derselbst commented 8 years ago

Hi, From your experiment, it seems that both options are useful. In this case, theses options could be added (via API, shell commands). Unfortunately i don't have SB hardware to compare the sound difference. I was wondering if you have the possibility to produce a short audio demo (Fluidsynth vs SB) ?.

Original comment by: jjceresa

derselbst commented 8 years ago

Here are some audio examples so you can hear the difference between the convex mod envelope attack (Audigy, SF spec) and the linear mod envelope attack (FluidSynth).

  1. Mod envelope to pitch: Both attack and decay are set to 2 seconds in length. Audigy: You can hear how the Audigy sweeps the pitch up very quickly at first, slowing as it reaches the high point. FluidSynth: In FluidSynth, the slope of the attack and decay are identical (linear).

  2. Mod envelope to filter cutoff: Both attack and decay are set to 2 seconds in length. Audigy: The filter opens very quickly and then hangs out at an open level for a while before the decay kicks in. FluidSynth: Unlike the Audigy, Fluidsynth has a very even sweep up and down.

  3. GeneralUser GS "Sweep Pad" Here is an example of a real-world preset that is greatly affected by the shape of the modulation envelope attack curve. The original version of this preset was programmed for the Sound Blaster hardware synths, on which it sounds like this (Audigy). However, the same preset loaded into FluidSynth sounds like this instead. The attack sounds way too slow on FluidSynth. Both the Audigy and FluidSynth are playing a roughly 6.5 second attack phase, but the convex curve on the Audigy causes the filter sweep to happen much more quickly at the beginning of the attack phase. The downside to the convex curve here is that the full 6.5 seconds must elapse before the decay phase can begin, which can seem like forever if you want to create a sweep up and down effect.

For the most recent versions of GeneralUser GS, I have re-programmed "Sweep Pad" to sound correct with FluidSynth, using an attack time of roughly 1.75 seconds instead of 6.5. Here is what the new version sounds like using FluidSynth, and here is what it sounds like on the Audigy. Now FluidSynth sounds correct and the Audigy's filter opens too quickly.

So, you can see the problem, but the question remains: what is the ideal solution? To review the options:

  1. Keep the mod envelope attack linear, which makes more sense musically, but results in inaccurate rendering of some presets designed on SB hardware or other SoundFont synths.
  2. Go for maximum compatibility with the spec, even if the result isn't as musically strong. This will increase compatibility with older SoundFonts.

Original comment by: mrbumpy409

derselbst commented 8 years ago

Thanks for the time to produce this good demonstration. All audios examples are manifest and anyone can hear the problem clearly.

My opinion is that any musical need should not be limited by any technology or specification. It is obvious that the SoundFonts format which is a great idea should be updated with new functionalities. For example the shape of the attack/decay/release segment could be chosen with new 'Generator shape property' (ie.concave,linear,convex).

But for now he question remains: what is the ideal solution? Actally,I don't see an ideal solution, but

First: The least worst solution could be going for the maximum compatibilty (option 2 above). Increasing compatibily with older soundfonts is very important. Consequently that means that fluidsynth should be updated to have a default convex shape for Modulation Attack segment.

Second, the actual linear shape for Mod Attack, seems to be musically useful. So keeping this option inside Fluidsynth would be interesting (option 1 above). Whith the help of a setting, command, or API the synthesizer could be set in this option (linear or convex).

Of course that means that at Soundfont design time, we always need to think and maintain two set of Soundfonts; the one working only with the default convex shape and the other working only with the linear shape.

jean-jacques ceresa.

Original comment by: jjceresa

derselbst commented 8 years ago

Yeah, I would also vote for going with the spec. I have had to maintain separate Audigy vs. FluidSynth versions of GeneralUser GS mainly due to this very issue. Providing a curve option is not a bad idea, although I tend to think that if you want to be able to customize envelope curves and filter types, etc., that is what a sampler format such as SFZ is for.

Original comment by: mrbumpy409

mrbumpy409 commented 7 years ago

modulation envelope test.tar.gz

Here are the test files from my original bug report on the SourceForge bug tracker.

jjceresa commented 6 years ago

Here are the test files from my original bug report on the SourceForge bug tracker.

Hello, (since more than one year now !).Thanks a lot for this important missing archive.

although I tend to think that if you want to be able to customize envelope curves and filter types, etc., that is what a sampler format such as SFZ is for.

Not yet familiar with this format, after a quick look there are SFZ 1.0 and SFZ 2.0 and both are official but only SFZ 1.0 is documented. Did you know if SFZ 2.0 documentation is accessible elsewhere ? or may be could you advice about preference between both ?

mrbumpy409 commented 6 years ago

The "official" documentation on the SFZ 2.0 specs was only ever published in the book Cakewalk Synthesizers: From Presets to Power Userhttps://www.amazon.com/Cakewalk-Synthesizers-Presets-Power-User/dp/1435455649/. However, fairly comprehensive documentation can also be found at the following links:

You can also find a good discussion group for SFZ programming herehttps://plogue.com/phpBB3/viewforum.php?f=14.

Peace,

-~Chris

On 12/23/2017 12:56 PM, jjceresa wrote:

Here are the test files from my original bug report on the SourceForge bug tracker.

Hello, (since more than one year now !).Thanks a lot for this important missing archive.

although I tend to think that if you want to be able to customize envelope curves and filter types, etc., that is what a sampler format such as SFZ is for.

Not yet familiar with this format, after a quick look there are SFZ 1.0 and SFZ 2.0 and both are official but only SFZ 1.0 is documented. Did you know if SFZ 2.0 documentation is accessible elsewhere ? or may be could you advice about preference between both ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/FluidSynth/fluidsynth/issues/153#issuecomment-353742424, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AGgnPRBUVjgnFNZ_VbFkncDxx1kCyOfwks5tDUz0gaJpZM4On3po.

jjceresa commented 6 years ago

Many thanks for the hints! jjc

derselbst commented 6 years ago

Second, the actual linear shape for Mod Attack, seems to be musically useful. So keeping this option inside Fluidsynth would be interesting. [...] Of course that means that at Soundfont design time, we always need to think and maintain two set of Soundfonts;

The fact that fluidsynth uses a linear modenv attack is a bug. The spec is absolutely clear to use a convex shape (whether we like it or not). And because to avoid having to think about two versions of soundfonts out there, I dont want to introduce any setting for this.

derselbst commented 5 years ago

Implemented by #406.