Hi Everyone,

Does anyone know the exact mathematical formulae for logarithmic fade in/fade out (or exponential fade in/fade out) available among options of “adjustable fade” effect? Where can we find such formulae?

Best regards,
MM.

The “Logarithmic In” option is the 6th option for the “preset” control (line 30). The option numbers start from zero, so “preset = 5”.
This gets picked up in line 92:

``````(5  (log-exp-curve 15.311 0))   ; Logarithmic In
``````

which calls the function “log-exp-curve” with parameters 15.311 and 0.

“log-exp-curve” is defined in lines 182 to 190:

``````;;; log or exponential curve scaled 0 to 1
;;; x is the minimum level in dB before scaling.
(defun log-exp-curve (x direction)
(control-srate-abs *sound-srate*
(let ((x (db-to-linear x)))
(if (= direction 0)
(setf env (pwev x 1 1))
(setf env (pwev 1 1 x)))
(mult (/ (- 1 x))     ; normalize to 0 dB
(diff env x)))))    ; drop down to silence
``````

When called with (log-exp-curve 15.311 0), “direction”=0, which is the fade-in direction.
So the code that creates the fade curve is:

``````(setf env (pwev x 1 1))
``````

The “pwev” function is defined within Nyquist: http://www.cs.cmu.edu/~rbd/doc/nyquist/part8.html#index423

(pwev l1 t2 l2 t3 t3 … tn ln) [LISP]

• Creates a piece-wise exponential envelope with breakpoints at (0, l1), (t2, l2), etc., ending with (tn, ln). Otherwise, the behavior is like that of pwe.

and

(pwe t1 l1 t2 l2 … tn) [LISP]

• Creates a piece-wise exponential envelope with breakpoints at (0, 1), (t1, l1), (t2, l2), … (tn, 1). Exponential segments means that the ratio of values from sample to sample is constant within the segment. (> The current implementation actually takes the log of each value, computes a piece-wise exponential from the points using pwl, then exponentiates each resulting sample. > A faster implementation is certainly possible!) Breakpoint values (lj) must be greater than zero. Otherwise, this function is similar to pwl, including stretch by sustain, mapping according to warp, sample rate based on control-srate, and “breakpoint munging” (see pwl described above). Default initial and final values are of dubious value with exponentials. See pwev below for the function you are probably looking for.

(emphasis mine)

The resulting “env” control signal is then multiplied by the selected audio.

Simplifying the code gives (approximately):

``````(setf x 5.82841)
(setf env (pwev x 1 1))
(setf env (mult (/ (- 1 x)) (diff env x)))
(mult *track* env)
``````

Q. Why “15.311”?
A. Because that value gives a similar amount of curvature as the “Cosine” curve.

Thank you very much Steve for your comprehensive and very helpful answer!