Slide effect - HELP NEEDED

Hello,
I really find the Turntable Warp plugin very interesting. However, I’ve tried to modify it so that there is no amplitude change, nor Change Time (i.e. I want it to slide for the whole entire selection). Ever since I’ve tried to modify it, I never got it to work, So I need some help please.
Also understand I’m not an expert about Nyquist at all, I’d prefer help from others.
Here’s the code. Again it doesn’t work when I run it, so I definitely would benefit from some help.

;nyquist plug-in

;version 2

;type process

;name "Slide..."

;action "Sliding..."

;info "Turntable Warping by David R. Sky\nbased on warp tutorial by Roger B. Dannenberg\nSteps are number of semitones above or below non-warped audio\nreleased under terms of the GNU Public License"



;control step0 "Initial step" real "semitones" 0 -36 36
;control step1 "End step" real "semitones" -12 -36 36




; Turntable Warping (mono/stereo) by David R. Sky, December 26, 2004 

; warps mono or stereo audio loaded into Audacity 1.2.3 and later

; step values are semitones above or below pitch of unwarped audio 

; Based on warp tutorial by Roger B. Dannenberg

; Released under terms of the GNU Public License

; http://www.opensource.org/licenses/gpl-license.php



; determine duration of selection in seconds

(setf dur (/ len *sound-srate*))








; function to stretch audio to inverse of duration

(defun newstretch (dur s)

(if (arrayp s) 

(vector (force-srate 44100 (stretch-abs (/ 1.0 dur) (sound (aref s 0)))) 

(force-srate 44100 (stretch-abs (/ 1.0 dur) (sound (aref s 1))))) 

(force-srate 44100 (stretch-abs (/ 1.0 dur) (sound s)))))



; Variable Resample function by Roger B. Dannenberg

(defun variable-resample (steps snd)

; p1 helps convert steps to a ratio        

  (let ((p1 (/ (log 2.0) 12)) ratio map)

; pitch ratio

    (setf ratio (s-exp (mult steps p1))) 

; map from real-time to sound time     

    (setf map (integrate ratio)) 

(snd-compose snd (force-srate *sound-srate* map))))



; doing the warp

(if (arrayp s)

(vector

; left channel

(newstretch dur 

(variable-resample 

(pwl 0.0 step0 dur step1 finish step1)

(mult (pwl 1.0 dur) 

(sound (aref s 0)))))



; right channel

(newstretch dur 

(variable-resample 

(pwl 0.0 step0 dur step1 finish step1)

(mult (pwl 1.0 dur) 

(sound (aref s 1))))))



; mono

(newstretch dur 

(variable-resample 

(pwl 0.0 step0 dur step1 finish step1)

(mult (pwl 1.0 dur) 

(sound s)))))

If you try running that code using the “Debug” button rather than the “OK” button, you will see an error message saying:

error: unbound variable - FINISH

That means that somewhere in your code you are using a variable called “finish” but it is not set to anything, so Nyquist doesn’t know what to do with it.

I’m not sure that I understand what you are trying to do. Turntable warp slows down the audio, like a turntable slowing down, so if all of the selected audio is processed it must get longer.

If you really want it change speed without the length changing, then use the “Sliding Time Scale / Pitch Shift” effect: http://manual.audacityteam.org/man/sliding_time_scale_pitch_shift.html

I’m not referring to changing the pitch by itself. What I am trying to do is change the speed from one point to another, that’s all. In other words, create a Jaws-accessible version of timetracks. Now why are they so f**ing visual?

Thanks, I now understand what you’re trying to do, and it’s a very good idea. It is, however, tricky to code. The hardest part is working out the time positions. The next hardest part is fixing bugs in the original plug-in code.

From a quick look at the code in turntablewarp-ms.ny I see there’s quite a lot of errors in David Sky’s code, so I think the best approach would be to start again from Roger Dannenberg’s “variable resample” tutorial. I have attached that tutorial in RTF format here:
pitch_change.rtf (15.6 KB)

This may help as a start. It can be run in the Nyquist Prompt effect.
It “sort of works”, but the function to calculate the new length after stretching needs to be written.

;version 4
;control initial-pitch "Initial pitch" float "" 0 -12 12
;control final-pitch "Final pitch" float "" 12 -12 12

(defun variable-resample (steps snd)
  (let ((p1 (/ (log 2.0) 12))  ; p1 helps convert steps to a ratio
        ratio map)
    (setf ratio (s-exp (mult steps p1))) ; pitch ratio
    (setf map (integrate ratio)) ; map from real-time to sound time
    (snd-compose snd (force-srate *sound-srate* map))))

(defun new-length (initial-dur)
  ;; Need to work out the new length after stretching
  ;; For now, we just return the original length
  initial-dur)

(setf dur (get-duration 1)) ;The initial length of the selection

(abs-env
  (let* ((end (new-length dur))
         ; make the speed envelope a little longer than required to avoid click at end.
         (pitch (pwl 0 initial-pitch end final-pitch (1+ end))))
     (multichan-expand #'variable-resample pitch (sound *track*))))

Thanks Steve.
Unfortunately I didn’t quite understand even the tutorial, but I somehow knew that the plugin will need to get the entire duration of the file as does the Turntable Warp plugin.
The parameters in my Slide effect are actually pretty simple really - “Initial deviation” and “Final deviation”, but rather than in semitones it would be in percentages. So I guess I’d have to delete the calculation of converting steps to a ratio? And get the duration? Or is there more to it besides the warp command and the last two points?
I knew it’d be at least a bit easier than you thought it would.

You still need to create the “mapping”, which is a ramp up from 0,0. The slope governs the speed.
The function that does the heavy lifting is the Nyquist function “snd-compose”.
http://www.cs.cmu.edu/~rbd/doc/nyquist/part8.html#index700

As an example, this gives a fixed rate speed change (which of course could be implemented more easily by just resampling, but the point is to use snd-compose):

;version 4

;control speed "Speed multiplier" float "" 1 0.1 10

; For constant speed, the duration is easily calculated as:
; original-duration / speed
(setf dur (/ (get-duration 1) speed))

(abs-env
  (let ((map  (force-srate *sound-srate* (pwlv 0 dur (* speed dur)))))
    (snd-compose *track* map)))

I think this does what you want:
slide-speed.ny (1.1 KB)

Thanks Steve,
However, I think it’s now just a case of trying to convert it so it’s understood by Audacity 2.0.6. I wonder what to modify for that? I guess that instead of version 4 would be version 3, and instead of track, I forgot - was it Snd? Just can’t remember.

Why not upgrade to Audacity 2.1.3?

“S”

Well, the only reason why I don’t ever want to try 2.1.2 is because it makes no sense at all for a plugin to insert unwanted silence and latency which might not be corrected, plus I’m not used to having effects perform in real-time. When I replaced track with just S, it doesn’t work.

What are you referring to?

I can remember for some reason, whichever plugins that can be changed in real-time when you play a file, I remember something about the effect having to insert latency so it could be applied. I’m not sure if this is still true in 2.1.2, but to me it just doesn’t make sense.
All I did with the code was to change track& to S, and version 4 to version 3. The plugin appears, but when I run it, it says Nyquist did not return audio.

The bug that you are referring to affects the preview of some third party plug-ins. It does not affect how the effect is applied, and does not affect any of the effects that are shipped with Audacity. It also does not affect Nyquist effects.

Try running the effect using the Debug button rather than the OK button.
What does it say in the debug window?

The “Sliding Speed Change” plug-in is now available on the Audacity wiki: http://wiki.audacityteam.org/wiki/Nyquist_Effect_Plug-ins#Sliding_Speed_Change