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 ☹
Use the Swiss army knife for sound generation, SoX.
You install it from the official repositories, simply by typing:
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.
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 of10
% 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 beforebrownnoise
. Here's an example for one hour: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 of0.1
Hz will cause 0.1 waves per second and therefore make one wave last for 10 seconds: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 with20
% background noise:Old, boring answer (plain white noise):
Now the easiest command to play white noise infinitely (until you abort it with Ctrl+C) is this:
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:It even shows you some nice stats while "playing":
You can generate pink noise using the play command from the sox utilities:
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
Not sure that this will produce real white noise that covers the whole spectrum, but a simple
seems to do the trick on my system (no need to install anything new or add a repository).
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.
ANoise Code, And for For extra river sound:
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.
FFMpeg has an audio noise source filter. You can play it using
ffplay
: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.This might be handy if you have a custom audio-output setup configured for your favourite player.
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 runningI see that nobody has used
aplay
yet so try the following: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...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:Hat tip http://unreasonable.org/white_noise_generator_with_sox_for_Linux
Disclaimer: I have not tried this myself yet
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 asdd 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.