Skip to main content

Topic: Can SoX handle float file with volume over 0dBFS? (Read 4344 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • bennetng
  • [*][*][*][*][*]
Can SoX handle float file with volume over 0dBFS?
I have such files and foobar shows 7.079733 in replaygain scan (track peak) but when I use SoX's stats command I got the following

Code: [Select]
Input File     : 'D:\bennet\@\sox\float.wav'
Channels       : 2
Sample Rate    : 44100
Precision      : 24-bit
Duration       : 00:00:26.43 = 1165375 samples = 1981.93 CDDA sectors
File Size      : 9.32M
Bit Rate       : 2.82M
Sample Encoding: 32-bit Floating Point PCM

In:100%  00:00:26.43 [00:00:00.00] Out:1.17M [!=====|=====!]        Clip:926k
             Overall     Left      Right
DC offset   0.000284  0.000284  0.000283
Min level  -1.000000 -1.000000 -1.000000
Max level   1.000000  1.000000  1.000000
Pk lev dB       0.00      0.00      0.00
RMS lev dB     -3.61     -3.61     -3.61
RMS Pk dB      -0.27     -0.27     -0.27
RMS Tr dB      -1.#J     -1.#J     -1.#J
Crest factor       -      1.51      1.51
Flat factor    37.26     37.26     37.26
Pk count        463k      463k      463k
Bit-depth      32/32     32/32     32/32
Num samples    1.17M
Length s      26.426
Scale max   1.000000
Window s       0.050

I tried SoX's −G and the gain and norm commands to process the files but clipping distortion persists. In foobar I can use replaygain>preamp to reduce volume without distortion. Is this SoX's limitation? Thanks!

  • [JAZ]
  • [*][*][*][*][*]
Can SoX handle float file with volume over 0dBFS?
Reply #1
I see the file is stored in floating point (as suggested by the name, but confirmed by Sox with "Sample Encoding: 32-bit Floating Point PCM" (and indirectly by the Bitrate, which is double of stereo 16bit 44Khz).
But said that, Sox is not operating in 32bits floating point, but in 24bit integer as indicated by "Precision      : 24-bit".

That's why min and max level are clipped to 1, which is the max value that can be stored in integer (because it represents full scale).

I don't know/use sox, but in case it can use the gain when doing stats, and you say that the file has a peak of 7, you should be applying a gain of 0.14.
I don't really know if it might be a bug, an implementation limitation, or an erroneous use of commandline parameters (maybe you need to specify the output format).

  • bennetng
  • [*][*][*][*][*]
Can SoX handle float file with volume over 0dBFS?
Reply #2
I guess SoX really unable to deal with float files above 0dBFS. Just tried TAudioConverter > Filters > SoX > Guard against clipping, but files still clipped even when writing to 32-bit float format.

  • [JAZ]
  • [*][*][*][*][*]
Can SoX handle float file with volume over 0dBFS?
Reply #3
Out of curiosity, i've downloaded 14.4.1 and played with it a bit.

The sad thing is that you are correct.

The instruction
Code: [Select]
>sox -S testfloat.wav -t wav -e floating-point tmp.wav
clips the output just like you say, even when the input file is in floating point, and i am asking the output to be floating point (which is is, but clipped).
Adding -G didn't change anything (i guess that's for when it applies multiple effects).

Finally, i tried the following:
Code: [Select]
>sox -S testfloat.wav -t sox -e floating-point tmp.wav
And that generates a 32bit *integer* file.

So it's like sox works internally in 32bit integer, although that's sort of incompatible with having a "clip guard".

Not even a gain operation on the input file is free of that:
Code: [Select]
>sox -v 0.1 -S testfloat.wav -t wav -e floating-point tmp.wav
(i.e. reduce the volume at 10% on the source)
Reduces the volume, but after clipping the input.
(again, same result with or without -G)

I tried explicitely a float format, but still the same result:
Code: [Select]
>sox -S -t f32 -e floating-point -b 32 --endian little -c 2 -r 44100 testfloat-raw.wav -t f32 -e floating-point -b 32 --endian little -c 2
-r 44100 tmp.wav
  • Last Edit: 21 July, 2013, 11:17:28 AM by [JAZ]

  • phofman
  • [*][*][*][*]
Can SoX handle float file with volume over 0dBFS?
Reply #4
Internally sox operates in int32. Therefore, all input formats are converted to sox_sample_t first.

The variable clip will contain number of samples outside of the allowed range -1, +1 in the input stream.

Therefore, it is not possible to use sox for IMO incorrect files with float samples larger than 1 without clipping.

  • [JAZ]
  • [*][*][*][*][*]
Can SoX handle float file with volume over 0dBFS?
Reply #5
Ok, after reading a bit more the manual and that, the options that sox offer to prevent clipping are in the context of effects/switches (so, the result). In any case, above full scale is always clipped, and the options either advise about the clipping, or apply a gain when it sees it will clip.

But that means that, if I wanted to decode an MP3 file with sox (and apply whatever effect i wanted), the origin will probably be already clipped if it is not mp3gained. (I hope this example is more real than the "float with above full scale values" situation).

Feels strange... it's a bit misleading to have options to operate in float, but not have the benefits of what float means.