12 thoughts on “Simple Vibrto Effect”

  1. I thank you. I corrected the code which works.

    (stretch-abs 1
    (vector
    (sim
    (scale 0.3 (variable-resample (pwl 1 0 1.1 2 3 2 3 0 12) (osc c4 12.239))))
    (scale 0.5 (fmosc (hz-to-step 440)
    (mult 10 (pwl 0 0 1 7 9 47 9 0 12) (lfo 4 12))))))

    On the other hand, I did not know how to use the parameters ” steps ” and “snd”. There is little information on the Internet. Could you indicate to me how we use the parameter ” snd “?
    Thank you.

    1. When you are posting code samples, please add “code” tags around your text. This makes the code appear in a box and will be laid out correctly.
      I’ve added code tags to your previous post.

      <code>
      ;Your code goes here.
      </code>

      STEPS and SND in your code are “variable” names (symbols that represent values).
      Variables are user defined – you can use most normal characters for variable names but should avoid keywords that are part of the LISP/Nyquist language and must not contain spaces.
      LISP/Nyquist are not case sensitive, so snd and SND are identical.

      In this case SND and STEPS are used to pass two values to the function called variable-resample
      The syntax for defining functions is described in the XLISP manual here: http://www.audacity-forum.de/download/edgar/nyquist/nyquist-doc/xlisp/xlisp-ref/xlisp-ref-087.htm
      Instead of using snd, the code could have used mysound or signal provided that the same name is used each time that you wish to refer to that variable.

      (setq x 3)
      (setq y 4)
      (+ x y) ; returns 7

      In the above, x and y are variables. They have been set to values of 3 and 4 respectively. Other than the choice of variable name it is identical to:

      (setq first-val 3)
      (setq second-val 4)
      (+ first-val second-val) ; returns 7

  2. Thank you for the previous information. I realized that this code really generates an oscillation around an axis of the pitch of a sound. I had thus made a mistake. It is well about a vibrato. I modified a little the code. On the other hand, I tried it in a stereo track and it works well.

    (setq initial-depth 0.3
    (setq final-depth 10.)
    (setq vibrato-freq 4)
    (setq initial-depth (* initial-depth 0.001))
    (setq final-depth (* final-depth 0.001))
    (setf vib-depth (stretch-abs 18 (pwlv initial-depth 1 final-depth)))

    (defun mysound ()
    (scale 0.5 (hzosc 612)))

    (stretch-abs 18
    (snd-compose (mysound) (integrate (sum 1 (mult vib-depth
    (hzosc vibrato-freq))))))

    I tried to understand the functioning of the function snd – compose. I did not arrive there because it is very complicated. A sentence as …” The sound f is used in effect as a lookup table, but it is assumed that g is non-decreasing, so that f is accessed in time order…” for example, is very hermetic for a musician. By looking for a long time, I found that a single code with the function snd – compose. We find it in the article “Pitch_change”. The presented code is intended for users confirmed by the language Nyquist because it is very complex.

    1. Yes that code will work in a mono or stereo track. The (mono only) SND-COMPOSE function is being applied to (MYSOUND) which is a mono sound. When Nyquist returns a mono sound to a stereo track, Audacity copies the sound to both tracks.

      SND-COMPOSE is one of the more complicated effects, which is one of the reasons that I thought it would be worth posting a simple example.

      The inner expression in SND-COMPOSE:
      (integrate (sum 1 (mult vib-depth (hzosc vibrato-freq))))
      creates a wiggly rising line (waveform) from 0 at the start of MYSOUND to an amplitude equal to the length of MYSOUND at the end of MYSOUND. It is this wiggly line that is used as a “look-up table” to map the original samples from MYSOUND to their new positions, thus creating a pitch shift. The amount of “wiggle” on the line sets how much the samples from MYSOUND are shifted.

      The wiggle should always be rising in amplitude – if it decreases, then that would attempt to move samples earlier than the preceding samples, which can’t be done.

      1. I thank you for the previous information. I found on the forum Nyquist a code with the function snd – compose. I tried it with the following regulations:
        (defun variable-resample (steps snd)
        (let* ((p1 (/ (log 2.0) 12))

        (ratio (s-exp (mult steps p1)))
         
        (map (integrate ratio)))
        (snd-compose snd (force-srate *sound-srate* map))))

        (setq dur (get-duration 1.))

        (force-srate 44100 (stretch-abs 2. (scale 0.04 (variable-resample
        (pwl 0. 0. (* dur 1.) 0. (* dur 2.) 12. (* dur 3.) -24 (* dur 4.) 0. (* dur 5.) 0. (* dur 6.) 12. (* dur 7.) -24 (* dur 8.) 0. (* dur 9.5) 0 (* dur 10.) 12 (* dur 11.) -24 (* dur 12.) 0. 14. 0.) (hzosc 697 12.) ) ) ) )
        It seems very interesting because we can create many variations in the proportions thanks to the function (pwl.
        On the other hand, it does not work. Do you see an error in this code there?

        1. There’s a few errors in that code.

          1. (stretch-abs 2,
          There should not be a comma after the 2

          Generally it is not good practice to write floating point numbers with just a dot – it’s too prone to typing errors. If you need a value to be a float, write it as (for example) “2.0” rather than “2.”

          2. (hzosc 697 12.)
          This is incorrect. HZOSC takes just one argument, the frequency. If you need to specify the duration you can do that with OSC.

          Whereas HZOSC specifies the frequency in Hz, OSC specifies the frequency in “steps” (the same as MIDI note numbers). Frequency (Hz) can be converted to the step number using HZ-TO-STEP. So instead of (hzosc 697 12.) you probably want: (osc (hz-to-step 698.12) 12)

          3. (force-srate 44100
          This is probably not “wrong”, provided that the track sample rate is 44100 Hz.
          It would probably be better to have: (force-srate *sound-srate* so that it can work correctly whatever the track sample rate.

          4. The PWL function looks rather odd.
          PWL takes pairs of “time” and “level” in the form:
          (pwl t1 l1 t2 l2 ... tn)
          All of the times are given as multiples of the original selection duration, except for the first (0) and the final one (14). The purpose of that is unclear, but I suspect that it is a coding error.

          I’m not entirely sure what the intention of the original author is, but I suspect that what they meant was something more like this:


          (defun variable-resample (steps snd)
          (let* ((p1 (/ (log 2.0) 12))
          (ratio (s-exp (mult steps p1)))
          (map (integrate ratio)))
          (snd-compose snd (force-srate *sound-srate* map))))

          (force-srate *sound-srate*
          (stretch-abs 2
          (scale 0.04
          (variable-resample
          (pwl 0 0 1 0 2 12 3 -24
          4 0 5 0 6 12 7 -24
          8 0 9.5 0 10 12 11 -24
          12 0 14 0)
          (osc (hz-to-step 698.12) 12)))))

          1. I thank you for all this information. I try to combine two codes. The one allows to create glissandis, and the second allows to create a progressive vibrato. My code is the following one:

            (defun variable-resample (steps snd)
            (let ((p1 (/ (log 2.0) 12)) ratio map)
            (setf ratio (s-exp (mult steps p1)))
            (setf map (integrate ratio))
            (snd-compose snd (force-srate *sound-srate* map))))

            (setq dur (get-duration 1))

            (setf modulator
            (scale 0.5 (mult (pwl 0 0 1 7 12 47 16 0) (lfo 4 16))))

            (setf sound
            (scale 0.5 (mult (fmosc c4 modulator))))

            (stretch-abs 1
            (scale 0.5
            (variable-resample (mult (modulator sound
            (pwl 0 0 1 0 1.1 20 3 21 3 0 16 0)
            (osc (hz-to-step 623.25)16))))))

            There are errors in this code because glissandis does not appear.
            After all, it is really possible to obtain this sound result?

          2. There’s a problem here:
            (pwl 0 0 1 7 12 47 16 0)
            As described in my previous post, PWL takes pairs of parameters, one for the time value and one for the amplitude (level).
            Time, level, time, level, time, level…. time (implied zero level).

            Your time values are:
            0, 1, 12, 16

            Your amplitude values are:
            0, 7, 47, 0
            The final amplitude should not be included because PWL automatically uses an amplitude value of zero as the last value, therefore there should always be an odd number of parameters.

            The main problem though is that your maximum value is 47 which is not nearly big enough for using it in FMOSC.

            If you look up FMOSC in the Nyquist manual you will see that the modulation is expressed in hz, e.g. a sinusoid modulation signal with an amplitude of 1.0 (2.0 peak to peak), will cause a +/- 1.0 hz frequency deviation in sound. Your modulation amount is at most 0.5 x 47 = 23.5 Hz which is not enough variation to be noticeable until you get about 2/3rds of the way through the sound.

            The following will have a much more noticeable effect:

            (setf modulator
            (scale 20 (mult (pwl 0 0 1 7 12 47 16 0) (lfo 4 16))))

            (setf sound
            (scale 0.5 (mult (fmosc c4 modulator))))

            Running your full code in the Nyquist Prompt and using the “Debug” button, there is an error shown:

            error: unbound function - MODULATOR
            if continued: try evaluating symbol again
            .....

            If we lay out your code a little better, the reason for the error becomes apparent:

            (stretch-abs 1
            (scale 0.5
            (variable-resample
            (mult
            (modulator
            sound
            (pwl 0 0 1 0 1.1 20 3 21 3 0 16 0)
            (osc (hz-to-step 623.25)16))))))

            You have written (modulator as if it is a function.
            What you actually want is to use the previously defined modulator variable.

            I can’t see exactly what you are trying to do, but the function variable-resample should take two parameers; steps and snd.

    1. The script can be applied to a mono track using the Nyquist Prompt effect.

      Select the region of a mono track that you want to apply the vibrato effect to, then from the Effect menu select “Nyquist Prompt”. Then copy and paste the script into the Nyquist Prompt and apply.

      Note that this effect is only intended to be applied to short sections (just a few seconds). The sound quality will become progressively worse over longer sections.

      1. Thank you for the information. It’s a pity that the effect is so short. I have the impression that it is an effect of tremolo, rather than an effect of vibrato. I tried to create a wave with this sound effect. The problem is that this code does not work. Do you understand the problem?
        (setq depth 2)
        (setq vibrato-freq 8)
        (setq depth (* depth 0.01))

        (defun mysound ()
        (scale 0.5 (hzosc 697)))

        (abs-env
        (mysound (integrate (sum 1 (mult depth (hzosc vibrato-freq))))))

        1. If you want a tremolo effect, that is a lot easier to do – I’ll post something if you like, but first for the job in hand…

          The important function in this vibrato effect is SND-COMPOSE (see: http://www.cs.cmu.edu/~rbd/doc/nyquist/part8.html#index667 ) but you’ve missed that in your code.

          Also, you have defined MYSOUND as a function, but are then treating it as a variable. A function call needs to be in parentheses (brackets) and in the form:
          (function-name arguments)
          In the case of MYSOUND there are no following “arguments” so all you need is (mysound).

          Try something like this:

          (setq depth 2)
          (setq vibrato-freq 8)
          (setq depth (* depth 0.01))

          (defun mysound ()
          (scale 0.5 (hzosc 697)))

          (abs-env
          (snd-compose (mysound) (integrate (sum 1 (mult depth (hzosc vibrato-freq))))))

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.