Boycott Israel

Support human rights - boycott Israel

gonzo blogging, commentary, opinion, and more from Tom Swiss
about unreasonable.org | contact Tom | recent updates | register | RSS feed | send a story
Active forum topics
Recent comments
"white noise" generator with sox for Linux
By tms at 17 January 2007 - 5:39pm | Categories: |

I am a light sleeper. So a while back I was thinking about getting a "white noise" generator for my bedroom.

Then I remembered that my computer sits right across from my bed. Certainly there must be a software option...

Sox is "the swiss army knife of sound processing programs". It comes standard on most GNU/Linux distributions and is available for other platforms.

It includes sound generation capabilties, for pure tones and for white noise. More agreeable for my purpose, though, is "pink noise", which is also in sox's bag of tricks.

After a bit of experimentation, I found the following shell script produced agreeable results:

pinknoise:


#!/bin/sh
 
len='7:00:00'
 
if [ "$1" != '' ]; then
  len=$1
fi
 
sox -t sl - -t sl - synth $len pinknoise < /dev/zero |\
  sox -t sl - -t ossdsp /dev/dsp band -n 1200 200 vibro 20 .1

The script takes an optional argument providing the length of time to run and produce sound (hh:mm:ss format); it defaults to seven hours, where its output will mask minor noises to allow a decent night's sleep. The first sox invocation generates the noise, while the second applies a filter and a light vibrato effect that I find a little more pleasant than the raw noise.

You may have to change the "-t ossdsp" and/or the "/dev/dsp" depending on your audio setup. man sox to discover other options. Share and enjoy.


September 2009 update

The latest sox renamed the "vibro" effect to "tremolo", breaking my script when I updated. That was annoying. I've also reworked the thing so the pipe is no longer needed. Here's the revised, updated version:


#!/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


Thanks all for your interest.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I like it!

By Drew Haven (not verified) on 5 December 2007 - 7:22pm

This beats the heck out of "cat /dev/urandom > /dev/dsp". The band filter is nice to take out the pops.

Groovy

By blackhole (not verified) on 18 November 2008 - 3:07pm

I will probably keep looking at other options such as Broodle to see what is out there. But this is a really cool one liner. I had no idea that sox could do this! Should somebody be looking for such a thing I'll be sure and point them to this page.

Thanks a lot.

Updates

By gi1242 (not verified) on 6 June 2009 - 5:20pm

With recent versions of sox, things are a little simpler:
play -n synth 60:00 brownnoise
produces brown noise for an hour. (Replace brown with pink/white if you prefer. My baby sleeps best with brown).

brown noise...

By tms on 10 June 2009 - 2:18pm

Have to say I thought this was a "brown note" joke, but the "brown" in "brown noise" means Brownian motion. It's also called red noise. I learned something today, hooray!

Tom Swiss - proprietor, unreasonable.org

thanks -- this works great!

By Anonymous (not verified) on 4 July 2009 - 3:52am

This tip is a godsend to me. Just switching to Ubuntu on my new netbook and this works like a charm. I was missing the app Noise, which I use on the Mac. I wonder if this would work using Terminal on the Mac? Anyway, thanks so much.

vibro effect renamed

By Tom (not verified) on 29 September 2009 - 10:01am

I'm still working out how to do this using a single command, I.E. without the pipe, but the 'vibro' effect is now called tremolo in the latest version of Sox.

Thanks for posting this anyway, I've had much more luck in 5 minutes with this than with Boodle.

vibro -> tremolo

By tms on 30 September 2009 - 12:05am

I just figured out the rename (it was driving me nuts that it broke after I upgraded my box) and came over to update the page, only to find your comment.

The two sox invocations can be replaced with one call to play:

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

So how do I combine it with sine-wave generation?

By John Arrowwood (not verified) on 1 October 2009 - 1:38pm

Suppose I want to do Brainwave Entrainment, so I want to play a 400hz pure tone in the left ear, and a 410hz tone in the right ear, and then I wanted to merge with that the pink or brown noise at 1/4th the volume. Can sox actually generate all that in a single command line?

And can sox do frequency shifts?

That would be awesome if it could! :)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <b> <i> <hr> <blockquote> <img> <h1> <h2> <h3> <h4> <h5> <h6>
  • Lines and paragraphs break automatically.
More information about formatting options