I generated a 10 second audio file containing white noise, using SoX :

sox.exe -n witteruis0.wav synth 10 whitenoise
sox.exe witteruis0.wav -n stats

The resulting "witteruis0.wav" is more or less normalized, but shows a DC offset, which I tried to get rid of, using :

sox.exe witteruis0.wav witteruis1.wav dcshift [negative of the DC offset in stats]

However, it responds with :

sox.exe WARN dcshift: dcshift clipped XXX samples; decrease volume?

The requested "witteruis1.wav" was not created...

I read that the volume can be changed automatically to avoid clipping using the -G option, but I have no clue where to put this in the command. I put it everywhere, each time resulting in errors. Examples are whoefully lacking in the SoX manual! Can someone help me out?

  • 1
    Is a DC offset at least -60 dB under max peak a real issue in your use case ? Are floats values the best option to represent a theoretically ideal white noise signal ?
    – audionuma
    Mar 22, 2018 at 8:16
  • 1
    How much DC offset is the file showing? I tried searching to see if DC offset is expected in white noise but didn’t find anything that confirms it. Mar 22, 2018 at 15:02
  • white noise is supposed to have a mean of 0 dsprelated.com/freebooks/sasp/White_Noise.html but that is a statistical property. There's no guarantee that a randomly generated sequence of floats uniformly distributed between -1 and +1 will actually have a perfectly 0 mean. The longer the sequence, the closer to 0 it's mean should be.
    – audionuma
    Mar 23, 2018 at 8:04
  • The amount of DC bias obviously changes randomly with each file generation, and so is never 0. The one I generated just now showed -0.001184 which amounts to -39 amplitude in a 16-bit sample. How do I get rid of it by using the -G option which is supposed to avoid clipping automatically ?
    – Petoetje59
    Mar 23, 2018 at 9:44
  • It seems that the -G option does not work as you expect in this case. A definitive answer might be obtained thru the SoX users mailing list sourceforge.net/p/sox/mailman/sox-users
    – audionuma
    Mar 25, 2018 at 8:29

2 Answers 2


Firstly, ensure that you are not generating "peak" white noise. You should be working at -20dBFS ideally, then you have room to move.

Secondly, understand that full spectrum white noise starts at 0Hz and stops at the nyquist frequency (fs/2) which means that there is going to be some DC in the signal.

The best way to do this is to generate some white noise at -20dBFS and then apply a highpass filter at a very low frequency, such as 10Hz. That will ensure there is no DC in the overall output signal.

sox -n foo.wav synth 100 whitenoise gain -n -20 highpass 10

You can test further by lowering the highpass parameter further to the lowest possible level until DC starts to re-appear.


Just leave the offset alone. White noise is uncorrelated: every sample is generated independently from any other sample. The only way to guarantee a DC offset of 0 for a finite number of independent samples is to make each sample 0, something which you obviously don't want. If you subtract the "DC offset" from white noise with a non-zero power, the samples are no longer independent since their value then depends on the sum of all previously independent samples.

"Fix" the mean by adding some value, and all other statistical moments of your sequence go down the drain.

  • This appears to be a mathematical 'what-not-to-do' rather than a simple solution to the OP's problem with sox?
    – Mark
    Oct 6, 2019 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.