Generate an extremely long brown/pink/white noise MP3 in Linux


Using https://bitbucket.org/rsvp/gists/src/fc42e2068cf0e2109bf58c94f59bfb1976405755/noise.sh?at=default, simplified. Added fade-in and fade-out. Compile sox and lame with sndfile support to get the w64 format.

#!/bin/bash

noise='brown'
# ^your choice: 'white', 'pink', 'brown', 'tpdf'
# where tpdf stands for Triangular Probability Density Function (cf. dither).
# N.B. - white and pink noise have higher frequencies than Brown.

#does not determine the size of the output when "fade" is used, but must be at least
#as long as the fade cutoff.
len='10000:00'

progress='--show-progress'

# FYI Channels: 2 @ 32-bit, Samplerate: 48000Hz.

#w64 format eliminates the 2GB sox barrier with conventional wav files
mkfifo out.w64
rm -fr noise.mp3

#Makes for a ~7hr, 1GB MP3 with these lame settings (320 kbps CBR)
real_len='414:00'
#This volume was selected to just barely avoid clipping (view the MP3 in Audacity)
volume='-0.4dB'

sox -c 2 --null out.w64 synth $len ${noise}noise vol $volume fade t 3 $real_len &

lame --preset insane out.w64 out.mp3

#for some reason, lame puts a little loud blip at the beginning of the file,
#at position 0.05s or so. So remove it here
ffmpeg -ss 0.1 -i out.mp3 -acodec copy noise.mp3

rm out.w64
rm out.mp3

Leave a Reply

Your email address will not be published. Required fields are marked *