4
$\begingroup$

I just noticed that Spotify fades in/out the music when you play/pause - is this to avoid clicking?

This attenuation is noticeable; is there a minimum amount of attenuation required to fix clicking (while not introducing a noticeable fade). Also, is there a type of attenuation that's best, linear, parabolic, etc?

On youtube, there's no noticeable attenuation, yet there's no clicking; could this be very small attenuation?

$\endgroup$
4
$\begingroup$

My guess is that for Spotify, it is not just about avoiding clicks, but also to improve the DJing kind of experience. The fade length seems to be a user setting in Spotify. Based on my testing with 20 Hz and 440 Hz test tones and Virtual Audio Cable, YouTube doesn't fade in or out or do any other kind of click removal when pausing, here with 20 Hz test tone:

enter image description here

The worst-case test signal to be faded in or out would be a full-scale constant-valued signal (for 16-bit audio that would be 32767, 32767, 32767, 32767, 32767, 32767, ...), because it has no audible sound of its own, and because it will still allow to hear the fade as loud as possible. Then we'd need the best possible fade shape, but I don't know what it is, so here is a sub-optimal fade in:

$$f(x) = \begin{cases}0&\text{if } x < 0,\\ \frac{1}{2}-\frac{1}{2}\cos(\pi x)&\text{if } 0 \le x \le 1,\\ 1&\text{if } x > 1.\end{cases}\tag{1}$$

enter image description here

The following "floatbeat" program plays this fade twice a second (once in and once out per second):

f = function(x){return 0.5-0.5*cos(x*PI)}, fadeLength=0.03, loopLength=1, sampleRate=44100, p=(t/sampleRate)%loopLength, q=p-loopLength/2, (p < fadeLength? f(p/fadeLength): (q < 0)? 1: (q < fadeLength? 1-f(q/fadeLength): 0))

Try running it and adjust fadeLength. At least for me, using good headphones at normal music listening volume, a fade length 0.03 s is only barely audible as a thump, and increasing it to 0.04 s makes the thump disappear. I think 0.03 s is pretty safe.

But is 0.03 s already so long that it sounds like a fade? Let's apply the fades to a 400 Hz sine tone, in floatbeat:

f = function(x){return 0.5-0.5*cos(x*PI)}, fadeLength=0.03, loopLength=1, freq=400, sampleRate=44100, p=(t/sampleRate)%loopLength, q=p-loopLength/2, (p < fadeLength? f(p/fadeLength): (q < 0)? 1: (q < fadeLength? 1-f(q/fadeLength): 0))*sin(2*PI*t*freq/sampleRate)

Running this, I can't hear a click in fade in or fade out. I know there is a fade from the way it sounds and because I do a lot of music editing, but it does not register as a gradual process, more like a smooth event.

Let's try some other fade shapes of length 0.03 s too, with my comments comparing each to Eq. 1:

  • Repeating Eq. 1 here for easy clicking.
  • A linear fade $f(x) = x$ sounds much clickier to me.
  • Smoothstep $f(x) = 3x^2-2x^3$ sounds maybe tiny bit worse to me.
  • Asymmetrical polynpomial $f(x) = 6x^2 - 8x^3 + 3x^4$ sounds significantly thumpier.
  • Smoothstep $f(x) = 10x^3-15x^4+6x^5$ sounds about as good, maybe even a bit better. Less mid-freq but more bassy thump.

Calculating the Fourier transform $F(f)$, where $f$ denotes frequency, of each fade of length 0.03 s appears to confirm what I heard: (For this, I calculated the Fourier transform of the derivative of each fade as function of time $t = \frac{x}{0.03s}$, and compensated for derivation by multiplying the result by a factor $-\frac{i}{f}$.)

enter image description here

I also included the pure tone hearing threshold curve from ISO 226:2003. Some caveats: I do not know the listening volume level so I just shifted the curve in dB scale until it matched my subjective hearing experience with the fade curves peaking above the threshold at roughly those frequencies at which I heard them. Also, the threshold curve has been measured for pure sinusoidal tones whereas here we are dealing with transient sounds. The level comparison between the two cannot be well defined. It would be better to do the analysis with something like a compressive gamma-chirp filter bank which better models hearing. I used closed-back headphones, but still my listening environment has some fan noise and such, so not perfect silence, so there could be some auditory masking going on. Despite all the caveats, I think the threshold curve is useful to show here as it seems to match what I heard. It also hints to that there may be a better fade shape that moves some of the energy from the first spectral side lobe to the main lobe, using window function terminology. Perhaps a better fade shape, one that barely touches the hearing threshold at multiple early lobes, could be obtained by integrating a suitably parameterized Ultraspherical window. Or perhaps there are ways to trace the hearing threshold for all lobes.

I'd choose between 5th order smoothstep and Eq. 1, or 3rd order smoothstep if you want to save some processing power. The choice is not too critical.

$\endgroup$
11
  • $\begingroup$ Hi thanks for the answer. What do you mean by full-magnitude constant-valued signal? I'm thinking a signal of all 1s? $\endgroup$ – Tobi Akinyemi Jul 9 '20 at 11:43
  • $\begingroup$ A signal of all ones is okay, theoretically, but be careful interpreting that through a real world sound system. If there are any coupling capacitors in the circuit, the speaker location will not "remain at one", but will drift back towards center. $\endgroup$ – Cedron Dawg Jul 9 '20 at 13:04
  • 1
    $\begingroup$ No big deal, Olli. I was just pointing out that if you were joining two signals with zero fade duration, that is your worst possible case. If you fade to silence, then silence to signal, I am quite comfortable agreeing that the silence is at zero and 0 to 1 is your worst case. $\endgroup$ – Cedron Dawg Jul 9 '20 at 17:59
  • 2
    $\begingroup$ Tis should be accepted answer $\endgroup$ – Black Yasmin Jul 16 '20 at 15:28
  • 1
    $\begingroup$ @TobiAkinyemi does it answer your question? If yes, please consider marking it as accepted. $\endgroup$ – jojek Jul 17 '20 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.