osxmidi / SFZero-X

Linux SFZ Player
Other
25 stars 2 forks source link

Sustain pedal realism #4

Closed geckolinux closed 3 years ago

geckolinux commented 3 years ago

Hi there, Ever since I got into Linux audio for playing the piano with my MIDI keyboard, I noticed a unique, subtle trait of LinuxSampler that made it feel distinctly more natural. With a sustain pedal, LinuxSampler allows for sustaining the residual resonance even after releasing all the keys. So basically, on a real piano, you hit some notes fairly hard, completely release them all, and then before their resonance dies out immediately hit the sustain pedal, and the residual resonance will continue for quite a while. LinuxSampler faithfully reproduces this behavior ( even with SF2 soundfonts), and to my knowledge it's the only free sampler that does this. SFZero-X does not either. Even the Sforzando player for Windows which is generally regarded as the standard for free SFZ players doesn't do this. Apart from LinuxSampler, the only thing on my system that also has proper sustain behavior is the commercial Pianoteq app. But the problem is that LinuxSampler doesn't seem to exist as a Linux VST (only for Windows apparently?) so it's hard to use it with other DAWs and synthesizer apps. Would it be possible to implement this behavior on SFZero-X? Thanks a lot!

osxmidi commented 3 years ago

Hi there, Ever since I got into Linux audio for playing the piano with my MIDI keyboard, I noticed a unique, subtle trait of LinuxSampler that made it feel distinctly more natural. With a sustain pedal, LinuxSampler allows for sustaining the residual resonance even after releasing all the keys. So basically, on a real piano, you hit some notes fairly hard, completely release them all, and then before their resonance dies out immediately hit the sustain pedal, and the residual resonance will continue for quite a while. LinuxSampler faithfully reproduces this behavior ( even with SF2 soundfonts), and to my knowledge it's the only free sampler that does this. SFZero-X does not either. Even the Sforzando player for Windows which is generally regarded as the standard for free SFZ players doesn't do this. Apart from LinuxSampler, the only thing on my system that also has proper sustain behavior is the commercial Pianoteq app. But the problem is that LinuxSampler doesn't seem to exist as a Linux VST (only for Windows apparently?) so it's hard to use it with other DAWs and synthesizer apps. Would it be possible to implement this behavior on SFZero-X? Thanks a lot!

Hi,

Do you want something like

if notes are already sounded, then once the “sustain” is activated they should be affected by the sustain. And if you release the pedal, but the keys are still held, the notes should continue to play.

osxmidi commented 3 years ago

https://linuxmusicians.com/viewtopic.php?t=12921


and I have got

ampeg_releasecc64=3

where the sustain pedal midicc would be 64 and the release time would be 3 seconds

but that would need to be added to the sfz file.

geckolinux commented 3 years ago

Do you want something like if notes are already sounded, then once the “sustain” is activated they should be affected by the sustain. And if you release the pedal, but the keys are still held, the notes should continue to play.

Hi there, if I understand correctly that's already the default behavior with SFZero. I was referring to the sustain pedal continuing to sustain the decayed resonance of the released keys. For example if the resonance of a released key decays to nothing in 500ms, then I would expect if I release a key and 200ms later depress the sustain pedal that it would continue to sustain what was left of the resonance for several seconds more. This is the behavior with a real piano, with Pianoteq, and with LinuxSampler.

I also noticed another quirk that is unique to SFZero: When I press a key or various keys, depress the sustain pedal, release the keys, and then with the sustain pedal still down if I lightly press those same keys it kills the resonance. Normally what would happen is that the resonance would continue at the same rate of decay as long as the sustain pedal is pressed.

Thanks again for looking into this.

osxmidi commented 3 years ago

Do you want something like if notes are already sounded, then once the “sustain” is activated they should be affected by the sustain. And if you release the pedal, but the keys are still held, the notes should continue to play.

Hi there, if I understand correctly that's already the default behavior with SFZero. I was referring to the sustain pedal continuing to sustain the decayed resonance of the released keys. For example if the resonance of a released key decays to nothing in 500ms, then I would expect if I release a key and 200ms later depress the sustain pedal that it would continue to sustain what was left of the resonance for several seconds more. This is the behavior with a real piano, with Pianoteq, and with LinuxSampler.

I also noticed another quirk that is unique to SFZero: When I press a key or various keys, depress the sustain pedal, release the keys, and then with the sustain pedal still down if I lightly press those same keys it kills the resonance. Normally what would happen is that the resonance would continue at the same rate of decay as long as the sustain pedal is pressed.

Thanks again for looking into this.

I think that what LinuxSampler is doing doesn't seem to be the usual thing.

I'll look into what LinuxSampler is doing but it might take some time as I'm pretty busy with LinVst and other things.

If you could post the sfz file you are using, that might help.

geckolinux commented 3 years ago

Thanks very much, I do appreciate your time. All SFZ soundfonts that I've tried have the same behavior, but this one is the most popular with piano players: https://freepats.zenvoid.org/Piano/SalamanderGrandPiano/SalamanderGrandPiano-SFZ+FLAC-V3+20200602.tar.gz

geckolinux commented 3 years ago

I think that what LinuxSampler is doing doesn't seem to be the usual thing.

I wouldn't be surprised if this is actually a "beneficial bug" of LinuxSampler. At any rate it seems like desirable behavior for most users, although it might be worth including a config option to disable it.

osxmidi commented 3 years ago

I think that what LinuxSampler is doing doesn't seem to be the usual thing.

I wouldn't be surprised if this is actually a "beneficial bug" of LinuxSampler. At any rate it seems like desirable behavior for most users, although it might be worth including a config option to disable it.

So far I've got this,

The sfz spec says

"If the sustain pedal is pressed (MIDI CC number 64 value is 64 or above), sfz does not process MIDI Note Off events until the pedal is released. All Note Off related processing happens at that point (when pedal is released)."


There is also loop_sustain which sfzero-x has but it's not enabled in the code

"loop_sustain: the player will play the loop while the note is held, by keeping it depressed or by using the sustain pedal (CC64). During the release phase, there’s no looping."


There is also

"on_loccN / on_hiccN

If a MIDI control message with a value between on_loccN and on_hiccN is received, the region will play. Default value is -1, it means unassigned.

Sample trigger on MIDI continuous control N. This does not involve playing any MIDI notes. Example #

on_locc64=127 on_hicc64=127

Region will play when a MIDI CC64 (sustain pedal) message with 127 value is received. So, basically, when the sustain pedal is pressed down, this region will play. This is useful with piano pedals - in the above example, on_loccN and on_hiccN could be used to trigger a mechanical noise sample. It would not typically be used with hi-hat pedals, as most electronic drum kits will send a MIDI note when the pedal hits bottom."

Salamander plays a pedal noise sample like the above from what I can make out.


Linuxsampler seems to be doing

     Releases the voices on the given key if sustain pedal is not pressed.
      If sustain is pressed, the release of the note will be postponed until
      sustain pedal will be released or voice turned inactive by itself (e.g.
      due to completion of sample playback).
geckolinux commented 3 years ago

Linuxsampler seems to be doing

 Releases the voices on the given key if sustain pedal is not pressed.
  If sustain is pressed, the release of the note will be postponed until
  sustain pedal will be released or voice turned inactive by itself (e.g.
  due to completion of sample playback).

Ahh, I see. So is that still within the SFZ spec? Or where is that paragraph taken from?

osxmidi commented 3 years ago

Linuxsampler seems to be doing

 Releases the voices on the given key if sustain pedal is not pressed.
  If sustain is pressed, the release of the note will be postponed until
  sustain pedal will be released or voice turned inactive by itself (e.g.
  due to completion of sample playback).

Ahh, I see. So is that still within the SFZ spec? Or where is that paragraph taken from?

That's taken from the Linuxsampler code comments.

Is there any difference between that and the below?

The sfz spec says

"If the sustain pedal is pressed (MIDI CC number 64 value is 64 or above), sfz does not process MIDI Note Off events until the pedal is released. All Note Off related processing happens at that point (when pedal is released)."

geckolinux commented 3 years ago

Interesting, so LinuxSampler's behavior is intentional (and very beneficial, in my opinion).

Is there any difference between that and the below?

"If the sustain pedal is pressed (MIDI CC number 64 value is 64 or above), sfz does not process MIDI Note Off events until the pedal is released. All Note Off related processing happens at that point (when pedal is released)."

In my interpretation this paragraph doesn't contradict LinuxSampler's behavior. It seems like a separate question: If there is still audible residual resonance has the Note Off event already occurred? Isn't Note Off as soon as a key is released? Or does it happen when the sample for that note plays to its end?

osxmidi commented 3 years ago

If I've got it right,

If the piano keys are released then that's a note off.

If the sustain pedal is held when the piano keys are released then the note off should be ignored (from what I can make out from the sfz spec.

If the sustain pedal is activated and held after the piano keys are released then a note off has already happened and Linuxsampler seems to allow to activate the sustain pedal after a note off has happened and that's not in the sfz spec from what I can make out.

SFZero-X has no pedal sustain specific code at the moment.

Implementing the sfz spec for the sustain pedal seems to be straight forward but the way Linuxsampler handles the sustain pedal is probably more involved.

geckolinux commented 3 years ago

Right, so LinuxSampler does appear to have non-standard behavior in that sense. Although I still think it's extremely positive for the playing experience.

So to sum up, there are two things here in this topic of sustain pedal realism:

  1. "I also noticed another quirk that is unique to SFZero: When I press a key or various keys, depress the sustain pedal, release the keys, and then with the sustain pedal still down if I lightly press those same keys it kills the resonance. Normally what would happen is that the resonance would continue at the same rate of decay as long as the sustain pedal is pressed."

(Could be improved by adhering to the SFZ spec.)

  1. So basically, on a real piano, you hit some notes fairly hard, completely release them all, and then before their resonance dies out immediately hit the sustain pedal, and the residual resonance will continue for quite a while.

(Requires innovating beyond the SFZ spec.)

Is that correct?

osxmidi commented 3 years ago

Right, so LinuxSampler does appear to have non-standard behavior in that sense. Although I still think it's extremely positive for the playing experience.

So to sum up, there are two things here in this topic of sustain pedal realism:

  1. "I also noticed another quirk that is unique to SFZero: When I press a key or various keys, depress the sustain pedal, release the keys, and then with the sustain pedal still down if I lightly press those same keys it kills the resonance. Normally what would happen is that the resonance would continue at the same rate of decay as long as the sustain pedal is pressed."

(Could be improved by adhering to the SFZ spec.)

  1. So basically, on a real piano, you hit some notes fairly hard, completely release them all, and then before their resonance dies out immediately hit the sustain pedal, and the residual resonance will continue for quite a while.

(Requires innovating beyond the SFZ spec.)

Is that correct?

I think so.

The way Linuxsampler uses the sustain pedal would be the best imo.

I'll see what I can do but it may take some time.

osxmidi commented 3 years ago

Right, so LinuxSampler does appear to have non-standard behavior in that sense. Although I still think it's extremely positive for the playing experience.

So to sum up, there are two things here in this topic of sustain pedal realism:

  1. "I also noticed another quirk that is unique to SFZero: When I press a key or various keys, depress the sustain pedal, release the keys, and then with the sustain pedal still down if I lightly press those same keys it kills the resonance. Normally what would happen is that the resonance would continue at the same rate of decay as long as the sustain pedal is pressed."

(Could be improved by adhering to the SFZ spec.)

  1. So basically, on a real piano, you hit some notes fairly hard, completely release them all, and then before their resonance dies out immediately hit the sustain pedal, and the residual resonance will continue for quite a while.

(Requires innovating beyond the SFZ spec.)

Is that correct?

Well I think I might be getting somewhere with the sfz spec and the sustain pedal and eliminating the quirky things but the Linuxsampler feature I'm not sure because it's hard to test with my current testing setup at the moment.

geckolinux commented 3 years ago

Thanks very much for your time on this. I tried the SFZero-X.vst3.zip with Carla. It seems to behave the same as before, not sure if maybe your recent changes weren't included in that build?

osxmidi commented 3 years ago

Thanks very much for your time on this. I tried the SFZero-X.vst3.zip with Carla. It seems to behave the same as before, not sure if maybe your recent changes weren't included in that build?

Yes you are right.

I did change some code for the sustain pedal in but it had no effect, I think Juce might be doing something with the sustain pedal because I currently have no sustain pedal handling code in SFZero-X but it's still handing the sustain pedal midicc64 so maybe it's Juce doing it.

osxmidi commented 3 years ago

Hi there, Ever since I got into Linux audio for playing the piano with my MIDI keyboard, I noticed a unique, subtle trait of LinuxSampler that made it feel distinctly more natural. With a sustain pedal, LinuxSampler allows for sustaining the residual resonance even after releasing all the keys. So basically, on a real piano, you hit some notes fairly hard, completely release them all, and then before their resonance dies out immediately hit the sustain pedal, and the residual resonance will continue for quite a while. LinuxSampler faithfully reproduces this behavior ( even with SF2 soundfonts), and to my knowledge it's the only free sampler that does this. SFZero-X does not either. Even the Sforzando player for Windows which is generally regarded as the standard for free SFZ players doesn't do this. Apart from LinuxSampler, the only thing on my system that also has proper sustain behavior is the commercial Pianoteq app. But the problem is that LinuxSampler doesn't seem to exist as a Linux VST (only for Windows apparently?) so it's hard to use it with other DAWs and synthesizer apps. Would it be possible to implement this behavior on SFZero-X? Thanks a lot!

Is this getting closer?

SFZero-X.vst3.zip

geckolinux commented 3 years ago

Is this getting closer?

SFZero-X.vst3.zip

Nice!!! Much better. I'd say you've successfully reproduced the behavior of LinuxSampler in the more subtle aspect of this issue:

So basically, on a real piano, you hit some notes fairly hard, completely release them all, and then before their resonance dies out immediately hit the sustain pedal, and the residual resonance will continue for quite a while.

Now there is just this more glaring quirk remaining:

I also noticed another quirk that is unique to SFZero: When I press a key or various keys, depress the sustain pedal, release the keys, and then with the sustain pedal still down if I lightly press those same keys it kills the resonance. Normally what would happen is that the resonance would continue at the same rate of decay as long as the sustain pedal is pressed.

I assume that one might be a bit easier to fix, since every other SFZ sampler I've tried doesn't act that way.

But again, congratulations on refining that subtle sustain behavior, I really appreciate your time and effort. The two fixes together will be a huge improvement.

osxmidi commented 3 years ago

"I also noticed another quirk that is unique to SFZero: When I press a key or various keys, depress the sustain pedal, release the keys, and then with the sustain pedal still down if I lightly press those same keys it kills the resonance. Normally what would happen is that the resonance would continue at the same rate of decay as long as the sustain pedal is pressed."

The light key touch might be triggering "note on" notes which would stop the already sounding notes and start new notes at a very low volume.

Is that what it seems like?

Maybe that is how the default Juce sustain pedal handling works.

If I hit a note and keep the sustain pedal down and then hit the same note then it generates a note on which stops the previous note and starts a new note (with the sustain pedal active for the new note).

Maybe I can override the default behavior.

geckolinux commented 3 years ago

The light key touch might be triggering "note on" notes which would stop the already sounding notes and start new notes at a very low volume.

Yes, exactly. Or even when pressing the same keys with a normal touch it still sounds unnatural, because the previous sustained notes get instantly cut off. On a normal piano it would just add cumulative amplitude each time the keys are pressed repeatedly with the sustain pedal down. I can make a recording to explain it better if you need. Thanks a lot!

osxmidi commented 3 years ago

The light key touch might be triggering "note on" notes which would stop the already sounding notes and start new notes at a very low volume.

Yes, exactly. Or even when pressing the same keys with a normal touch it still sounds unnatural, because the previous sustained notes get instantly cut off. On a normal piano it would just add cumulative amplitude each time the keys are pressed repeatedly with the sustain pedal down. I can make a recording to explain it better if you need. Thanks a lot!

If you could post a recording it will help I think.

osxmidi commented 3 years ago

The light key touch might be triggering "note on" notes which would stop the already sounding notes and start new notes at a very low volume.

Yes, exactly. Or even when pressing the same keys with a normal touch it still sounds unnatural, because the previous sustained notes get instantly cut off. On a normal piano it would just add cumulative amplitude each time the keys are pressed repeatedly with the sustain pedal down. I can make a recording to explain it better if you need. Thanks a lot!

I've made a few changes

SFZero-X.vst3.zip

geckolinux commented 3 years ago

Much better! I'd call that just about perfect in terms of playing dynamics. Well done!