33

I'm using SoX to trim a set of wav files into 16kHz, 16bit, mono channel wav files (which will be subsets of one of the initial wav files). Most of the source wav files are already set to this specification, however, I just found out that some of them have different sample rates. Since it's going to be automated in Java using a ProcessBuilder, I figured I could use the following command:

sox <source_wav> -b 16 <dest_wav> channels 1 rate 16000 trim <startTime> =<endTime>

and it'll only change the sample rate if it isn't 16000 Hz. It does what it's supposed to on files with the same specification, but on files with different sample rates, I get:

sox WARN rate: rate clipped 48 samples; decrease volume?
sox WARN dither: dither clipped 44 samples; decrease volume?

How should I deal with this without degrading the quality of the audio? Note that I don't know anything about signal processing.

cesar
  • 8,944
  • 12
  • 46
  • 59

2 Answers2

43

As suggested by the tool, try reducing the volume slightly, e.g. by preceding with -v 0.99 (or 0.98 etc.). Such small changes in volume are imperceptible.

Example:

sox -v 0.99 <source_wav> -b 16 <dest_wav> channels 1 rate 16000 trim <startTime> =<endTime>

If you still get clipping then the audio is likely severely clipped (i.e. disorted) to begin with (this is common with modern music; see Wikipedia: Loudness war) and so the warnings can be ignored—no additional distortion is being introduced.

As mentioned in the comments, the -G option can be given which will automatically make any adjustment to the volume needed to avoid clipping (at the expense of a little extra CPU time, i.e. it runs slightly slower with -G).

PatriceG
  • 3,851
  • 5
  • 28
  • 43
user871634
  • 461
  • 5
  • 5
  • 6
    I reread the documentation and realized I missed the `-G` option, which fixes the gain automatically. I want to avoid having to set an arbitrary number so decided to use the `-G` option. If you append the use of the guard option to your answer, I'd be glad to give this to you, cause it's pretty informative. – cesar Aug 17 '11 at 03:51
  • 3
    You can also use the '--norm' option to both prevent clipping and, if the audio is too quiet, increase it so that it's the max volume without clipping. – drojf Apr 22 '15 at 01:48
  • I had to go down to -v 0.814 on Alesso - When I'm Gone (VIP Mix) lol.. the resulting file does sound wayyy better though. -G and --norm did not work, I think it's a bug when used with rate, but I don't really know – neaumusic Jul 03 '22 at 05:32
1

I had the issue. Changing the encoding of the wav file fixed it:

sox input.wav -e signed-integer output.wav
Markus Lenger
  • 521
  • 5
  • 7