Skip to content

Alsa driver limited to 16-bit / 48kHz audio files #494

Open

Description

@GeorgeIoak

While trying to play 24-bit/96kHz or 24-bit 192kHz files with aplay the files are downsampled to 16-bit

pi@raspberrypi ~ $ aplay -v audio/JimmyAndTheCrows96kHz.wav
Playing WAVE 'audio/JimmyAndTheCrows96kHz.wav' : Signed 24 bit Little Endian in 3bytes, Rate 96000 Hz, Stereo
Plug PCM: Rate conversion PCM (48000, sformat=S16_LE)
Converter: linear-interpolation
Protocol version: 10002
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S24_3LE
  subformat    : STD
  channels     : 2
  rate         : 96000
  exact rate   : 96000 (96000/1)
  msbits       : 24
  buffer_size  : 32768
  period_size  : 8192
  period_time  : 85333
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 8192
  period_event : 0
  start_threshold  : 32768
  stop_threshold   : 32768
  silence_threshold: 0
  silence_size : 0
  boundary     : 1073741824
Slave: Hardware PCM card 0 'bcm2835 ALSA' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 16384
  period_size  : 4096
  period_time  : 85333
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 4096
  period_event : 0
  start_threshold  : 16384
  stop_threshold   : 16384
  silence_threshold: 0
  silence_size : 0
  boundary     : 1073741824
  appl_ptr     : 0
  hw_ptr       : 0

pi@raspberrypi ~ $ mplayer -ao alsa audio/test32bit_44.1kHz.wav
MPlayer svn r34540 (Debian), built with gcc-4.6 (C) 2000-2012 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing audio/test32bit_44.1kHz.wav.
libavformat version 53.21.1 (external)
Mismatching header version 53.19.0
Audio only file format detected.
Load subtitles in audio/
==========================================================================
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 44100 Hz, 2 ch, s32le, 2822.4 kbit/100.00% (ratio: 352800->352800)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
==========================================================================
AO: [alsa] 44100Hz 2ch s32le (4 bytes per sample)
Video: no video
Starting playback...
A:  23.5 (23.5) of 66.0 (01:06.0)  1.8%


MPlayer interrupted by signal 2 in module: play_audio
A:  23.6 (23.5) of 66.0 (01:06.0)  1.8%

Exiting... (Quit)
pi@raspberrypi ~ $ mplayer -ao alsa audio/JimmyAndTheCrows96kHz.wav
MPlayer svn r34540 (Debian), built with gcc-4.6 (C) 2000-2012 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing audio/JimmyAndTheCrows96kHz.wav.
libavformat version 53.21.1 (external)
Mismatching header version 53.19.0
libavformat file format detected.
[wav @ 0xb63ecc78]max_analyze_duration reached
[lavf] stream 0: audio (pcm_s24le), -aid 0
Clip info:
 comment: Jimmy And The Crows
 encoded_by: Keith Greeninger, Chris Kee & Br
 date: 2013-07-25
 creation_time: 14:58:00
 time_reference: 0
 coding_history: A=PCM,F=96000,W=24,M=stereo,T=KORG AudioGate ver.2.3.2 (Windows 7),

 artist: Keith Greeninger, Chris Kee & Brain
 title: Jimmy And The Crows
Load subtitles in audio/
==========================================================================
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 96000 Hz, 2 ch, s24le, 4608.0 kbit/100.00% (ratio: 576000->576000)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
==========================================================================
AO: [alsa] 48000Hz 2ch s24le (3 bytes per sample)
Video: no video
Starting playback...
A:  36.9 (36.9) of 475.2 (07:55.2)  9.2%


MPlayer interrupted by signal 2 in module: decode_audio
A:  37.0 (36.9) of 475.2 (07:55.2)  9.2%

Exiting... (Quit)

But playing with omxplayer they "appear" to play back correctly:

pi@raspberrypi ~ $ omxplayer -p audio/JimmyAndTheCrows96kHz.wav
Audio codec pcm_s24le channels 2 samplerate 96000 bitspersample 24
Subtitle count: 0, state: off, index: 1, delay: 0
have a nice day ;)

Activity

  1. popcornmix commented on Jan 14, 2014

    @popcornmix
    Collaborator

    Alsa limits sampling rate to 48kHz, but can easily be increased.
    It also only supports 8 and 16-bit samples. This can be increased although may be a little more involved.

    omxplayer will honour the sampling rate. I believe the code path may involve the samples being converted to 16-bit.

    The OMX API does allow 32-bit samples to be submitted (although hdmi is limited to 24-bit), so hello_audio could be modified to output higher depth samples. Whether you could hear the difference is debatable.

  2. GeorgeIoak commented on Jan 14, 2014

    @GeorgeIoak
    Author

    24-bit audio files are becoming more popular now. I just got back from CES and there was a whole room dedicated to companies that provide high resolution audio files for downloads. Sony had a whole section in their booth for high res audio and even Creative Labs had a section for high res audio.

    The market may be small but it is growing.

  3. popcornmix commented on Jan 14, 2014

    @popcornmix
    Collaborator

    Agreed. If the hardware can support it, and some people want it, then I'd like to make it available.
    But very subtle improvements are obviously lower priority than major bugs reported.
    But, it's on my list!

  4. GeorgeIoak commented on Jan 14, 2014

    @GeorgeIoak
    Author

    Don't start a war with comments like "subtle improvements", trust me, there are quite a few people out there who are very passionate about this stuff. Do you know of anyone who is knowledgeable about this enough to help?

  5. P33M commented on Jan 14, 2014

    @P33M
    Contributor

    Yes. Popcornmix.

  6. GeorgeIoak commented on Jan 14, 2014

    @GeorgeIoak
    Author

    Sorry, I meant besides popcornmix since I'm sure he's busy and this isn't at the top of his to do list.

  7. popcornmix commented on Jan 14, 2014

    @popcornmix
    Collaborator

    Increasing the max samplerate of alsa driver is trivial. Just edit the 48000 and rebuild kernel.
    Supporting > 16-bit samples is trivial on the kernel side, but I'd guess there will be GPU side issues that need debugging (you can specify 32-bit samples and it does things with that, but it's never been tested, so is unlikely to work).

    hello_audio already supports up to 192kHz. Making it support 32-bit samples should just work. Anyone can try that, and produce a "higher quality" player.

  8. GeorgeIoak commented on Jan 14, 2014

    @GeorgeIoak
    Author

    Yes, we've already checked the sample rate and as you say, it's trivial. 32-bit doesn't help too much in the real world since almost nothing is available in 32-bit. The trick is getting 24-bit packaged in the 32-bit and processed properly.

  9. popcornmix commented on Jan 14, 2014

    @popcornmix
    Collaborator

    Most APIs don't deal with actual packed 24-bit quantities as they are expensive to access.
    Normally APIs (like openmax) will just deal with 32-bit quanties and the least significant 8 bits will not be used.

    I'll need to check if ALSA treats SNDRV_PCM_FMTBIT_S24 as packed or not.

  10. GeorgeIoak commented on Jan 14, 2014

    @GeorgeIoak
    Author

    I think it's actually SNDRV_PCM_FMTBIT_S24_3LE that's needed if I'm not mistaken

  11. amtssp commented on Jun 10, 2014

    @amtssp

    Hi.
    Previously (in kernel 3.14.1 and before (3.13.y) I was able to output 192khz (32_LE) via HDMI (after having changed the file and rebuild the module (like this) :
    .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
    .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_192000,
    .rate_min = 8000,
    .rate_max = 192000,
    .channels_min = 1,
    .channels_max = 2

    However, in later kernels it now outputs only 48 khz even though I have applied the same changes and build the modules like I always have been doing. At the moment I'm using 3.14.4.

    I use it for making the small piCorePlayer which is used as a Squeezebox replacement player. It is not pure raspian as I need to rebuild the kernel to produce a tinycore linux. However, there has been no problems before, only at the latest kernels.

    I noticed that the behaviour of how HDMI is selected has been changed - could that have an influence on the issue I'm seeing?

    Steen

  12. popcornmix commented on Jun 10, 2014

    @popcornmix
    Collaborator

    @amtssp
    The firmware does uses the maximum supported sample rate from the EDID as a limit.
    What does "tvservice -a" report?
    Try adding hdmi_force_edid_audio=1 which assumes all audio formats/rates are supported.

  13. amtssp commented on Jun 10, 2014

    @amtssp

    Thanks for your reply.

    I already use the following commands in order to try to force audio via
    HDMI.
    Most users are using this player without a screen attached as it is only an
    audio player.

    sudo echo hdmi_force_mode=1
    sudo echo hdmi_drive=2
    sudo echo hdmi_force_hotplug=1

    sudo echo hdmi_force_edid_audio=1

    sudo echo hdmi_ignore_edid=0xa5000080

    I will try to see if I can figure out exactly when the behaviour was
    changed.

    Sorry the tvservice command was not found - as I stated I'm using microcore
    linux

    tc@piCorePlayer:~$ tvservice -a
    -sh: tvservice: not found

    If you have time please try it:
    https://sites.google.com/site/picoreplayer/home

    Steen

    On Tue, Jun 10, 2014 at 1:06 PM, popcornmix notifications@github.com
    wrote:

    @amtssp https://github.com/amtssp
    The firmware does uses the maximum supported sample rate from the EDID as
    a limit.
    What does "tvservice -a" report?
    Try adding hdmi_force_edid_audio=1 which assumes all audio formats/rates
    are supported.

    Can you identify when this happened?

    —
    Reply to this email directly or view it on GitHub
    #494 (comment).

  14. popcornmix commented on Jun 10, 2014

    @popcornmix
    Collaborator

    I'd suggest removing hdmi_ignore_edid=0xa5000080.
    We now allow HDMI modes to be forced even if not listed in the EDID.

    There was a firmware commit on "March 8th 2004" labelled:
    "audioplus: limit sample rates chosen to ones supported by hardware"

    so might be worth trying a firmware from just before and just after that point.

    Is there a simple way of making PiCorePlayer play an audio file without a squeezebox client?
    I'm not sure our work's network will support it.
    (If I can play a file through ssh or http then that would be easier)

  15. JulienCa commented on Mar 26, 2015

    @JulienCa

    Hello
    Did anyone try to resolve this 24 bits issue and 48000 Hz limit in raspberry ?
    I have some files from qobuz.com which are in 24 bits / 96 kHz and I cannot succeed playing them with mpd : it is always resampled to 16 bits / 48 or 44.1 khz depending on the existing limit in mpd.conf (format "44100:16:2") is activated or not. But is never played in the original format whereas omxplayer does it well.
    I am ok to make a test if someone can compile the sources. Or if someone could give me information about the compiling process because I never did it on a raspberry. My first step would be to compile the unmodified sources and see if I can reproduce the reference image. Then I could try some code modifications as suggested above.

  16. 16 remaining items

  17. w3ua commented on Apr 28, 2019

    @w3ua

    Any progress?

  18. jcucurull commented on Sep 24, 2021

    @jcucurull

    Any news on that? Any action is taken?

  19. Hoeze commented on Aug 13, 2022

    @Hoeze
    Contributor

    @popcornmix Are there any updates on this issue?

  20. popcornmix commented on Aug 15, 2022

    @popcornmix
    Collaborator

    This is supported under kms from the kernel.

    pi@pi4:~ $ aplay --dump-hw-params /usr/share/sounds/alsa/Noise.wav
    Playing WAVE '/usr/share/sounds/alsa/Noise.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
    HW Params of device "default":
    --------------------
    ACCESS:  RW_INTERLEAVED
    FORMAT:  U8 S16_LE S16_BE S24_LE S24_BE S32_LE S32_BE FLOAT_LE FLOAT_BE MU_LAW A_LAW S24_3LE S24_3BE
    SUBFORMAT:  STD
    SAMPLE_BITS: [8 32]
    FRAME_BITS: [8 1024]
    CHANNELS: [1 32]
    RATE: [1 384000]
    PERIOD_TIME: (2 4294967295)
    PERIOD_SIZE: [1 1398102)
    PERIOD_BYTES: [128 1398102)
    PERIODS: [3 1024]
    BUFFER_TIME: (7 4294967295]
    BUFFER_SIZE: [3 4194304]
    BUFFER_BYTES: [384 4194304]
    TICK_TIME: ALL
    --------------------
    

    Apps like kodi are able to output 8 channel 192kHz audio over hdmi.

  21. Hoeze commented on Aug 15, 2022

    @Hoeze
    Contributor

    @popcornmix thanks for your answer.
    I just tried your command on my (freshly installed) Pi Zero:

    aplay -Dhw:CARD=vc4hdmi,DEV=0 --dump-hw-params -v /usr/share/sounds/alsa/Noise.wav
    Playing WAVE '/usr/share/sounds/alsa/Noise.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
    HW Params of device "hw:CARD=vc4hdmi,DEV=0":
    --------------------
    ACCESS:  MMAP_INTERLEAVED RW_INTERLEAVED
    FORMAT:  IEC958_SUBFRAME_LE
    SUBFORMAT:  STD
    SAMPLE_BITS: 32
    FRAME_BITS: [64 256]
    CHANNELS: [2 8]
    RATE: [32000 48000]
    PERIOD_TIME: (166 1024000]
    PERIOD_SIZE: [8 32768]
    PERIOD_BYTES: [256 1048576]
    PERIODS: [2 8192]
    BUFFER_TIME: (333 2048000]
    BUFFER_SIZE: [16 65536]
    BUFFER_BYTES: [256 524288]
    TICK_TIME: ALL
    --------------------
    aplay: set_params:1343: Sample format non available
    Available formats:
    - IEC958_SUBFRAME_LE

    Is this a limitation to my Pi Zero or can I do something about this?
    For the record, I have also tried setting hdmi_force_edid_audio=1, without any changes to above output.

    System details:

    Details
    pi@raspberrypi:~ $ uname -a
    Linux raspberrypi 5.15.56+ #1575 Fri Jul 22 20:26:40 BST 2022 armv6l GNU/Linux
    pi@raspberrypi:~ $ cat /etc/os-release 
    PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
    NAME="Raspbian GNU/Linux"
    VERSION_ID="11"
    VERSION="11 (bullseye)"
    VERSION_CODENAME=bullseye
    ID=raspbian
    ID_LIKE=debian
    HOME_URL="http://www.raspbian.org/"
    SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
    BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
    pi@raspberrypi:~ $ cat /boot/config.txt
    # For more options and information see
    # http://rpf.io/configtxt
    # Some settings may impact device functionality. See link above for details
    
    # uncomment if you get no picture on HDMI for a default "safe" mode
    #hdmi_safe=1
    
    # uncomment the following to adjust overscan. Use positive numbers if console
    # goes off screen, and negative if there is too much border
    #overscan_left=16
    #overscan_right=16
    #overscan_top=16
    #overscan_bottom=16
    
    # uncomment to force a console size. By default it will be display's size minus
    # overscan.
    #framebuffer_width=1280
    #framebuffer_height=720
    
    # uncomment if hdmi display is not detected and composite is being output
    #hdmi_force_hotplug=1
    
    # uncomment to force a specific HDMI mode (this will force VGA)
    #hdmi_group=1
    #hdmi_mode=1
    
    # uncomment to force a HDMI mode rather than DVI. This can make audio work in
    # DMT (computer monitor) modes
    hdmi_drive=2
    
    hdmi_force_edid_audio=1
    
    # uncomment to increase signal to HDMI, if you have interference, blanking, or
    # no display
    #config_hdmi_boost=4
    
    # uncomment for composite PAL
    #sdtv_mode=2
    
    #uncomment to overclock the arm. 700 MHz is the default.
    #arm_freq=800
    
    # Uncomment some or all of these to enable the optional hardware interfaces
    #dtparam=i2c_arm=on
    #dtparam=i2s=on
    #dtparam=spi=on
    
    # Uncomment this to enable infrared communication.
    #dtoverlay=gpio-ir,gpio_pin=17
    #dtoverlay=gpio-ir-tx,gpio_pin=18
    
    # Additional overlays and parameters are documented /boot/overlays/README
    
    # Enable audio (loads snd_bcm2835)
    dtparam=audio=on
    
    # Automatically load overlays for detected cameras
    camera_auto_detect=1
    
    # Automatically load overlays for detected DSI displays
    display_auto_detect=1
    
    # Enable DRM VC4 V3D driver
    dtoverlay=vc4-kms-v3d
    max_framebuffers=2
    
    # Disable compensation for displays with overscan
    disable_overscan=1
    
    [cm4]
    # Enable host mode on the 2711 built-in XHCI USB controller.
    # This line should be removed if the legacy DWC2 controller is required
    # (e.g. for USB device mode) or if USB support is not required.
    otg_mode=1
    
    [pi4]
    # Run as fast as firmware / board allows
    arm_boost=1
    
    [all]
    dtoverlay=dwc2
    enable_uart=1
  22. Hoeze commented on Aug 15, 2022

    @Hoeze
    Contributor

    In the end, what I'd like to achieve is to directly loop USB OTG Audio to HDMI:
    alsaloop -c8 -C default:CARD=UAC2Gadget -P default:CARD=vc4hdmi --rate=192000 -f S32_LE
    However, I have no clue why I fail with this...

    My audio setup can be found (and easily reproduced) here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions