Adding background noise oder background muisc

I know how I can to that (see subject) manually.

Unfortunately I have to process a lot of mp3 files.

Am I right, that Audacitys batch mode won’t help me without a plug in?

How can I add for example a brown noise to a track by using Nyquist?

Can I use within Nyqusit another track with music to add this as background music to my original track?

Is there another way to do what I want with plenty of mp3 files?

Hi silencesound
A lot of things can be done by Nyquist but we must know what exactly you want to do.
You could for example:

  • Import all mp3’s
  • select all tracks you want noise to be added to.
  • add the noise via the Nyquist prompt or a specially created plug-in
  • export the tracks again.

That’s about the simplest way that I can think of.
Here is an example that mixes a wind-like sound to the selected tracks. Select your tracks, open the Nyquist prompt from the effect menu, insert the code and press OK. You can change the level to any number you like. -20 dB is a ratio of 0.9 original sound and 0.1 the wind. -6 dB would be 0.5 to 0.5.

(setf level (db-to-linear -20))
(defmacro contour (scale offset)
  `(sum ,offset (mult ,scale (s-abs (reson (noise) 0.1 0.2 1)))))
(setf wind  
  (mult (contour 300 0.7) 
        (sim (reson (noise) 593 80 2)
             (reson (noise) (contour 300000 300)200 2))))
(multichan-expand #'sim (mult (- 1 level)s) (mult level wind))

What is meant by background music? Should every track take the same music and when, over the whole length?
One would normally use the autoduc tool to ensure that the background music is really in the background when the important sounds appear.

If you want to “batch process” a lot of files and add noise to each, then I think that you would need to use a plug-in to add the noise. The plug-in could be called from a “Chain”. I don’t know of any existing plug-ins that do this, but in principle it would not be difficult to write one, though (as Robert J. H. wrote) it would depend on exactly what you are wanting to do.

Many thanks for the code.
A first try of a plugin is attached.

AutoDuck would be great, but can I use it form within a Nyquist plugin?
backgroundnoise.ny (733 Bytes)

Topic moved to the new plug-ins section.

Well done, that seems to work fine. :stuck_out_tongue:
One little comment, the “Audio Level” setting is possibly misleading as it is actually a “mix” control rather than a “level” control.
Also, for anyone that has not studied the code it is not clear what “min ‘wind’” and “mx ‘wind’)” will do (probably a typo there too.

The last line of the plug-in mixes the noise (in this case “wind noise”) with the original sound.
This approach can be used for mixing any type of generated sound with the currently selected audio, for example this plug-in (attached) has options for white noise, pink noise, crackle and wind noise.
AddNoise.ny (2.02 KB)

You can’t access other Audacity effects from within a Nyquist plug-in, but you may be able to create a similar effect in Nyquist code,
What are you wanting to do?

That’s a really cool plug-in, Steve.
The crackle sound is very useful for a song, i’ve written, which starts as an old fashioned vinyl Single.
My wind code is a little coarse, written adhoc. I gave the name “level” on purpose, because the wind is not normalized, the sounds won’t therefore add up to 0 dB (wet&dry).

Maybe we can add some other interesting (noisy) sounds. There’s of course the sea/surf theme that comes first to mind. Or the murmering of people in a restaurant.
Here’s another little snippet with an flamenco touch to it (palmas and foot stamping). Maybe you can use it for this plug-in or for your drum machine.

;; palmas
(Defun  do-that-clap (step)
    ((envelope (exp-dec 0.005 0.007 0.1)) 
    (clap (force-srate 44100 (scale-srate (mult  envelope (noise)) (/ step 150.0)))))
      (pan (mult 0.5 clap) (real-random 0.1 0.9))))

(set-sound-srate *sound-srate*)
(setf s (abs-env (simrep (num 12) (stretch (/ (power 2 (random 2))   12.0)   
  (at  num  (do-that-clap (real-random 5.0 25.0))))) ))
(setf l (aref s 0))
(setf r (aref s 1))
(seqrep (measure 10) (vector l r))

I borrowed it from an old snippet that I’d written for exactly the same purpose :slight_smile:
The original version created a short section of absolute duration that could be set to match the required rpm (33, 45, 78)
The function would run twice to provide two slightly different sounds. One would be repeated a few times before fading into several repeats of the other and so on.
I’d intended to make it into a plug-in at some point but never got round to it.

I like it.
I added a multiplier of 2 to give it a peak level closer to 0 dB without needing to normalize.

Generating pink noise is a pain.
Can you think of an easier way to do that?

Ooh, that’s an interesting one.
It’s a shame there aren’t a few more Nyquist coders active on the forum - we could have a lot of fun with this sort of thing.


There’s another one that I should really get round to finishing.

Yes creating sounds makes the most fun and Nyquist was made for just this purpose.
We sometimes move too far away from this scope and limit ourselves to DSP.
I’ve written about 200 lines code for an hammond emulation.
I’ve taken all the original gear ratios for the tone wheels and all original draw bar measurements. But the point where I got lost was the implementation of the chorus effect with a serie of lowpassfilters.
I guess that you struggle too with the lowpass filter for the pink noise. It gives one really pain in the neck to get this -3 dB (if I am not mistaken) attenuation right.
My only solution would be via a custom-tailored window-function. But a speedy and economic implementation can only be done when the fft functions work properly.

Here’s another snippet with an original “helvetic” (swiss) touch to it…

(defun alphorn (pitch dur)
    ((dur (get-duration dur))
    (contour (stretch dur (pwev 1e-05  0.03 1 0.85 1 1 1e-5))))
      (mult 0.3 contour (fmosc (hz-to-step pitch) 
               (eq-band (noise dur) pitch 120 0.11)))))

(defun melody (step)
    ((pitch (step-to-hz step)))
        (at 0 (alphorn pitch 4.05))
        (at .5 (alphorn (* pitch (+ 2 (random 3))) 0.9))
        (at 1.0  (alphorn (* pitch (+ 3  (random 4))) 0.7))
        (at 1.3 (alphorn (* pitch (+ 2    (random 4))) 0.8))
        (at 1.6 (alphorn (* pitch (+ 1  (random 4))) 0.7 ))
        (at 2.0  (alphorn (* pitch (+ 2  (random 4)))0.4))
        (at 2.2 (alphorn (* pitch (+ 2    (random 5))) 0.9))
        (at 2.3 (alphorn (* pitch (+ 2  (random 5))) 1.4 ))
        (at 3 (alphorn (* pitch (+ 2  (random 4)))1)))))

(defun duet ()
  (stretch 2 (sim (pan (melody c3) 0.3)
       (at 0.3 (pan (melody c2) 0.8)))))
(set-sound-srate *sound-srate*)

I found an effect in AddNoise:
The resulting volume is a mixture from the original sound and the background sound.
That means if you start with the parameter set to 20 the resulting original sound is only about 80% of the original volume.

Is that indented?
Is there a workaround?

Is there an easy way to include a kind of simple auto duck functionality?
Maybe that could even be the workaround from above?

Yes that is intended.
The reason for it is that when you add sounds together the overall amplitude tends to increase. This could cause the peak level to exceed 0 dB which would result in “clipping” the peaks and causing an unpleasant distortion.
The “workaround” would be to change the code.

I presume that you mean that you want less noise where the original sound is above a certain level so that the noise mostly occurs during quiet periods. Is that what you want?
It would be a lot of work to try and implement all 7 controls from the Auto Duck effect, but a similar type of effect with less controls could probably be implemented more easily.
Why don’t you tell us exactly what it is that you are wanting to do. It would be a lot easier for us to help you if we knew what the job was.

An easy way would be to take the code from SilenceFinder.ny oder SoundFinder.ny an apply in the silent parts more background noise then in the sound parts.

noise mix (sound)
noise mix (silent)
level for silence

It would probably be easier and would certainly be more efficient to create a control signal that follows the amplitude of the sound and then use that control signal as a gain envelope - in effect “gating” the sound when the signal is over a threshold level.
It would still be easier if we knew what this was for :wink: