Values from conversion to .dat format using sox does not seem to be normalized
Question
Values from my conversion to .dat format using sox does not seem to be normalized - hope someone can see what I am doing wrong.
I am trying to do something similar to what is described in this great SO post about sox and gnuplot (I am sending the values to processing in Java, so a bit different context). The problem is that in my .dat file I get "only small values", while the man pages says they will be normalized between -1 and 1.
After installing sox and mp3-handling packages, I do the following to test:
sox elevator.mp3 -c 1 -r 11000 elevator_mediumres.dat
cat elevator_mediumres.dat |cut -c21-33 > elevator_mediumres_values_only.dat
sort -n elevator_mediumres_values_only.dat > elevator_mediumres_values_only_sorted.dat
# echo min $(head -1 elevator_mediumres_values_only_sorted.dat) max $(tail -1 elevator_mediumres_values_only_sorted.dat)
This gives the output "min -0.48370361 max 9.1552734e-05". If I do the first command to wav instead of dat, the wav file sounds OK (as OK as 11kHz mono of Aerosmith's "Love in an elevator" ever does). I could of course normalize manually the data afterwards, but I am hoping there is a a better and more straightforward way.
Thanks,
-S-
Solution
You seem to have a major dc-shift in your file. Depending on what you need to do with the data, you probably need to remove that before normalizing. To do this with sox
, first determine dc-shift. Here's one way with sox
, awk
and bash
:
dc_shift=$(sox infile.wav -n stats 2>&1 | awk '/DC offset/ { print $3 }')
Now apply dc-shift and normalization to the input file:
sox infile.wav normalized.wav dcshift $(( -dc_shift )) gain -n
sox
commandline is built up like this:
sox IN OUT EFFECTS
Each effect is applied sequentially.