How to capture envelope from one track and apply to another

Using Nyquist scripts in Audacity.
Post and download new plug-ins.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
monsto
Posts: 2
Joined: Sun Mar 03, 2019 11:14 am
Operating System: Windows 10

Re: How to capture envelope from one track and apply to anot

Post by monsto » Sun Mar 03, 2019 11:23 am

steve wrote:
Fri Nov 20, 2015 2:11 pm
Trebor wrote:The magic phrase is "envelope-follower",
e.g. the second block of Nyquist-code here ... http://forum.audacityteam.org/viewtopic ... 90#p107790
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.

Code: Select all

;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".

LeeJames
Posts: 85
Joined: Tue Aug 14, 2012 9:34 pm
Operating System: Windows 7

Re: How to capture envelope from one track and apply to another

Post by LeeJames » Sat Dec 19, 2020 1:34 pm

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:

Image

Obviously, I want it to look more like this…
Image

(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
Posts: 9902
Joined: Sat Dec 27, 2008 5:22 pm
Operating System: Windows 8 or 8.1

Re: How to capture envelope from one track and apply to another

Post by Trebor » Sat Dec 19, 2020 2:51 pm

LeeJames wrote:
Sat Dec 19, 2020 1:34 pm
The script no longer works ...
time-resolution is to blame.png
time-resolution is to blame.png (14.2 KiB) Viewed 775 times

Try a shorter "time resolution", say 10ms.
(also check envelope-follower is on "Peak", not "RMS").

LeeJames
Posts: 85
Joined: Tue Aug 14, 2012 9:34 pm
Operating System: Windows 7

Re: How to capture envelope from one track and apply to another

Post by LeeJames » Sat Dec 19, 2020 3:25 pm

Trebor wrote:
Sat Dec 19, 2020 2:51 pm
Try a shorter "time resolution", say 10ms.
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

Post Reply