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?
I appreciate your help in advance!
Best regards,
MM.
logarithmic fade in/fade out
Forum rules
This forum is for Audacity on Windows.
Please state which version of Windows you are using,
and the exact three-section version number of Audacity from "Help menu > About Audacity".
Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
Please state which version of Windows you are using,
and the exact three-section version number of Audacity from "Help menu > About Audacity".
Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
Re: logarithmic fade in/fade out
Here's the code: https://github.com/audacity/audacity/bl ... le-fade.ny
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:
Code: Select all
(5 (log-exp-curve 15.311 0)) ; Logarithmic In"log-exp-curve" is defined in lines 182 to 190:
Code: Select all
;;; 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 fade-in else fade-out
(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
So the code that creates the fade curve is:
Code: Select all
(setf env (pwev x 1 1))and(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.
(emphasis mine)(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.
The resulting "env" control signal is then multiplied by the selected audio.
Simplifying the code gives (approximately):
Code: Select all
(setf x 5.82841)
(setf env (pwev x 1 1))
(setf env (mult (/ (- 1 x)) (diff env x)))
(mult *track* env)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
Re: logarithmic fade in/fade out
Q. Why "15.311"?
A. Because that value gives a similar amount of curvature as the "Cosine" curve.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
Re: logarithmic fade in/fade out
Thank you very much Steve for your comprehensive and very helpful answer!