138

I have a three week old baby. Occasionally she refuses to sleep. Some people tell me this is the way life is, some people tell me I need to buy things to fix it. This is becoming an alarmingly common pattern in this parenting game.

Anyway one of these things "I need to buy" is a white noise generator. White noise defined as:

a random signal is considered "white noise" if it is observed to have a flat spectrum over the range of frequencies that is relevant to the context. For an audio signal, for example, the relevant range is the band of audible sound frequencies, between 20 to 20,000 Hz.

There are several things I can buy. Apps for Android, dedicated boxes that I'm sure just play a tiny clip of pre-generated noise, all the way to mega-expensive true-random white noise generators.

I want to generate my own white noise sample

I know I could download one with youtube-dl from one of the many videos out there but copyright aside, frequency compression is horrible online I want full-white-frequency goodness. If such a thing actually exists. Plus I'm a glutton for punishment and I believe that if something can be done via the command line, that's the way we should be doing it. That's how I aim to raise this one anyway.

So we have things like /dev/urandom and paplay. Is there a sensible way to take random data and channel it into the audible range of white noise and out of my speakers? Answers that write to file are okay too. The important thing is a steady range-confined sample. No squawks.

Note: answers that generate the brown note will not be appreciated ☹

Oli
  • 299,380

14 Answers14

186

Use the Swiss army knife for sound generation, SoX.

You install it from the official repositories, simply by typing:

sudo apt-get install sox

Updated, fancy answer (pleasing ocean waves):

After experimenting a bit with SoX, I came up with this great command which imitates the soft murmur of the sea with its soothing sound of waves that flow over a flat sandy beach on a sunny summer day...

Well, enough poetry, here's the command. Listen yourself.

play -n synth brownnoise synth pinknoise mix synth sine amod 0.3 10

Explanation:

This command first generates and mixes brown noise and pink noise, which I find to be the most comfortable and natural noise. Then it generates a sine wave of 0.3 Hz with an offset of 10% and uses this to modulate the amplitude of our mixed noises to produce the sound of ocean waves.

Modifications:

  • Timer:
    You can add a timer and limit the playback duration by specifying the number of seconds, the number of minutes and seconds (mm:ss) or the number of hours, minutes and seconds (hh:mm:ss) right before brownnoise. Here's an example for one hour:

    play -n synth 1:0:0 brownnoise synth pinknoise mix synth sine amod 0.3 10
    
  • Wave frequency:
    If you want the waves to hit the beach more or less frequent, simply change the frequency of the sine wave used for amplitude modification (0.3 in the above command). The number represents the amount of waves per second, so a frequency of 0.1 Hz will cause 0.1 waves per second and therefore make one wave last for 10 seconds:

    play -n synth brownnoise synth pinknoise mix synth sine amod 0.1 10
    
  • Minimum background noise volume:
    The sine that is used for amplitude modulation got shifted to an offset of 10%, so the brown-pink noise will always be played with at least 10% volume. If you want a stronger or weaker background noise, increase or decrease this offset to your needs. Here's an example with 20% background noise:

    play -n synth brownnoise synth pinknoise mix synth sine amod 0.3 20
    

Old, boring answer (plain white noise):

Now the easiest command to play white noise infinitely (until you abort it with Ctrl+C) is this:

play -n synth whitenoise

If you prefer a time limit, you may add that in the format hh:mm:ss. The following command would make noise for one and a half hour, for example:

play -n synth 01:30:00 whitenoise

It even shows you some nice stats while "playing":

$ play -n synth 00:00:05 whitenoise 

  Encoding: n/a           
  Channels: 1 @ 32-bit   
Samplerate: 48000Hz      
Replaygain: off         
  Duration: unknown      

In:0.00% 00:00:05.12 [00:00:00.00] Out:240k  [!=====|=====!] Hd:0.0 Clip:0    
Done.
gliptak
  • 664
Byte Commander
  • 110,243
49

White noise is torture.

Especially for the delicate ears of babies.

This is because white noise has too much energy in the high frequencies.

Captain Man
  • 252
  • 1
  • 4
  • 13
32

You can generate pink noise using the play command from the sox utilities:

sudo apt-get install sox
play -t sl -r48000 -c2 -n synth -1 pinknoise .1 60

Adjust the values of .1 and 60 to suit your needs. Pink noise is less harsh on the ear and is hopefully the sound you require

25

Not sure that this will produce real white noise that covers the whole spectrum, but a simple

pacat /dev/urandom

seems to do the trick on my system (no need to install anything new or add a repository).

dadexix86
  • 6,776
17

I'm a glutton for punishment, so I'll give you the GUI way. Take a look at ANoise.

The default sound that it comes with is bad, but you can download other sounds like Forest Rain, Fountain, & Others. You can set it to start with the system, and even set it to stop after a certain time.

sudo add-apt-repository ppa:costales/anoise
sudo apt-get update
sudo apt-get install anoise

ANoise Code, And for For extra river sound:

sudo apt-get install anoise-community-extension1
muru
  • 207,228
Mitch
  • 109,787
12

Open Audacity.

Go into "Generate > Noise..."

Select "Brownian" (way less aggressive than actual white noise). Amplitude and duration does not matter much.

Loop using Shift+Play button.

Marin
  • 121
10

FFMpeg has an audio noise source filter. You can play it using ffplay:

ffplay -f lavfi -showmode 0 -i 'anoisesrc=color=brown'

The arg to -i is interpreted as a lavfi filter graph, because of -f lavfi. -showmode 0 disables ffplay's default audio visualizer window, which it shows by default for audio-only inputs.

As you can see from the output of ffmpeg -h filter=anoisesrc, you get a choice of brown/pink/white noise at whatever amplitude and samplerate you like, optionally with a finite duration.


You can also use mpv, a nice fork of mplayer, or other players that allow ffmpeg filtergraphs. e.g.

mpv  av://lavfi:anoisesrc=color=brown

This might be handy if you have a custom audio-output setup configured for your favourite player.

Peter Cordes
  • 2,287
7

The installed-by-default utility speaker-test generates pink noise (which, as @nightingale, is what you really want, not white noise). It can be set to do so indefinitely by running

speaker-test -l 0
heemayl
  • 93,925
Jules
  • 320
  • 1
  • 2
  • 12
7

I see that nobody has used aplay yet so try the following:

aplay --channels=2 --format=S16_LE --rate=44100 --duration=3600 /dev/urandom

It is not terribly imaginative so I have added in a timer to compensate :). The duration settings is in seconds so this will run for 1 hour and then turn off, hopefully the baby will have settled by then...

andrew.46
  • 39,359
3

Low-pass Brown noise

Sounds to me like a far away storm or a giant river/waterfall. Feel free to adjust frequency parameter 1k in Hz, filter poles -1 or -2, and output volume as gain parameter in dB.

play -n synth brownnoise lowpass -1 1k gain -10
qwr
  • 2,969
3

Tom Swiss of unreasonable.org uses the following code (using sox) to generate white/pink noise. You'll need to first install sox (sudo apt install sox), then create a shell script with the following code:

#!/bin/sh

len='7:00:00'

if [ "$1" != '' ]; then
  len=$1
fi

play -t sl - synth $len  pinknoise band -n 1200 200 tremolo 20 .1 < /dev/zero

Hat tip http://unreasonable.org/white_noise_generator_with_sox_for_Linux

Disclaimer: I have not tried this myself yet

muru
  • 207,228
3

White noise is mathematically an even distribution of frequencies. You can produce it with random data from /dev/random or /dev/urandom. If you want to change the "tone" of the produced noise (for example to make it less "weighty" by removing lower frequencies, or to make it "damper" by removing higher frequencies) then you could use a command such as dd bs=1 if=/dev/urandom of=whitenoise.raw count=1048576 to generate some white noise, then import it into Audacity and use the high-pass and low-pass filters to adjust it to your liking (when using the filters remember that the average human ear will hear frequencies up to 20kHz).

EDIT: Audacity can also generate white noise itself.

micheal65536
  • 938
  • 7
  • 13
0
  1. Take any old radio, tune into a frequency where there's no station, maybe (if possible) remove or collapse the antenna and turn it on.
  2. Use aplay /dev/random. It will generate white noise and play it. I don't think you have speakers powerful enough to output infrasound (e.g. brown noise) at enough decibels to cause problems, as you don't even have very big effects with 120db and I don't think you get anywhere near that with your speakers.
Lampe2020
  • 153
0

There's also Renoise, a very powerful multi-platform audio sequencer, though the full version is commercial. The demo version however doesn't have many limitations, and will let you do what you want, and add filters, effects, etc. to the generated sound.

http://www.renoise.com

True white noise with a lowpass filter, and maybe some chorus and reverb added for a nice natural effect, would sound quite pleasing.

delt
  • 343