Adding randomized silence (Windows 10, Audacity 2.1.3)

Help for Audacity 2.x.x on Windows.

ImageThis forum is for Audacity 2.x.x on Windows.

  • Please state which version of Windows you are using, the exact three-section version of Audacity from Help > About Audacity and whether you obtained the .exe installer or the zip.

  • Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
    The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.

Adding randomized silence (Windows 10, Audacity 2.1.3)

Permanent link to this post Posted by PiTeRr » Thu Jul 27, 2017 6:29 pm

Hello :)

I've been currently working on my thesis where I'm supposed to create track which should consist of tones at frequency of 1000 Hz and different levels of gain (their duration is 250 ms). Between those tones there is supposed to be randomized silence according to the formula : silence:= 1800 ms + random(1000), so the silence is supposed to range from 1800 ms to 2800 ms. I'm deeply asking for help in writing formula that can realise this task. Thanks in advance for helping the newbie :)
PiTeRr
 
Posts: 22
Joined: Thu Jul 27, 2017 6:15 pm
Operating System: Windows 10

Re: Adding randomized silence (Windows 10, Audacity 2.1.3)

Permanent link to this post Posted by steve » Thu Jul 27, 2017 9:31 pm

I hope I'm not doing your homework for you ;)
Try running this in the Nyquist Prompt effect::

Code: Select all
;version 4
;type generate
(setf tone
  (mult (osc (hz-to-step 1000) 0.25)
        (pwlv 0 0.01 0.8 0.24 0.8 0.25 0)))

(defun rest ()
  (s-rest (+ 1.8 (rrandom))))

(seqrep (i 20)
  (seq (cue (rest))(cue tone)))
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 44206
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Adding randomized silence (Windows 10, Audacity 2.1.3)

Permanent link to this post Posted by PiTeRr » Fri Jul 28, 2017 4:09 am

Thank you for the reply and help :) To be honest, you almost did my homework and your post is a lot of help :o In this track I'm supposed to conclude tones at frequency of 1000 Hz and 10 different levels of gain that ranges from -5 dB to -45 dB in reference to basic sound which whole duration time is 250 ms (accretion time is 20 ms, duration is 210 ms and descent time is 20 ms) and amplitude is 1. Between those tones there is supposed to be a silence as I described in the previous post. I'm a complete newbie to programming in Nyquist so I would be very grateful if it was possible to get even very short explanation what this code came from :)
PiTeRr
 
Posts: 22
Joined: Thu Jul 27, 2017 6:15 pm
Operating System: Windows 10

Re: Adding randomized silence (Windows 10, Audacity 2.1.3)

Permanent link to this post Posted by PiTeRr » Tue Aug 01, 2017 2:23 pm

Hi :)
Could I count on help with my issue ? Big thanks in advance and best greetings :)
PiTeRr
 
Posts: 22
Joined: Thu Jul 27, 2017 6:15 pm
Operating System: Windows 10

Re: Adding randomized silence (Windows 10, Audacity 2.1.3)

Permanent link to this post Posted by steve » Tue Aug 01, 2017 4:19 pm

PiTeRr wrote: would be very grateful if it was possible to get even very short explanation what this code came from

Anything after a semicolon is treated by Nyquist as a "comment" and is ignored by Nyquist.

The first couple of lines are special "comments" in that they are ignored by Nyquist, but mean something to Audacity. These comments are referred to as "headers" (they usually occur at the head (top) of the script. More about Nyquist plug-in headers here: http://wiki.audacityteam.org/wiki/Nyqui ... -in_Header

Code: Select all
;version 4
;type generate
;; The two lines above tell Audacity to treat the code as "version 4" plug-in code
;; and treat it as a "Generator".

A significant difference between "generate" type effects and "process" type effects is in how they deal with time.
For a "process" type effect, "1 unit" of time is equivalent to the duration of the selection. In other words, time is relative to the duration length.
For "generate" type effects, "1 unit" of time is 1 second. In other words, "local time" (in the plug-in) is equivalent to "global time" (real time outside of the plug-in).


Code: Select all
;; Set the value of the variable 'tone' to a sound that is created
;; by multiplying a 1000 Hz, 0.25 seconds oscillator, by a control signal.
;; The control signal is created by PWLV
(setf tone
  (mult (osc (hz-to-step 1000) 0.25)
        (pwlv 0 0.01 0.8 0.24 0.8 0.25 0)))

http://www.cs.cmu.edu/~rbd/doc/nyquist/ ... l#index381
http://www.cs.cmu.edu/~rbd/doc/nyquist/ ... #index1630
http://www.cs.cmu.edu/~rbd/doc/nyquist/ ... l#index410
Here, PWLV creates an "envelope" that rises from 0 at time=zero to 0.8 and time=0.1, then falls from 0.8 at time=0.24 to zero at time=0.25
OSC generates the 1000 Hz tone of duration 0.25 seconds ("seconds" because it is "generate" type plug-in code) with an amplitude of 1.
MULTiplying the tone by the control signal, scales the amplitude of each sample in the tone by the respective level in the control signal.


Code: Select all
;; Define a function 'REST' that generates silence
;; for a random duration of 1.8 + (random value 0 to 1)
(defun rest ()
  (s-rest (+ 1.8 (rrandom))))

http://www.audacity-forum.de/download/e ... ef-087.htm
http://www.cs.cmu.edu/~rbd/doc/nyquist/ ... l#index573
http://www.cs.cmu.edu/~rbd/doc/nyquist/ ... #index1630
The reason that we use a function here rather than a variable, is because we need to regenerate each instance of the silence so that we get different lengths of silence each time.



Code: Select all
;; Repeat a sequence of behaviours for i = 0 to 20
;; The 'behaviour' is to sequence the silence produced by the REST function
;; with the CUEd sound "tone"
(seqrep (i 20)
  (seq (cue (rest))(cue tone)))

http://www.cs.cmu.edu/~rbd/doc/nyquist/ ... l#index611
http://www.cs.cmu.edu/~rbd/doc/nyquist/ ... l#index610
http://www.cs.cmu.edu/~rbd/doc/nyquist/ ... l#index344
The important thing that CUE does for us, is that it allows us to use a "sound" as a "behaviour". This is really the tricky part to explain, but you can read about it here: http://www.cs.cmu.edu/~rbd/doc/nyquist/part4.html#30
If we didn't CUE the sounds, then it would still work, but Nyquist would complain and create debug warnings.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 44206
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Adding randomized silence (Windows 10, Audacity 2.1.3)

Permanent link to this post Posted by steve » Tue Aug 01, 2017 4:32 pm

PiTeRr wrote:I'm supposed to conclude tones at frequency of 1000 Hz and 10 different levels of gain that ranges from -5 dB to -45 dB in reference to basic sound which whole duration time is 250 ms (accretion time is 20 ms, duration is 210 ms and descent time is 20 ms) and amplitude is 1

So instead of creating "tone" as a variable with a fixed sound value, you will need to define a function that returns the required sound each time it is called.

Use DEFUN to define the function.
PWLV to create the envelope.

Once you have defined a function "tone", assuming that you are not sending parameters to the function, you would call it by writing the name of the function in parentheses
(tone)
as we did previously with
(rest)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 44206
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Adding randomized silence (Windows 10, Audacity 2.1.3)

Permanent link to this post Posted by PiTeRr » Wed Aug 02, 2017 10:27 am

Thanks a lot for this very comprehensive explanation, it's a huge help :) I'm wondering if and how it is possible to randomize also gain cause it is supposed to be random in the range -5 dB to -45 dB, but these sound levels should change exactly of amount 5 dB. For example first appeared sound's gain is -5 dB in reference to basic sound, then -15 dB to basic sound, then -45 dB to basic sound and so on. I mean randomized gain change of multiple of 5 dB in reference to basic sound. I was thinking about making a rrandom function in a pwlv envelope multiplied by 5 and also a truncate function to truncate it to an integer and recieve a condition of change of exactly multiple of 5 dB), but I think I'm still missing something or overcomplicate it. I would be very grateful for further tips.

P.S. Out of pure curiosity : Is it possible to change (mult (osc (hz-to-step 1000) 0.25) (pwlv 0 0.01 0.8 0.24 0.8 0.25 0))) to this function (osc-note pitch [duration env loud table]). I think the second function does exactly the same, but I can be wrong.
PiTeRr
 
Posts: 22
Joined: Thu Jul 27, 2017 6:15 pm
Operating System: Windows 10

Re: Adding randomized silence (Windows 10, Audacity 2.1.3)

Permanent link to this post Posted by steve » Wed Aug 02, 2017 11:28 am

PiTeRr wrote:P.S. Out of pure curiosity : Is it possible to change (mult (osc (hz-to-step 1000) 0.25) (pwlv 0 0.01 0.8 0.24 0.8 0.25 0))) to this function (osc-note pitch [duration env loud table]). I think the second function does exactly the same, but I can be wrong.

Yes you could, but you would still need to define "env" as a "sound" (control signal) because the alternative syntax "(t1 t2 t4 l1 l2 l3)" does not give you enough control points.

Got to dash - back in a bit to answer your other question.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 44206
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Adding randomized silence (Windows 10, Audacity 2.1.3)

Permanent link to this post Posted by steve » Wed Aug 02, 2017 12:52 pm

PiTeRr wrote:I was thinking about making a rrandom function in a pwlv envelope multiplied by 5 and also a truncate function to truncate it to an integer and recieve a condition of change of exactly multiple of 5 dB)

There's a random integer function that you could use:
http://www.cs.cmu.edu/~rbd/doc/nyquist/ ... #index1629
For multiples of 5, simply generate an integer in an appropriate range, and multiply by 5 (-5 for negative numbers)
For example:
Code: Select all
(* -5 (+ 1 (random 10)))  ;generate a random number between -5 and -50
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 44206
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Adding randomized silence (Windows 10, Audacity 2.1.3)

Permanent link to this post Posted by PiTeRr » Wed Aug 02, 2017 5:05 pm

Big, big thanks :) this is clear, but how to manipulate amplification of created sound ? I was thinking about randomizing it inside envelope but I don't know if an amplitude changes linearly proportional to a change of amplification, cause inside an envelope we can change an amplitude. No more ideas come to my head when it comes to that issue. I need to ask for help once again :)
PiTeRr
 
Posts: 22
Joined: Thu Jul 27, 2017 6:15 pm
Operating System: Windows 10

Next

Return to Windows



Who is online

Users browsing this forum: No registered users and 13 guests