Reputation: 1
I need to add white noise at a constant dB level to batches of sound files using Audacity. The Generate plugin 'Noise' is essentially what i'm looking for, but it can't be used to add noise to files in a chain since it overwrites each file rather than adding the white noise to it. There's an Effect plugin 'Add Noise' which is also very close to what i need, but the white noise is added as a percent of the total noise in each file, rather than adding it at a constant dB level to each file.
I'm trying to edit the code for the 'Add Noise' plugin using 'Nyquist Prompt' in order to change the noise level setting from a percent to dB, but am at a loss for what the new code should be. I think the 2 lines i need to change are lines 9 and 13, but again, i'm not totally sure. The 'Add Noise' plugin came from Audacity forum.
;nyquist plug-in
;version 3
;type process
;categories "http://lv2plug.in/ns/lv2core#GeneratorPlugin"
;name "Add Noise ..."
;action "Adding Selected Noise ..."
;info "by 'Steve Daulton.\nReleased under GPL V2."
;control mix "Noise mix (%)" real "" 20 0 100
;control type "Type of Noise" choice "White,Pink,Crackle,Wind" 0
(setf mix (/ mix 100))
;;; Wind noise by Robert J. H.
(defun wind (gust speed)
(defmacro contour (scale offset min-wind max-wind)
`(sum ,offset
(mult ,scale
(s-abs (reson (noise) ,min-wind ,max-wind 1)))))
(mult 2
(contour 300 0.7 gust speed)
(sim (reson (noise) 593 80 2)
(reson (noise) (contour 300000 300 gust speed) 200 2))))
;;; pink noise
(defun pink ()
(setf params (list '(25600 -4 2.0) '(12800 -3 2.0) '(6400 -2 2.0) '(3200 -1 2.0)
'(1600 0 2.0) '(800 1 2.0) '(400 2 2.0) '(200 3 2.0) '(100 4 2.0)
'(50 5 2.0) '(25 6 2.0) '(12.5 7 2.0)))
(force-srate *sound-srate*
(sound-srate-abs 96000
(progn
(setf colour-noise (noise))
(dotimes (i (length params))
(setf colour-noise
(eq-band colour-noise
(first (nth i params))
(second (nth i params))
(third (nth i params)))))
(lowpass2 colour-noise 25600 0.5)))))
;;; crackle
(defun crackle (density)
(defun clicks ()
(let ((mynoise (mult 1.33 (lp (noise) 1000)))
(density (max
(- 0.9 density)
0.1)))
(clip
(mult (/ (- 1 density))
(diff (s-max mynoise density) density))
1.0)))
(sum (clicks) (mult -1 (clicks))))
;;; mix two mono sounds
(defun mono-mix (snd1 snd2 mix)
(sim (mult (- 1 mix) snd1)
(mult mix snd2)))
;; select the type of noise
(setf my-noise
(case type
(0 (noise))
(1 (pink))
(2 (crackle 0.4))
(t (let ((gustiness 0.2)
(wind-speed 0.2))
(wind gustiness wind-speed)))))
; stereo mix sound and noise
(multichan-expand #'mono-mix s my-noise mix)
Upvotes: 0
Views: 384
Reputation: 1
Steve (site admin on Audacity Forum) edited the code for me. Line 9, 13 and 58 needed to be changed. Here's my post on the Audacity Forum.
;nyquist plug-in
;version 3
;type process
;categories "http://lv2plug.in/ns/lv2core#GeneratorPlugin"
;name "Add Noise ..."
;action "Adding Selected Noise ..."
;info "by 'Steve Daulton.\nReleased under GPL V2."
;control level "Noise level (0 to 1)" real "" 0.5 0 1
;control type "Type of Noise" choice "White,Pink,Crackle,Wind" 0
(setf mix level)
;;; Wind noise by Robert J. H.
(defun wind (gust speed)
(defmacro contour (scale offset min-wind max-wind)
`(sum ,offset
(mult ,scale
(s-abs (reson (noise) ,min-wind ,max-wind 1)))))
(mult 2
(contour 300 0.7 gust speed)
(sim (reson (noise) 593 80 2)
(reson (noise) (contour 300000 300 gust speed) 200 2))))
;;; pink noise
(defun pink ()
(setf params (list '(25600 -4 2.0) '(12800 -3 2.0) '(6400 -2 2.0) '(3200 -1 2.0)
'(1600 0 2.0) '(800 1 2.0) '(400 2 2.0) '(200 3 2.0) '(100 4 2.0)
'(50 5 2.0) '(25 6 2.0) '(12.5 7 2.0)))
(force-srate *sound-srate*
(sound-srate-abs 96000
(progn
(setf colour-noise (noise))
(dotimes (i (length params))
(setf colour-noise
(eq-band colour-noise
(first (nth i params))
(second (nth i params))
(third (nth i params)))))
(lowpass2 colour-noise 25600 0.5)))))
;;; crackle
(defun crackle (density)
(defun clicks ()
(let ((mynoise (mult 1.33 (lp (noise) 1000)))
(density (max
(- 0.9 density)
0.1)))
(clip
(mult (/ (- 1 density))
(diff (s-max mynoise density) density))
1.0)))
(sum (clicks) (mult -1 (clicks))))
;;; mix two mono sounds
(defun mono-mix (snd1 snd2 mix)
(sim snd1
(mult mix snd2)))
;; select the type of noise
(setf my-noise
(case type
(0 (noise))
(1 (pink))
(2 (crackle 0.4))
(t (let ((gustiness 0.2)
(wind-speed 0.2))
(wind gustiness wind-speed)))))
; stereo mix sound and noise
(multichan-expand #'mono-mix s my-noise mix)`
Upvotes: 0