135

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
  • 289,791
  • 117
  • 680
  • 835
  • 29
    See other answers for the techie side. Practical me says that there are CDs of surf/rain/waterfall noise that may not be mathematically pure white noise but are probably much closer to the soothing ear-candy you are looking for (and likely at the origin of the reputation of the white noise). – xenoid Jun 20 '16 at 21:22
  • 1
    @xenoid I will accept answers that virtually render the sounds of a waterfall ☺ – Oli Jun 20 '16 at 21:26
  • 5
    Would [this](https://gist.github.com/rsvp/1209835) work? – Mitch Jun 20 '16 at 21:30
  • @Mitch I'll send you the bill for dry-cleaning our sofa :) – Oli Jun 20 '16 at 21:31
  • @Oli I have paid a lot of them, one more won't hurt :) – Mitch Jun 20 '16 at 21:32
  • There's a package called `jnoise` in the repositories which should generate white or pink noise. I can't get it to run on my machine though, it requires JACK audio which I seem not to use... Maybe it works for you? – Byte Commander Jun 20 '16 at 21:46
  • 6
    The post that @Mitch pointed at is not in reference to the 'brown note'. "The term "Brown noise" does not originate from the color, but from Robert Brown who discovered Brownian motion." – Adrian Jun 20 '16 at 22:05
  • 2
    May I recommend https://mynoise.net/ . Its not quite the audiophile fidelity you mention, but stochastic noise like that is considered to be better for people's hearing than white noise or pink noise. In fact, too much white/pink noise in the formative years is actually associated with a lot of mental troubles down the road, presumably because they are put in an environment with no meaningful small signals to find. – Cort Ammon Jun 21 '16 at 04:26
  • 4
    Tune the radio away from any channel? – gerrit Jun 21 '16 at 10:36
  • @gerrit But FM radios are sooo old school... ;-) – Byte Commander Jun 21 '16 at 11:52
  • We just put a vacuum cleaner in the room, switched it on and left. That worked. –  Jun 21 '16 at 22:21
  • 13
    Unless you have already taught your baby [Pearson's chi-squared test](https://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test), true randomness isn't too big of a deal. – PyRulez Jun 22 '16 at 03:14
  • I use Death Metal and Black Metal for white noise. :D – MetalMikester Jun 22 '16 at 14:38
  • 1
    If you're OK with the web, I really like http://asoftmurmur.com/ for generating all kinds of white noise. It has white noise, waves, fire crackling, and settings for volume levels of different types of noises. My personal favorite mix: http://asoftmurmur.com/?v=00001200000000240008. – daboross Jun 22 '16 at 19:57
  • Related tag on [softwarerecs.se]: [noise-generator](http://softwarerecs.stackexchange.com/questions/tagged/noise-generator) – unor Jun 22 '16 at 21:50
  • 1
    "frequency compression is horrible online I want full-white-frequency goodness" -- as another new parent (11 months): you are over-thinking this. (In particular, as noted in one of the answers, per your stated goal of helping your infant sleep, you actually *don't* want real white noise.) – Kyle Strand Jun 22 '16 at 23:19
  • 1
    While most people commonly call it "white noise" you do not want *literally* white noise. That has all of the energy concentrated in high frequencies which is really harsh. You want "pink noise". The energy is evenly spread through the frequency spectrum. If you bought a "white noise generator" you will get something more like pink noise than white noise from it. – thomasrutter Jun 24 '16 at 04:41
  • Tons of youtube vids you can rip. We have ysed baby white noise for both our boys. – JohnP Jun 24 '16 at 21:38

13 Answers13

180

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
  • 604
  • 7
  • 13
Byte Commander
  • 105,631
  • 46
  • 284
  • 425
  • 6
    I edited my answer and added a fancy but simple ocean wave sound generator command which will please baby's (and daddy's) ears far more than plain white noise. – Byte Commander Jun 21 '16 at 10:06
  • 2
    I love this - but the sine wave volume change isn't really very much like the sound of waves on the beach. It needs to increase in volume quite quickly as the wave breaks on the beach, then fall away much more slowly. Is there a way to achieve that? – Caesar Jun 22 '16 at 00:16
  • 7
    @Caesar there's a limit to how good you can get with these tools, but I think `play -n synth brownnoise synth pinknoise mix synth 0 0 0 15 40 80 trapezium amod 0.2 10` is closer to what you're asking for :) – hobbs Jun 22 '16 at 05:21
  • 1
    @hobbs and now if the repetition frequency were not so regular ... ;-) :-P – Rmano Jun 22 '16 at 13:25
  • 1
    @Rmano that, I don't think is doable within sox :) – hobbs Jun 22 '16 at 18:33
  • Brown noise may lead to... extra diaper changes... – Hack-R Jun 25 '16 at 03:57
  • 1
    @Hack-R The [comments](http://askubuntu.com/questions/789465/generate-white-noise-to-calm-a-baby#comment1186236_789465) already mention that's not true. – Mast Jun 25 '16 at 09:55
  • +1, also works in Fedora (please don't bash me). Makes both me and my little guy pretty relaxed (using hobbs version) – Cem Kalyoncu Jun 25 '16 at 15:38
  • As a fully-grown adult, I found this so satisfying and relaxing to listen to that I immediately set up an alias so I can listen to this sound whenever I want. – Kevin Jun 27 '16 at 08:30
  • 3
    +1. Here's my tweaked version: `play -n synth brownnoise synth pinknoise mix synth 0 0 0 10 10 40 trapezium amod 0.1 30` The longer period makes it harder to notice the regularity. The numbers mean: 0.1 = wave crash frequency (0.1 Hz = one wave every 10 seconds); 30% = noise level in between waves; 1st 10% = duration (over the 10 seconds) of the rising part of the wave; 2nd 10% = when it starts falling (they are both 10% so that the wave crashes as soon as it's done rising in volume); 40% duration of the entire wave: this means 100% - 40% = 60% of the time is spent waiting between waves. – Tobia Nov 04 '16 at 15:12
  • Here's just a noise - no waves - `play -n synth brownnoise synth pinknoise mix synth sine amod 10 100` – valk Jul 26 '17 at 07:14
  • `play` defaults of 48kHz and 32-bit samples drain your equipment batteries faster than playing 44.1kHz 16-bit CD-audio quality music. Apply `-r44.1k -b8` command line options - you are unlikely to notice any difference between 48kHz 32-bit and 44.1kHz 8-bit noise, but you'll notice your batteries lasting longer. Add `-c2` for stereo noise, it is more immersive. – Maxim Egorushkin May 06 '22 at 23:51
31

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

Colin Ian King
  • 18,370
  • 3
  • 59
  • 70
  • I think `speaker-test` does this as well, but I think pink noise is less than optimal, it's noise sure, but having no variation might not be desireable? –  Jun 20 '16 at 21:13
  • 4
    @bc2946088 12 hours of pure white noise can be accomplished with `play -n synth 12:00:00 whitenoise` – Nick Weinberg Jun 20 '16 at 21:16
  • 6
    You say I can adjust them but what do the `.1` and `60` arguments actually mean? – Oli Jun 21 '16 at 09:45
  • The .1 is kind of irrelevant here; the 60 is the DC offset. The lower it is the more range (in amplitute) you have in the waveform, setting it nearer to 100 will cause it have less range as it's nearly maxed out to 100% full range. – Colin Ian King Oct 20 '17 at 08:00
  • Couldn't help but notice that this `play` command burns my Bluetooth headset battery much faster than playing anything from YouTube. Turns out `play` defaults to 48kHz 32-bit quality, which is an overkill for noise - more than 2.17x data bandwidth compared to 44.1kHz 16-bit CD-audio quality. To reduce battery drain (even lower than that of your music player) use `-c2 -r44.1k -b8` command line options - you are unlikely to notice any difference between 48kHz 32-bit and 44.1kHz 8-bit noises. – Maxim Egorushkin May 06 '22 at 23:44
24

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,596
  • 2
  • 39
  • 113
  • That certainly sounds a lot like the white noise `sox` produces. – Oli Jun 20 '16 at 23:40
  • pacat is eiter not installed in my system by default - so no reason to prefer this ;-) – linolino Jun 22 '16 at 08:01
  • 2
    @linolino aren't you on Ubuntu? If you are, it has to be installed (unless you manually removed it). It is provided by `pulseaudio-utils`, that is even part of the live system (see the [manifest](http://releases.ubuntu.com/16.04/ubuntu-16.04-desktop-amd64.manifest)). If you don't have it, then probably your installation in corrupted. I suggest that you open a new question explaining the problem and asking for help on how to restore your installation. – dadexix86 Jun 22 '16 at 08:09
  • 1
    Unless they're using a server version. – Arronical Jun 22 '16 at 11:15
  • 1
    In any case, you can still use `aplay` instead of `pacat`. `alsa-utils` seem to be installed by default. – Ruslan Jun 23 '16 at 06:52
  • 1
    @dadexix86 actually I have got an lubuntu. Anyway somehow not working in my case after apt-get install. But ByteDefenders solution is working fine ;-) – linolino Jun 27 '16 at 16:10
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
  • 193,181
  • 53
  • 473
  • 722
Mitch
  • 106,657
  • 24
  • 210
  • 268
  • +1 I use Anoise all the time. But it has a few major bugs with 16.04. –  Jun 22 '16 at 15:03
10

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
  • 101
  • 2
8

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,177
  • 18
  • 20
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
  • 90,425
  • 20
  • 200
  • 267
Jules
  • 301
  • 1
  • 2
  • 10
6

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
  • 37,085
  • 25
  • 149
  • 228
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
  • 193,181
  • 53
  • 473
  • 722
Nick Weinberg
  • 4,555
  • 4
  • 24
  • 30
  • That outputs at an 8kHz sample rate, so there's no noise energy above 4kHz. :/ Proper pink noise should have some. Interesting suggestion to use a vibrato / tremolo filter on the noise, though. – Peter Cordes Jun 21 '16 at 07:38
  • 1
    Better solution? Remove `len='7:00:00'`, `if [ "$1" != '' ];then` and `fi`, adding support for infinite noise. – EKons Jun 21 '16 at 08:33
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
  • 798
  • 6
  • 13
2

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,692
  • 23
  • 39
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
  • 51
  • 9
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
  • 333
  • 1
  • 4