Project

General

Profile

Ubuntu 12.04 -- how to get ALSA to output 24-bit?

Added by Jack Elliott almost 11 years ago

Hi, Audacious 3.2.1, Ubuntu 12.04, USB d-a converter.

It's unclear to me whether Audacious is sending 24/96khz data to the USB d-a converter or not. In File > Preferences > Audio I have ALSA selected. "Bit Depth" is set to 24. Under "Preferences" I have tried all of the options that talk to the USB PnP DAC except for the surround-sound ones.

When playing a 16/44 mp3, I see:

jack@jack-Music:/proc/asound/card2/pcm0p/sub0$ cat hw_params
access: MMAP_INTERLEAVED
format: S16_LE
subformat: STD
channels: 2
rate: 48000 (48000/1)
period_size: 1024
buffer_size: 16384

When playing a 24/96 pcm .wav file, I see:

jack@jack-Music:/proc/asound/card2/pcm0p/sub0$ cat hw_params
access: RW_INTERLEAVED
format: S16_LE
subformat: STD
channels: 2
rate: 48000 (48000/1)
period_size: 1024
buffer_size: 8192

These seem to be about the same.

Of course, I may be looking in the wrong place.


Replies (12)

RE: Ubuntu 12.04 -- how to get ALSA to output 24-bit? - Added by John Lindgren almost 11 years ago

You are probably using the dmix mixer/resampler. Use one of the devices that starts with "hw:".

RE: Ubuntu 12.04 -- how to get ALSA to output 24-bit? - Added by Jack Elliott almost 11 years ago

Thank you. hw:2,0 is the one assigned to the USB PnP DAC.

If I select that as PCM Device,

and leave the Mixer Device to "Default Mixer Device"
and Mixer Element to "Master" then press "play" I get:
ALSA error: snd_pcm_hw_params_set_format_failed: invalid argument.

Other Mixer Device settings, such as hw:2, or default((null)) give either the same error, or "ALSA error: snd_mixer_find_selem failed"

RE: Ubuntu 12.04 -- how to get ALSA to output 24-bit? - Added by Jack Elliott almost 11 years ago

Additional information: I can use hw:2,0 if I set the File > Preferences bit depth to 16. But not 24, 32, or floating point -- those give ALSA error: snd_pcm_hw_params_set_format_failed: invalid argument.

RE: Ubuntu 12.04 -- how to get ALSA to output 24-bit? - Added by John Lindgren almost 11 years ago

Well, pick a combination that works and use it. If you're getting errors it means you're trying to do something the hardware (or driver) doesn't support.

RE: Ubuntu 12.04 -- how to get ALSA to output 24-bit? - Added by Jack Elliott almost 11 years ago

"If you're getting errors it means you're trying to do something the hardware (or driver) doesn't support."

I reckon you're right. I connected up another USB audio device (Musical Fidelity V-Link II). It supports 24/96.*

Anyway, with the V-link, I got "ALSA error: snd_pcm_hw_params_set_format_failed: invalid argument" when trying to drive it via hw:1,0 (where it turned up after restart) and with hw:CARD=Vlink, Dev=0; but with sysdefault:CARD=Vlink no error. catting hw_params showed 24 bits, and 48kHz (the file I was playing), so I seem to have a working setup.

Thanks for the help.

  • The first device claims to support 24/96, too, but oh well.

RE: Ubuntu 12.04 -- how to get ALSA to output 24-bit? - Added by Andrea Iob over 10 years ago

Hi,

I've just bought a HRT Music Streamer II+ USB DAC and, like Jack Elliott, I'm having some problems with 24 bit depth when using the hardware device directly (hw:). The DAC supports 16 and 24 bit depths, but only the first is working in audacious (with 24 bit I get the error snd_pcm_hw_params_set_format_failed).

The problem can be related to the fact that audacious tries to open the PCM device with the following settings:

alsa.c:336 [alsa_open_audio]: Opening PCM device hw:1,0 for S24_LE, 2 channels, 44100 Hz.

but the 24bit format supported by the DAC is S24_3LE and not S24_LE. In fact, the file /proc/asound/II/stream0 contains
the following information:

www.hirestech.com 2013 REV 3.0 Music Streamer II+ at usb-0000:00:1d.2-2, full s : USB Audio

Playback:
Status: Stop
Interface 1
Altset 1
Format: S24_3LE
Channels: 2
Endpoint: 1 OUT (ASYNC)
Rates: 96000, 88200, 48000, 44100, 32000
Interface 1
Altset 2
Format: S16_LE
Channels: 2
Endpoint: 1 OUT (ASYNC)
Rates: 96000, 88200, 48000, 44100, 32000

Is this a plausible cause of the problem? Would it be possible to add the S24_3LE among the different bit depths?

Thanks.
Andrea

RE: Ubuntu 12.04 -- how to get ALSA to output 24-bit? - Added by Andrea Iob over 10 years ago

I've tried to patch Audacious to support S24_3LE, but my patch does not work. With the patch I don't get anymore the error snd_pcm_hw_params_set_format_failed, but I hear only noise.

With aplay I'm able to use the format S24_3LE:

aplay -F S24_3LE -D hw:1,0 SOR\ KFR3\ Loop\ SPerc127\ \ 018.wav
Playing WAVE 'SOR KFR3 Loop SPerc127 018.wav' : Signed 24 bit Little Endian in 3bytes, Rate 44100 Hz, Stereo

Any hints on what I'm doing wrong?

Thanks.

RE: Ubuntu 12.04 -- how to get ALSA to output 24-bit? - Added by John Lindgren over 10 years ago

Well, your patch adds a UI option but practically nothing else. You need to at least add conversions in audio.c and update the FMT_SIZEOF macro in audio.h. There may be other code that needs updating as well.

RE: Ubuntu 12.04 -- how to get ALSA to output 24-bit? - Added by Andrea Iob over 10 years ago

I was a little bit too optimistic. I though all the conversions were handled by ALSA.

I don't have the knowledge to modify the details of the conversions. The only thing I know on the 24 bit format is that S24_XE samples are stored in 4bytes with padding on high bits while S24_3XE are stored in 3bytes. But I have no idea what that means for an audio player point of view.

I have updated the patch to add fake conversions in audio.c (fake means that are the same of the S24_XE/U24_XE) and I've updated the FMT_SIZEOF macro in audio.h. Since there is no int24_t data type, is it possible to store the samples in a int32_t? I know that what I've done is just the easy part and the real work is missing, but as I said I'm not able to do more.

If you have some time it would be great if you can help me with this. I can test the code (if it will not damage the hi-fi or the DAC).

Thanks.

RE: Ubuntu 12.04 -- how to get ALSA to output 24-bit? - Added by John Lindgren over 10 years ago

The conversions would be handled by ALSA if you did not insist on using the direct hardware device. You should be able to set up ALSA to accept 32-bit and convert to whatever the hardware supports.

RE: Ubuntu 12.04 -- how to get ALSA to output 24-bit? - Added by Andrea Iob over 10 years ago

Well, I didn't know it was possible to modify the ALSA configuration file to handle the sample rate and bit depth conversions. Now I've modified $HOME/.asoundrc and I've set the Audacious bit depth to 24.

If I've understood correctly how ALSA works, with a configuration file like this:

<<<<<
defaults.namehint.showall on
defaults.pcm.rate_converter "samplerate_best"

pcm_slave.MS_II_slave {
pcm "hw:1,0"
}

pcm.MS_II {
type plug
slave MS_II_slave
}

I can know select the new PCM device called MS_II and ALSA would do a resampling only when the hardware does not support the sample rate of the file being played. Moreover, if there is a resampling, it is now done with a better algorithm, i.e. SRC_SINC_BEST_QUALITY from libsamplerate (requires alsa-plugins to work). Since I've set Audacious to use a 24 bit format, ALSA automatically selects the format S24_3LE and the conversion from S24_LE is done on-the-fly by ALSA (like you said).

Last question: on a theoretical point of view is there some kind of degradation of the signal going form a format with a lower bit depth to a one with a higher bit depth (for example S16_LE -> S24_LE) ? I would say that it isn't. I'm not concerned about sound quality, it's just out of curiosity.

RE: Ubuntu 12.04 -- how to get ALSA to output 24-bit? - Added by John Lindgren over 10 years ago

There is theoretically no degradation going to a higher bit rate.

    (1-12/12)