monsto
March 3, 2019, 11:23am
21
Unfortunately that code is a bit tricky to use because it requires the sound to be followed to be in the left channel of a stereo track, and the sound to apply the envelope to in the right channel of the stereo track. To use that code with stereo tracks (and binaural beats are stereo by definition) requires messing around splitting and rejoining the stereo tracks several times.
Here is an alternative Nyquist script that will work with mono or stereo tracks, provided the tracks are not too long (I’ve set the max selection length to 30 minutes as that tested OK). This code requires Audacity 2.1.1 or later.
;type process
;control res "Time resolution" float "seconds" 0.1 0.01 10
;control mode "Follow peak or RMS level" choice "Peak,RMS" 0
(defun mono (sig)
(setf sig (s-abs sig))
(if (arrayp sig)
(mult 0.5 (sum (aref sig 0)(aref sig 1)))
sig))
(setf step (truncate (* res *sound-srate*)))
(setf op (- 2 mode))
(cond
((> (get-duration 1) 1800)
(format nil "Error.~%~%Selection too long.~%~
Reduce the selection to 30 mins maximum"))
((< (length (get '*selection* 'tracks)) 2)
(format nil "Error.~%~%This effect requires at least 2 tracks to be selected.~%~
The amplitude envelope is copied from the first~%~
selected track, then applied to subsequent tracks."))
((< (get-duration 0.5) res)
(format nil "Error.~%~%The 'Time Resolution' should be considerably~%~
shorter than the length of the selection.~%~
The absolute maximum allowed 'Time Resolution' is~%~
half of the selection length."))
((= (get '*track* 'index) 1)
(setf *scratch*
(snd-copy (snd-avg (mono *track*) step step op)))
; return *track* to prevent audio from being released from *scratch*.
*track*) ;*track*)
(T
(let ((env *scratch*)
(offset (* res (/ (1+ mode) 2.0)))
(initial-amp (snd-fetch (snd-copy *scratch*))))
; release *scratch* when we're finished
(if (= (get '*track* 'index)(length (get '*selection* 'tracks)))
(setf *scratch* '*unbound*))
(mult *track*
(sim
(abs-env (pwlv 0 offset initial-amp))
(at-abs offset (cue env)))))))
The track that you want to follow must be the first selected track.
The envelope detected in the first selected track is then applied to each subsequent track.
Dear Steve,
This post was very helpful. I wanted to do the same thing, copy envelope from one track to another and this code worked 9/10 for my needs. The only knock is that it moved the envelope as opposed to copying it. With some creative copy/undo/paste, it was a mere speedbump.
I signed up for an account simply to say “Thanks for posting this”.
Can anyone please help me?
For many years I’ve used an ‘envelope follower’ script which worked perfectly.
The script no longer works when I updated Audacity, so I’ve used the one in this thread (above), but this doesn’t work, as you can see:
Obviously, I want it to look more like this…
(Note: this envelope is just an extreme example to clearly demonstrate the problem. If I wanted this kind of simple ‘on/off’ effect I would just use Duck.)
Trebor
December 19, 2020, 2:51pm
23
Try a shorter “time resolution”, say 10ms.
(also check envelope-follower is on “Peak”, not “RMS”).
Ah, thank you, that worked!
I changed line 2 from:
;control res “Time resolution” float “seconds” 0.1 0.01 10
to
;control res “Time resolution” float “seconds” 0.01 0.01 10