Click-free fade-in algorithm for synths?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Click-free fade-in algorithm for synths?

Johannes Lorenz
A note-on event can lead to clicks in synths, which is often fixed by a
fade-in algorithm.

If the attack rate for a synth's signal is 0, the synth shall not click,
and still fade in as fast as possible. What is the best algorithm for
fading in a signal, that scales also with small buffersizes, like 32
samples per buffer (at 44100 samples/s)?

For example, in zynaddsubfx, we count the ascending zero crossings and
calculate the fade-in length upon it [1]. Then, an S-curve of that
length is multiplied with the signal. Counting zero crossings prevents
clicking on lower notes, and it makes higher notes more punchy. That
algorithm works very well for a buffersize of 256 samples (at 44100
samples/s), but it fails at 32 samples (since the zero crossings of 32
samples are often not representive).

Any papers, or experience with other synths? We currently need a good
solution for (at least) zynaddsubfx and the triple oscillator in LMMS.


Links:
[1]
https://github.com/zynaddsubfx/zynaddsubfx/blob/4e36e765f677dbc689461889e502d015c22966a5/src/Synth/ADnote.cpp#L1202-L1222
_______________________________________________
Linux-audio-dev mailing list
[hidden email]
https://lists.linuxaudio.org/listinfo/linux-audio-dev
Reply | Threaded
Open this post in threaded view
|

Re: Click-free fade-in algorithm for synths?

Christopher Arndt
Am 24.09.19 um 20:38 schrieb Johannes Lorenz:
> A note-on event can lead to clicks in synths, which is often fixed by a
> fade-in algorithm.
>
> If the attack rate for a synth's signal is 0, the synth shall not click,

Some would disagree with that. Clicking can in fact be used as a tool in
sound design. From a sound programmers perspective I'd rather like the
synth to provide different envelope curves.


Chris
_______________________________________________
Linux-audio-dev mailing list
[hidden email]
https://lists.linuxaudio.org/listinfo/linux-audio-dev
Reply | Threaded
Open this post in threaded view
|

Re: Click-free fade-in algorithm for synths?

Paul Davis
In reply to this post by Johannes Lorenz


On Tue, Sep 24, 2019 at 12:38 PM Johannes Lorenz <[hidden email]> wrote:
Counting zero crossings prevents
clicking on lower notes, and it makes higher notes more punchy.

There's fundamentally no such thing as a zero crossing. You might have two samples on either side of zero, but you still don't have a sample *at* zero, so in the general case, truncating one of them to zero and starting/ending there is still going to give you distortion and/or noise. Obviously there may be cases where one of them is close enough to zero for this not to be be an issue, but it's not a general method.
Ardour applies declick fades every time the transport starts and stops. You can read about how we do it here:



_______________________________________________
Linux-audio-dev mailing list
[hidden email]
https://lists.linuxaudio.org/listinfo/linux-audio-dev
Reply | Threaded
Open this post in threaded view
|

Re: Click-free fade-in algorithm for synths?

Tim-2
On 9/24/19 4:26 PM, Paul Davis wrote:

>
>
> On Tue, Sep 24, 2019 at 12:38 PM Johannes Lorenz <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Counting zero crossings prevents
>     clicking on lower notes, and it makes higher notes more punchy.
>
>
> There's fundamentally no such thing as a zero crossing. You might have
> two samples on either side of zero, but you still don't have a sample
> *at* zero, so in the general case, truncating one of them to zero and
> starting/ending there is still going to give you distortion and/or
> noise. Obviously there may be cases where one of them is close enough to
> zero for this not to be be an issue, but it's not a general method.
> Ardour applies declick fades every time the transport starts and stops.
> You can read about how we do it here:
>
> https://github.com/Ardour/ardour/blob/master/libs/ardour/ardour/disk_reader.h#L135
> https://github.com/Ardour/ardour/blob/master/libs/ardour/disk_reader.cc#L1445
> https://github.com/Ardour/ardour/blob/master/libs/ardour/amp.cc#L163

Hi Paul. Thanks, I was going to mention that.

We had a similar conversation a few years ago when I was adding
  anti-zipper noise to MusE, and I inquired about zero-crossing methods.

I replied that TV and amplifier electronic volumes use zero-crossing,
  so why not use it?

But I conceded the very point you mention above, ie. where exactly is
  the crossing point.
And it is dependent on frequency so you get a different attack result
  each time.

In a TV or amp volume chip it's OK but here, meh...

So in the end, looking at the code given above, I can see I did much
  the exact same thing as Ardour, using a fixed coefficient value
  driven by time passage (sample rate).

Cheers.
Tim.
_______________________________________________
Linux-audio-dev mailing list
[hidden email]
https://lists.linuxaudio.org/listinfo/linux-audio-dev
Reply | Threaded
Open this post in threaded view
|

Re: Click-free fade-in algorithm for synths?

Will J Godfrey
On Tue, 24 Sep 2019 19:12:47 -0400
Tim <[hidden email]> wrote:

>On 9/24/19 4:26 PM, Paul Davis wrote:
>>
>>
>> On Tue, Sep 24, 2019 at 12:38 PM Johannes Lorenz <[hidden email]
>> <mailto:[hidden email]>> wrote:
>>
>>     Counting zero crossings prevents
>>     clicking on lower notes, and it makes higher notes more punchy.
>>
>>
>> There's fundamentally no such thing as a zero crossing. You might have
>> two samples on either side of zero, but you still don't have a sample
>> *at* zero, so in the general case, truncating one of them to zero and
>> starting/ending there is still going to give you distortion and/or
>> noise. Obviously there may be cases where one of them is close enough to
>> zero for this not to be be an issue, but it's not a general method.
>> Ardour applies declick fades every time the transport starts and stops.
>> You can read about how we do it here:
>>
>> https://github.com/Ardour/ardour/blob/master/libs/ardour/ardour/disk_reader.h#L135
>> https://github.com/Ardour/ardour/blob/master/libs/ardour/disk_reader.cc#L1445
>> https://github.com/Ardour/ardour/blob/master/libs/ardour/amp.cc#L163 
>
>Hi Paul. Thanks, I was going to mention that.
>
>We had a similar conversation a few years ago when I was adding
>  anti-zipper noise to MusE, and I inquired about zero-crossing methods.
>
>I replied that TV and amplifier electronic volumes use zero-crossing,
>  so why not use it?
>
>But I conceded the very point you mention above, ie. where exactly is
>  the crossing point.
>And it is dependent on frequency so you get a different attack result
>  each time.
>
>In a TV or amp volume chip it's OK but here, meh...
>
>So in the end, looking at the code given above, I can see I did much
>  the exact same thing as Ardour, using a fixed coefficient value
>  driven by time passage (sample rate).
>
>Cheers.
>Tim.


Just like to add, that on a complex waveform with a strong harmonic content it's
quite likely to cross the zero point 2-3 times during each cycle of the
fundamental.

--
It wasn't me! (Well actually, it probably was)

... the hard part is not dodging what life throws at you,
but trying to catch the good bits.
_______________________________________________
Linux-audio-dev mailing list
[hidden email]
https://lists.linuxaudio.org/listinfo/linux-audio-dev
Reply | Threaded
Open this post in threaded view
|

Re: Click-free fade-in algorithm for synths?

Fons Adriaensen-3
In reply to this post by Paul Davis
On Tue, Sep 24, 2019 at 02:26:53PM -0600, Paul Davis wrote:
 
> There's fundamentally no such thing as a zero crossing. You might have two
> samples on either side of zero, but you still don't have a sample *at*
> zero, so in the general case, truncating one of them to zero and
> starting/ending there is still going to give you distortion and/or noise.
> Obviously there may be cases where one of them is close enough to zero for
> this not to be be an issue, but it's not a general method.

Even if you would have an exact zero sample, that would not avoid a
click. It would only ensure that the click has a 1/f^2 spectrum
instead of 1/f (so it would contain less HF).

From a synth I'd expect a controllable and precisely defined fade-in,
not something that tries to be clever. If the fade-in time has to
depend on frequency (it usually does if the frequency can change over
a large range), that should be programmable or 'voltage controlled'
just as anything else.

Ciao,

--
FA

_______________________________________________
Linux-audio-dev mailing list
[hidden email]
https://lists.linuxaudio.org/listinfo/linux-audio-dev
Reply | Threaded
Open this post in threaded view
|

Re: Click-free fade-in algorithm for synths?

Fons Adriaensen-3
In reply to this post by Johannes Lorenz
On Tue, Sep 24, 2019 at 08:38:19PM +0200, Johannes Lorenz wrote:

> For example, in zynaddsubfx, we count the ascending zero crossings and
> calculate the fade-in length upon it [1]. Then, an S-curve of that length is
> multiplied with the signal. Counting zero crossings prevents clicking on
> lower notes, and it makes higher notes more punchy. That algorithm works
> very well for a buffersize of 256 samples (at 44100 samples/s), but it fails
> at 32 samples (since the zero crossings of 32 samples are often not
> representive).

That could be a good method, but why should this (or anything a synth
does) depend on period size ? Implementation may be a bit simpler if
it does, but that's poor excuse (IMHO :-)...

Ciao,

--
FA


_______________________________________________
Linux-audio-dev mailing list
[hidden email]
https://lists.linuxaudio.org/listinfo/linux-audio-dev
Reply | Threaded
Open this post in threaded view
|

Re: Click-free fade-in algorithm for synths?

Manuel Haible
In reply to this post by Johannes Lorenz
>> For example, in zynaddsubfx, we count the ascending zero crossings and
>> calculate the fade-in length upon it [1]. Then, an S-curve of that
>> length is multiplied with the signal. Counting zero crossings prevents
>> clicking on lower notes, and it makes higher notes more punchy.
 
You are experiencing different phenomena:

- Groove: by dividing / multiplying frequencies to rhythm, envelope-times ect. - it just grooves.
In fact this is a very basic part of Electronic Dance Music.
- On lower notes the envelope might be slow here = no clicking
- Did you try syncing the oscillator with the note-on trigger? this gives a consistent "punch" and you can start it at 0, -1, +1, whatever - your choice.
Free running oscillators are more "groovy" and "alive".
- "Punch" is archived with the hold-stage in an AHDSR-envelope. Minimoog has that, - it overdrives the envelope, which rersults in a plateu.

For counting / finding zero-X it's simply this:  
 if {sample[now]*sample[before]==negative

Of course the result depends very much on the resolution (samplewise and bitwise).
Small buffersizes shouldn't be any problem anyway!? But yes for counting you have to wait, find and count.

Actually you do know the count of zerocrossings, as you know the frequency the oscillator swings!? So you don't have to mesure it!


Interesting topic... what are you working on? What is your goal?
 
 
Gesendet: Dienstag, 24. September 2019 um 20:38 Uhr
Von: "Johannes Lorenz" <[hidden email]>
An: [hidden email]
Betreff: [LAD] Click-free fade-in algorithm for synths?
A note-on event can lead to clicks in synths, which is often fixed by a
fade-in algorithm.

If the attack rate for a synth's signal is 0, the synth shall not click,
and still fade in as fast as possible. What is the best algorithm for
fading in a signal, that scales also with small buffersizes, like 32
samples per buffer (at 44100 samples/s)?

For example, in zynaddsubfx, we count the ascending zero crossings and
calculate the fade-in length upon it [1]. Then, an S-curve of that
length is multiplied with the signal. Counting zero crossings prevents
clicking on lower notes, and it makes higher notes more punchy. That
algorithm works very well for a buffersize of 256 samples (at 44100
samples/s), but it fails at 32 samples (since the zero crossings of 32
samples are often not representive).

Any papers, or experience with other synths? We currently need a good
solution for (at least) zynaddsubfx and the triple oscillator in LMMS.


Links:
[1]
https://github.com/zynaddsubfx/zynaddsubfx/blob/4e36e765f677dbc689461889e502d015c22966a5/src/Synth/ADnote.cpp#L1202-L1222
_______________________________________________
Linux-audio-dev mailing list
[hidden email]
https://lists.linuxaudio.org/listinfo/linux-audio-dev
 
 

_______________________________________________
Linux-audio-dev mailing list
[hidden email]
https://lists.linuxaudio.org/listinfo/linux-audio-dev
Reply | Threaded
Open this post in threaded view
|

Re: Click-free fade-in algorithm for synths?

Manuel Haible
 
let me correct:
 
 
>>For counting / finding zero-X it's simply this:  
>> if {sample[now]*sample[before]==negative


if {sample[now]*sample[before]<=0
 
 
Gesendet: Mittwoch, 25. September 2019 um 15:10 Uhr
Von: [hidden email]
An: "Johannes Lorenz" <[hidden email]>
Cc: [hidden email]
Betreff: Re: [LAD] Click-free fade-in algorithm for synths?
>> For example, in zynaddsubfx, we count the ascending zero crossings and
>> calculate the fade-in length upon it [1]. Then, an S-curve of that
>> length is multiplied with the signal. Counting zero crossings prevents
>> clicking on lower notes, and it makes higher notes more punchy.
 
You are experiencing different phenomena:

- Groove: by dividing / multiplying frequencies to rhythm, envelope-times ect. - it just grooves.
In fact this is a very basic part of Electronic Dance Music.
- On lower notes the envelope might be slow here = no clicking
- Did you try syncing the oscillator with the note-on trigger? this gives a consistent "punch" and you can start it at 0, -1, +1, whatever - your choice.
Free running oscillators are more "groovy" and "alive".
- "Punch" is archived with the hold-stage in an AHDSR-envelope. Minimoog has that, - it overdrives the envelope, which rersults in a plateu.

For counting / finding zero-X it's simply this:  
 if {sample[now]*sample[before]==negative

Of course the result depends very much on the resolution (samplewise and bitwise).
Small buffersizes shouldn't be any problem anyway!? But yes for counting you have to wait, find and count.

Actually you do know the count of zerocrossings, as you know the frequency the oscillator swings!? So you don't have to mesure it!


Interesting topic... what are you working on? What is your goal?
 
 
Gesendet: Dienstag, 24. September 2019 um 20:38 Uhr
Von: "Johannes Lorenz" <[hidden email]>
An: [hidden email]
Betreff: [LAD] Click-free fade-in algorithm for synths?
A note-on event can lead to clicks in synths, which is often fixed by a
fade-in algorithm.

If the attack rate for a synth's signal is 0, the synth shall not click,
and still fade in as fast as possible. What is the best algorithm for
fading in a signal, that scales also with small buffersizes, like 32
samples per buffer (at 44100 samples/s)?

For example, in zynaddsubfx, we count the ascending zero crossings and
calculate the fade-in length upon it [1]. Then, an S-curve of that
length is multiplied with the signal. Counting zero crossings prevents
clicking on lower notes, and it makes higher notes more punchy. That
algorithm works very well for a buffersize of 256 samples (at 44100
samples/s), but it fails at 32 samples (since the zero crossings of 32
samples are often not representive).

Any papers, or experience with other synths? We currently need a good
solution for (at least) zynaddsubfx and the triple oscillator in LMMS.


Links:
[1]
https://github.com/zynaddsubfx/zynaddsubfx/blob/4e36e765f677dbc689461889e502d015c22966a5/src/Synth/ADnote.cpp#L1202-L1222
_______________________________________________
Linux-audio-dev mailing list
[hidden email]
https://lists.linuxaudio.org/listinfo/linux-audio-dev
 
 
_______________________________________________ Linux-audio-dev mailing list [hidden email] https://lists.linuxaudio.org/listinfo/linux-audio-dev

_______________________________________________
Linux-audio-dev mailing list
[hidden email]
https://lists.linuxaudio.org/listinfo/linux-audio-dev
Reply | Threaded
Open this post in threaded view
|

Re: Click-free fade-in algorithm for synths?

Neil C Smith-2
In reply to this post by Johannes Lorenz
On Tue, 24 Sep 2019 at 19:38, Johannes Lorenz <[hidden email]> wrote:
>
> A note-on event can lead to clicks in synths, which is often fixed by a
> fade-in algorithm.

No idea if it's useful in this case, or whether it duplicates anything
anyone else has said, but I use a form of the switch-and-ramp idea by
Miller Puckette to handle discontinuities in hot-swapped DSP code.

http://msp.ucsd.edu/techniques/latest/book-html/node63.html

Best wishes,

Neil

--
Neil C Smith
Artist & Technologist
www.neilcsmith.net

PraxisLIVE - hybrid visual live programming
for creatives, for programmers, for students, for tinkerers
www.praxislive.org
_______________________________________________
Linux-audio-dev mailing list
[hidden email]
https://lists.linuxaudio.org/listinfo/linux-audio-dev
Reply | Threaded
Open this post in threaded view
|

Re: Click-free fade-in algorithm for synths?

Daniel Swärd
In reply to this post by Johannes Lorenz
On Tue, 2019-09-24 at 20:38 +0200, Johannes Lorenz wrote:
> A note-on event can lead to clicks in synths, which is often fixed by
> a fade-in algorithm.

In most synthesizer tutorials (we're also talking about real hardware
analog synthesizers) they will say that to avoid the click, just add a
tiny amount to the amplitude envelope attack stage.

        /Daniel
_______________________________________________
Linux-audio-dev mailing list
[hidden email]
https://lists.linuxaudio.org/listinfo/linux-audio-dev