Re: [Alsa-user] [asoundrc] "lossless" format conversion without any rate conversion?

2017-11-17 Thread Vincent Yu
Thank you so much for the informative and detailed response!

Clemens Ladisch wrote:
> This plugin will not do resampling.

It's a relief to hear that plug, in this situation, will not cause resampling.

>> Specifically, does sample rate conversion still occur anywhere in the
>> signal chain even though I provided the "unchanged" string for rate?
>
> The hardware, another plugin layered on top of this, or some application
> might still do resampling.  :)

Ah, yes - like when applications mix or change the volume of streams
before talking to ALSA. I'll be sure to try to have the applications
send a bit-perfect stream to the aforementioned newly defined pcm.

>> I would like to create a configuration to force digital audio output
>> from my PC (Arch Linux - ALSA only, no Pulseaudio) to remain at or be
>> converted to 24-bit format without any sample rate conversion.
>
> Then try the linear plugin, which changes only the sample format:
>
> pcm.my_new_default {
> type linear
> slave {
> pcm "hw:0,0"
> format S24_3LE
> }
> }
>
> (The "plug" plugin does nothing but dynamically inserting other plugins,
> such as "linear"/"route"/"rate", when required.)

Using the linear plugin directly also works for me. Thanks for
clarifying how stuff is working under the hood. I'm directly using the
linear plugin now to make my asoundrc config more readable and clear
to me in the future.

>> I understand that the word, "lossless," in the title may be a bit of
>> a misnomer, since quantization noise from quantization errors during
>> bit depth conversion will raise the noise floor of the signal by
>> a small (and probably inaudible) amount
>
> Converting between integer sample formats does not change the bits; you
> get quantization errors only with volume changes.

Ah, right - CD audio uses LPCM. So only zero-padding occurs... by left
shifting zeros from the right into the samples (without taking
endianness into account)? To only increase precision without losing
information. Ah, it makes sense.

>> looking at the code and trying to grep directory trees recursively for
>> the string, "unchanged", to see if I can get any leads, I got lost in
>> the behemoth of a code base
>
> The "unchanged" string is parsed in pcm.c; in pcm_plug.c, search for
> "== -2".

And so we get:

links |= SND_PCM_HW_PARBIT_RATE;

I was just using a rather vanilla configuration of vim to browse the
code base. Perhaps I should look into plugins and such to make looking
up references/definitions easier. Thanks, yet again, for the
clarification and taking the time to respond to my long post!

Thanks,
Vincent

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


Re: [Alsa-user] [asoundrc] "lossless" format conversion without any rate conversion?

2017-11-16 Thread Clemens Ladisch via Alsa-user
Vincent Yu wrote:
> Will any sample rate conversions occur with this .asoundrc config?
>
> pcm_slave.force_24_bit_no_rate_convert {
> pcm "hw:0,0"
> format S24_3LE # Or other 24-bit format
> rate "unchanged" # Necessary?
> }
>
> pcm.my_new_default {
> type plug
> slave force_24_bit_no_rate_convert
> }

http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html#pcm_plugins_plug

This plugin will not do resampling.

> Specifically, does sample rate conversion still occur anywhere in the
> signal chain even though I provided the "unchanged" string for rate?

The hardware, another plugin layered on top of this, or some application
might still do resampling.  :)

> I would like to create a configuration to force digital audio output
> from my PC (Arch Linux - ALSA only, no Pulseaudio) to remain at or be
> converted to 24-bit format without any sample rate conversion.

Then try the linear plugin, which changes only the sample format:

pcm.my_new_default {
type linear
slave {
pcm "hw:0,0"
format S24_3LE
}
}

(The "plug" plugin does nothing but dynamically inserting other plugins,
such as "linear"/"route"/"rate", when required.)

> I understand that the word, "lossless," in the title may be a bit of
> a misnomer, since quantization noise from quantization errors during
> bit depth conversion will raise the noise floor of the signal by
> a small (and probably inaudible) amount

Converting between integer sample formats does not change the bits; you
get quantization errors only with volume changes.

> looking at the code and trying to grep directory trees recursively for
> the string, "unchanged", to see if I can get any leads, I got lost in
> the behemoth of a code base

The "unchanged" string is parsed in pcm.c; in pcm_plug.c, search for
"== -2".


Regards,
Clemens

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


[Alsa-user] [asoundrc] "lossless" format conversion without any rate conversion?

2017-11-16 Thread Vincent Yu
Hello all,

I've been scratching my head over this for a few hours, looking
through forums, docs, and finally the alsa-lib git repository's C code
to try to find the answer to my question, but, alas, I feel that I may
need to ask for your help.

Will any sample rate conversions occur with this .asoundrc config?

pcm_slave.force_24_bit_no_rate_convert {
pcm "hw:0,0"
format S24_3LE # Or other 24-bit format
rate "unchanged" # Necessary?
}

pcm.my_new_default {
type plug
slave force_24_bit_no_rate_convert
}

(apologies if formatting got garbled)

Specifically, does sample rate conversion still occur anywhere in the
signal chain even though I provided the "unchanged" string for rate?

I would like to create a configuration to force digital audio output
from my PC (Arch Linux - ALSA only, no Pulseaudio) to remain at or be
converted to 24-bit format without any sample rate conversion. I
understand that the word, "lossless," in the title may be a bit of a
misnomer, since quantization noise from quantization errors during bit
depth conversion will raise the noise floor of the signal by a small
(and probably inaudible) amount, but my primary concern is avoiding
any sample rate conversions in the entirety of the signal path. And to
be clear, here, I only ever use one sound source on my PC at a time,
so I will never mix any sound sources together. Currently, my setup
involves exclusive hardware access any time I want to use my sound
card (external USB DAC), resulting in no format or rate conversion at
all (i.e. a "bit-perfect" signal). My rationale for desiring format
conversion - and only format conversion - is at the bottom of this
email.

The only thing I can find online is people wanting to either reduce
their bit depth or change their sampling rate; I haven't been able to
find a post/thread describing my situation. And the most I could
gather from the docs was that ALSA handles conversion "automagically",
but I couldn't get more details past that. Finally, looking at the
code and trying to grep directory trees recursively for the string,
"unchanged", to see if I can get any leads, I got lost in the behemoth
of a code base (which is not a bad thing! I'm just trying to convey a
sense of being overwhelmed).

Rationale:
Many of the world's most well-known label's mastering engineers aim to
produce a final product with the sample peaks not above 0dB in order
to attempt to avoid clipping. In theory (particularly, according to
the Nyquist theorem), the original bandwidth-limited analogue signal
can be perfectly and losslessly reconstructed from this digital signal
(assuming negligible quantization noise). However, the "true" peaks in
the original analogue signal between samples may actually be above 0dB
(which is why, in these cases, if you change the sample rate, you will
very likely - and in the case of upsampling, are guaranteed to - clip
the signal). Nevertheless, with a well-designed DAC that has
sufficient headroom above 0dB to account for these >0dB intersample
peaks, the original signal can still be perfectly reconstructed. The
only thing is, it seems that the only DACs that have the headroom for
this are extremely expensive $1600+ dedicated DACs. Most DACs would
fail to be able to upsample above 0dB or be able to produce an
analogue signal above 0dB, resulting in clipping of the signal. For a
16-bit, 44.1kHz signal, the worst-case frequency is 11kHz, and,
quoting from a paper on this, "... a low-level burst of noise
splatters across the audio spectrum with the bulk of the energy
concentrated in the higher frequencies. These short transient bursts
occur at every inter-sample over, and they can become audible if the
recording has enough of these overs. These bursts tend to create a
false percussive brightness in the high end." The reason any of this
happened in the first place is probably because of a disconnect
between DAC designers and mastering engineers, as well as the
"loudness wars", pushing most record labels ever closer to 0dB.

Since I don't currently have the budget for one of these $1600+ DACs,
I would like to mitigate the issue through software. The idea goes
like this: Take any signal on my PC (e.g. 16-bit, 44.1 kHz), convert
it to a 24-bit format without sample rate conversion, attenuate the
signal by 3.5-5dB to bring the intersample peaks to or below 0dB
(a.k.a. turn down the volume), and then finally send the signal to the
DAC. It is important to follow these steps in order. The conversion to
24-bit format is to mitigate dynamic range loss when changing the
digital volume.

TL;DR: Want to avoid clipping.

Thanks,
Vincent

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net