# Wind Tutorial

This page describes a "wind" effect created by Alex. The basic function is as follows.

Note: all examples use SAL syntax followed by Lisp syntax in a smaller font. Since SAL does not support optional parameters, keyword parameters are used instead, so these implementations are not exactly equivalent.

    function wind(dur: 3, scal: 3, cps: 590, bw: 40)
      return (env(0.07, 0.08, 0.1, 1, 0.6, 0.8, 1) *
    	  (reson(scal * noise(), cps, bw, 2) +
    	   reson(scal * 1.13 * noise(),
                     cps * pwl(0, 0.74, 0.2, 0.96, 0.5, 0.8,
                               0.75, 1.16, 0.9, 0.97, 1, 0.74, 1),
                     bw * 1.042, 2))) ~ dur

    (defun wind (&optional (dur 3) (scal 3) (cps 590) (bw 40))
      (stretch dur
        (mult (env 0.07 0.08 0.1 1 0.6 0.8 1)
    	  (sum
    	    (reson (scale scal (noise)) cps bw 2)
    	    (reson (scale (mult scal 1.13) (noise))
                       (mult cps (pwl 0 0.74 0.2 0.96 0.5 0.8 0.75 1.16 0.9 0.97 1 0.74 1))
                       (mult bw 1.042)
                       2)))))

The basic idea is to use bandpassed noise to create the sound of wind. In this example, two bandpass filters are added together. The first uses a fixed center frequency and bandwidth, and the second uses a piece-wise linear function to control the center frequency. The entire sound is multiplied by an envelope and stretched to the desired duration. Note how several optional parameters can be used to change the default behavior.

A slight elaboration of the wind function uses several copies of wind in sequence with slight overlap:

    function multiwind()
      return simrep(i, 4, wind() @ (i * 2.9))

    (defun multiwind ()
      (simrep (i 4) (at (* i 2.9) (wind))))

One problem with this approach is that the wind sound becomes periodic. This could be solved by using noise or random numbers to generate the center frequency variation rather than a fixed envelope.