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.

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

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

"Amplification" is just "multiplication".
"Multiplying a sound" applies the multiplication factor to each sample value, thereby scaling the amplitude. Multiplying by x2 is very close to +6 dB boost. Multiplying by 0.5 is very close to -6 dB (reduction).

Note that for sounds you can't use (* A B), you have to use "mult" (mult A B).

There are a couple of handy conversion functions:
DB-TO-LINEAR converts a number from dB scale to linear scale
LINEAR-TO-DB converts a number from linear scale to dB scale

Example: Amplify the selected audio in a track by -3 dB
Code: Select all
(mult *track* (db-to-linear -3.0))
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 44161
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 8:18 pm

Thanks a lot. I created a code like this
Code: Select all
;version 4
;type generate
(defun tone ()
  (mult (osc (hz-to-step 1000) 0.25))
        (pwlv 0 0.02 1 0.23 1 0.25 0)
(mult tone (db-to-linear (* -5 (+ 1 (random 10)))))

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

(seqrep (i 200)
  (seq (cue (rest))(cue tone)))


I still get errors after debugging. Could you take a look ? You are a huge help :)
PiTeRr
 
Posts: 16
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 9:10 pm

I think you could do with a better text editor - one that has "parentheses matching". Counting the brackets will send you crazy ;)

Try NotePad++ (https://notepad-plus-plus.org/) and set the language option to "Lisp" (There are enough similarities between the "Nyquist" and "Lisp" to make the syntax highlighting useful, even though not complete).

Apart from mismatched parentheses, there are just a couple of mistakes.

In the last line of your "tone" function, you have a variable called "tone", but that variable has not been defined. In fact, you don't need that variable at all. All you need to do is to multiply three things: the sound, the envelope and the random scale factor.

The other error is in the final line. You are using "tone" as is if it is a "variable" when actually it is now a "function".

Suggestion: Now that both "rest" and "tone" are functions, we don't need to CUE them. They are simply generated (as "behaviors") when and where SEQREP requires them, so that last couple of lines may be simplified as:

Code: Select all
(seqrep (i 200)
  (seq (rest) (tone)))
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 44161
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 9:55 pm

Code: Select all
;version 4
;type generate
(defun tone ()
  (mult (osc (hz-to-step 1000) 0.25))
        (pwlv 0 0.02 1 0.23 1 0.25 0)
(mult (db-to-linear (* -5 (+ 1 (random 10))))))

(defun rest ()
  (s-rest (+ 1.8 (rrandom))))
 
(seqrep (i 200)
  (seq (rest) (tone)))


I think every parentheses match in this code above, cause I checked in Notepad++ and I still get errors after debugging. What can be wrong ? Thanks once again for a tremendous help :)
PiTeRr
 
Posts: 16
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 10:28 pm

PiTeRr wrote:I still get errors after debugging

Your errors are ...?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 44161
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 » Thu Aug 03, 2017 2:24 am

I will paste everything
Code: Select all
error: bad argument type - 0.316228
Function: #<Subr-SND-SRATE: #68781f8>
Arguments:
  0.316228
Function: #<FSubr-LET: #687b358>
Arguments:
  ((SND-SR (SND-SRATE SND)))
  (COND ((> SR SND-SR) (SND-UP SR SND)) ((< SR SND-SR) (SND-DOWN SR SND)) (T SND))
Function: #<FSubr-COND: #687b458>
Arguments:
  ((ARRAYP SND) (LET* ((LEN (LENGTH SND)) (RESULT (MAKE-ARRAY LEN))) (DOTIMES (I LEN) (SETF (AREF RESULT I) (FORCE-SRATE SR (AREF SND I)))) RESULT))
  (T (LET ((SND-SR (SND-SRATE SND))) (COND ((> SR SND-SR) (SND-UP SR SND)) ((< SR SND-SR) (SND-DOWN SR SND)) (T SND))))
Function: #<Closure-FORCE-SRATE: #68c6a38>
Arguments:
  44100
  0.316228
Function: #<FSubr-PROGV: #6879578>
Arguments:
  (QUOTE (*WARP*))
  (IF (WARP-FUNCTION *WARP*) (LIST (LIST (SREF-INVERSE (WARP-FUNCTION *WARP*) T0) (WARP-STRETCH *WARP*) (WARP-FUNCTION *WARP*))) (LIST (LIST T0 (WARP-STRETCH *WARP*) NIL)))
  (CHECK-T0 (FORCE-SRATE S%RATE (TONE)) (QUOTE (FORCE-SRATE S%RATE (TONE))))
Function: #<FSubr-PROGV: #6879578>
Arguments:
  (QUOTE (*WARP* *SUSTAIN* *START* *LOUD* *TRANSPOSE* *STOP* *CONTROL-SRATE* *SOUND-SRATE*))
  (QUOTE ((0 1 NIL) 1 -1e+021 0 0 1e+021 2205 44100))
  (AT-ABS T0 (FORCE-SRATE S%RATE (TONE)))
Function: #<Closure: #6924990>
Arguments:
  2.70984
1>
PiTeRr
 
Posts: 16
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 Aug 03, 2017 2:26 pm

I'll try to show you how I approach debugging...

The first line:
Code: Select all
error: bad argument type - 0.00316228

Looking through the code, there's only one place in the code that can have come from, and that's dB amplitude value.

Let's check...
In the code we have:
Code: Select all
(db-to-linear (* -5 (+ 1 (random 10))))

so if that is where the first error came from, then "0.00316228" should be equivalent to a dB value that is a multiple of 5, so we can check if it is:
Code: Select all
(print (linear-to-db 0.00316228))

and sure enough, that's -50 dB (prints as -49.999994)

So now we look at the context. Find the first pair of matched parentheses outside of the db-to-linear function:
Code: Select all
(mult (db-to-linear (* -5 (+ 1 (random 10)))))

What are we multiplying "(db-to-linear (* -5 (+ 1 (random 10))))" with? Nothing!

What do we want to multiply "(db-to-linear (* -5 (+ 1 (random 10))))" with?
We want to multiply it with
(osc (hz-to-step 1000) 0.25))
and
(pwlv 0 0.02 1 0.23 1 0.25 0)

so what we should have here is:
Code: Select all
(mult (osc (hz-to-step 1000) 0.25))
      (pwlv 0 0.02 1 0.23 1 0.25 0)
      (db-to-linear (* -5 (+ 1 (random 10))))


Try changing that, check that the parentheses all match up in pairs, and then see if there are further errors.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 44161
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 » Thu Aug 03, 2017 2:58 pm

Huge thanks to you :) I checked every parenthesis and now it works perfectly :) this is the final code that works :)
Code: Select all
;version 4
;type generate
(defun tone ()
  (mult (osc (hz-to-step 1000) 0.25)
        (pwlv 0 0.02 1 0.23 1 0.25 0)
(db-to-linear (* -5 (+ 1 (random 10))))))

(defun rest ()
  (s-rest (+ 1.8 (rrandom))))
 
(seqrep (i 200)
  (seq (rest) (tone)))


How can I make it up to you :) ?
PiTeRr
 
Posts: 16
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 Aug 03, 2017 3:41 pm

Congratulations :D

If you wanted to tidy up the indentation to aid readability (highly recommended when dealing with longer code), the final line of the "tone" function could be indented to line up with the other "mult" parameters like this:

Code: Select all
(defun tone ()
  (mult (osc (hz-to-step 1000) 0.25)
        (pwlv 0 0.02 1 0.23 1 0.25 0)
        (db-to-linear (* -5 (+ 1 (random 10))))))


Probably not important in this case, but if you wanted to make the code more efficient, we don't actually need to generate the tone and the envelope for each instance - we could just generate them once and call a new dB gain factor each time like this:

Code: Select all
;version 4
;type generate
(defun tone ()
  (mult (osc (hz-to-step 1000) 0.25)
        (pwlv 0 0.02 1 0.23 1 0.25 0)))

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

(defun gain ()
  (db-to-linear (* -5 (+ 1 (random 10)))))

(let ((tone (tone)))
  (seqrep (i 200)
    (seq (rest) (cue (mult (gain) tone)))))

(this version runs about 2 times faster than the previous version).
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 44161
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 » Thu Aug 03, 2017 4:03 pm

Thank you for all the tips and letting me know there is more efficient way to run this code :) Out of pure curiosity : is it possible to incorporate 0 dB amplification into this randomized function of amplification to be able to incorporate basic sound into this randomized track ?
PiTeRr
 
Posts: 16
Joined: Thu Jul 27, 2017 6:15 pm
Operating System: Windows 10

PreviousNext

Return to Windows



Who is online

Users browsing this forum: No registered users and 12 guests