Delay with bpm and panning

Archive of Nyquist Plug-ins.
Many of the plug-ins here will be available on the Audacity Wiki.
Forum rules
This Forum is an archive of old topics concerning Nyquist plug-ins.

Feedback and questions relating to topics may be posted, but please
DO NOT POST NEW TOPICS HERE.

New plug-ins may be posted on the New Plug-Ins board.
Other posts relating to Nyquist should be posted to the main Nyquist board.

The main repository for Audacity/Nyquist Plug-ins is on the Audacity Wiki.
steve
Site Admin
Posts: 49421
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Delay with bpm and panning

Post by steve » Tue Aug 28, 2018 12:05 pm

First, let's define what the problem is:

At the end of the previous (working) version, you have:

Code: Select all

(if (arrayp *track*)
    (stereo-delay *track*)
    "Error.\nStereo track required.")
which says: "if the track is stereo, apply the function 'stereo-delay' to the track", else throw an error."

The function "stereo-delay" takes stereo audio as it's argument, and returns a stereo sound as the result, but the function "extract" requires a mono sound, so you can't directly apply "extract" to the result of "stereo-delay".

Solution:
Store the (stereo) result from "stereo-delay" in a temporary variable, then apply "extract" to that intermediate result using "multichan-expand".

Code: Select all

(setf dur (get-duration 1))
(if (arrayp *track*)
    (let ((temp-result (stereo-delay *track*)))
      (multichan-expand #'extract-abs 0 dur temp-result))
    "Error.\nStereo track required.")
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Felipe Zanabria
Posts: 46
Joined: Fri Mar 16, 2018 1:38 am
Operating System: Windows 7

Re: Delay with bpm and panning

Post by Felipe Zanabria » Tue Aug 28, 2018 3:03 pm

This sounds good. :)
Delay bpm.ny
(2.1 KiB) Downloaded 7 times
I have fixed the numbers in the bpm function.

Instead of making notes climb by 60, 30, 15 etc, I left this at 60 and added the multiplication in bpm values ​​like 0.5, 1, 2, 4, 8, 16, so if someone wants to modify the values to make notes in other types of times I can easily do.

steve
Site Admin
Posts: 49421
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Delay with bpm and panning

Post by steve » Wed Aug 29, 2018 7:52 am

That works nicely, except for a couple of typos:
In "defun sig" the options are numbered 0, 1, 1, T.
In ";control options" you have a curly brace in the option "Add} high pass filter"
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Felipe Zanabria
Posts: 46
Joined: Fri Mar 16, 2018 1:38 am
Operating System: Windows 7

Re: Delay with bpm and panning

Post by Felipe Zanabria » Wed Aug 29, 2018 5:49 pm

Hello Steve, look this.
Delay bpm.ny
(2.1 KiB) Downloaded 11 times

steve
Site Admin
Posts: 49421
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Delay with bpm and panning

Post by steve » Wed Aug 29, 2018 6:28 pm

That fixes the issues that I mentioned, but do you really want the low pass filter to use the "Lower frequency for the filter" (default 300 Hz)?

When I first tried the low-pass option, I thought that it broke the delay part of the effect because I could no longer hear the echo. It didn't break the effect, it just made the echo so quiet (because it was below 300 Hz) that I couldn't hear it. Yes that was "user error" on my part, but I was initially caught out.

Unfortunately we are not yet able to grey out controls that are not used, so we need to consider GUI very carefully to make effects "intuitive". You need not agree with me, but I'd be inclined to have just one "filter frequency" control that is used by all three filter types, and a "width" control that is used only by the band-pass filter.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Felipe Zanabria
Posts: 46
Joined: Fri Mar 16, 2018 1:38 am
Operating System: Windows 7

Re: Delay with bpm and panning

Post by Felipe Zanabria » Wed Aug 29, 2018 11:34 pm

I thought about this possibility, but it would take away the precision to the effect, because the width control in the bandpass2 function works in a way contrary to the number that is used to establish the q in the eq-band function.
I was inspired by the phone effect that there are in some electronic songs.
With the default frequency cut settings and the selected bandpass, it is possible to do this.
If you use a single cut control and a wide one does not allow this effect, since the spectrum passes with little resonance at 2000 Hz.

steve
Site Admin
Posts: 49421
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Delay with bpm and panning

Post by steve » Thu Aug 30, 2018 1:05 pm

Felipe Zanabria wrote:
Wed Aug 29, 2018 11:34 pm
I thought about this possibility, but it would take away the precision to the effect, because the width control in the bandpass2 function works in a way contrary to the number that is used to establish the q in the eq-band function.
You don't need to change the filter to the eq-band filter. You could still use the highpass and lowpass filters, but set them according to a defined centre frequency and band width. For example, a centre frequency of 1000 Hz and a bandwidth of 2 octaves is equivalent to a low pass corner frequency of 2000 Hz and a high pass corner frequency of 500 Hz, which is also equivalent to a centre frequency of 1000 Hz and a width of 1500 Hz.

Calculating the high and low corner frequencies given width in Hz is a bit tricky as it involves solving a quadratic equation. If I remember my math correctly, I think it can be done like this:

Code: Select all

;control hz "Centre" float "Hz" 1000 10 10000
;control width "Width" float "Hz" 1500 0 10000

(defun get-ratio (a b c)
  ;;; We get ratio as the positive solution of a quadratic
  (/ (+ (- b) (sqrt (- (* b b)(* 4 a c))))(* 2 a)))

(setf ratio (get-ratio hz (- width) (- hz)))
;(print ratio)
(setf hi (* hz ratio))
(setf low (/ hz ratio))
(print hi)
(print low)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Felipe Zanabria
Posts: 46
Joined: Fri Mar 16, 2018 1:38 am
Operating System: Windows 7

Re: Delay with bpm and panning

Post by Felipe Zanabria » Thu Aug 30, 2018 6:02 pm

Hello Steve, tri this:

Code: Select all

;nyquist plug-in
;version 4
;type process
;name "Delay with bpm and panning..."
;action "Performing Delay with bpm and panning..."

;control decay "Decay" float "dB" -6 -24 0
;control bpm "Tempo" float "bpm" 120 1 500
;control notes "Note values:" choice "Half note (0.5),Quarter note (1),Eighth note (2),Sixteenth note (4),Thirty-second note (8),Sixty-fourth note (16)" 2
;control echoes "Number of echoes" int "times" 5 1 100
;control spread "Pan spread" float "move" 0.0 -1 1
;control options "Select aditional options for the delayed sound:" choice "Normal,Add high pass filter,Add low pass filter,Add band pass filter" 0
;control hz "Centre" float "Hz" 1000 10 10000
;control width "Width" float "Hz" 1500 0 10000

(setq notes
  (case notes
    (0 0.5)
    (1 1)
    (2 2)
    (3 4)
    (4 8)
    (t 16)))
(setq delay (* 60 (/ (* bpm notes))))

(defun sig ()
(case options
(0 *track*)
(1 (highpass2 *track* hz 1))
(2 (lowpass2 *track* hz 1))
(t (highpass2 (lowpass2 *track* hi 1) low 1))))

(defun get-ratio (a b c)
  ;;; We get ratio as the positive solution of a quadratic
  (/ (+ (- b) (sqrt (- (* b b)(* 4 a c))))(* 2 a)))

(setf ratio (get-ratio hz (- width) (- hz)))
;(print ratio)
(setf hi (* hz ratio))
(setf low (/ hz ratio))
(print hi)
(print low)

(defun stereo-delay (sig)
  (let ((out sig))
    (do ((i 1 (1+ i))
         (gain decay (+ gain decay))
         (where spread (* -1 where)))
        ((> i echoes) out)
      (setf out
        (sim out
             (at-abs (* i delay)
                (panning (loud gain (cue (sig))) where)))))))

(defun panning (stereo-sig where)
  (let* ((mono-gain (* where where))
         (where (/ (+ 1 where) 2.0))  ;range 0 to 1
         (mono-sig (mono-mix stereo-sig)))
    (sum (mult mono-gain (pan mono-sig where))
         (stereo-pan stereo-sig where))))

(defun stereo-pan (stereo-sig where)
  (setf gain  (- 2 (* 4 (abs (- where 0.5)))))
  (vector (mult gain (- 1 where) (aref stereo-sig 0))
          (mult gain where (aref stereo-sig 1))))

(defun mono-mix (stereo)
  (mult 0.5 (sum (aref stereo 0)
                 (aref stereo 1))))

(setf dur (get-duration 1))
(if (arrayp *track*)
    (let ((temp-result (stereo-delay *track*)))
      (multichan-expand #'extract-abs 0 dur temp-result))
    "Error.\
Stereo track required.")

steve
Site Admin
Posts: 49421
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Delay with bpm and panning

Post by steve » Fri Aug 31, 2018 7:51 am

That works for me. What do you think about it?
If this was to be a public release plug-in, is there anything that you would add or change?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Felipe Zanabria
Posts: 46
Joined: Fri Mar 16, 2018 1:38 am
Operating System: Windows 7

Re: Delay with bpm and panning

Post by Felipe Zanabria » Fri Aug 31, 2018 3:04 pm

I think no. In case it is published in the audacity wiki it would be little to put only me as the author of this plug-in, because you have contributed to the great majority of the code. I want to say that you are also the author of the delay with bpm and panning.

Post Reply