Re: A question about alsa(1) and sox(1) internals
On Fri, Jul 22, 2022 at 8:51 PM John Conover <conover@panix.com> wrote:
> The command:
>
> sox ... sine create 1000 vol -60 dB
>
> generates a 1 kHz. sine wave at 1 / 1000 full scale.
>
> Does the low level sine wave still consist of +/- 2^15 steps?
>
> (i.e., does the volume reduction occur during sine wave generation, or
> post generation?)
Normally sox does everything with 32-bit integers internally, 2^15
steps wouldn't show up anywhere unless you force the output to 16
bits. I'm not exactly sure how it keeps track of the volume when
processing with "vol", but I got curious and ran some tests.
Generating random values with sox built-in white noise generator and
saving the output to 64-bit doubles I got 30.4 "bits" for -10 dB, 29
bits for -20 dB etc, down to 18 bits for -90 dB.
dB Unique Bits
-10 1440999152 30.4
-20 542466154 29.0
-30 190121342 27.5
-40 65008874 26.0
-50 21855432 24.4
-60 7256755 22.8
-70 2388275 21.2
-80 780808 19.6
-90 253960 18.0
-90,+70 542455597 29.0
Interestingly enough, chaining volume commands will "remember" the
command, so doing this:
vol -90 dB vol +70 dB
gives the same resolution as doing a single vol -20 dB - it doesn't
quantize at the -90 dB level.
In summary: sox tries very hard not to discard information on the way
to the output.
Reply to: