• person rss_feed

    Timothée Jaussoin’s feed

    Blog

    • chevron_right

      Fixing cracking sound with Alsa output when playing music in 5.1 on your RaspberryPi

      Timothée Jaussoin · Sunday, 13 August, 2023 - 09:07 edit · 1 minute · 3 visibility

    Just a small article to explain how to fix the annoying "cracking music" that I had when I was playing 5.1 albums on my RPi.

    At first I though it was a resampling issue (converting from 44100Hz to 48000 or 96000Hz or vice-versa) or a bug in Alsa. but it turn out that you have to configure your HDMI output to a 7.1 configuration (8.1), I found the solution on this forum.

    So here is my \etc\asound.rc file:

    pcm.device{
        type hw
        card 0
        device 0
    }
    
    pcm.!surround51 {
        type route
        slave.pcm "device"
        slave.channels 8
        ttable {
          0.0 1
          1.1 1
          2.4 1.8
          3.5 1.1
          4.3 1.8
          5.0 0.5
          5.1 0.5
          6.6 0
          7.7 0
        }
    }
    

    Here I reroute also my channels differently and I have specific volume level for some of them. My speakers are positioned at different places in my room, so I had to adjust that. Feel free to customize it regarding your own configuration.

    As you can see the speaker 6 and 7 are muted. It's a 7.1 setup but behaving like a 5.1. The LFE channel is send to my two main column speakers that can do low frequencies. If you have a subwoofer you can route the channel 5 directly to it.

    I also added another virtual device to upmix stereo output to all my speakers:

    pcm.20to51 {
      type route
      slave.pcm surround51
      slave.channels 6
      ttable.0.0 1
      ttable.1.1 1
      ttable.0.2 1
      ttable.1.3 1
      ttable.0.4 0.5
      ttable.1.4 0.5
      ttable.0.5 0.5
      ttable.1.5 0.5
    }
    

    And in MPD I added two new output, one for the direct 5.1 configuration, one for the stereo to 5.1 virtual device:

    audio_output {
            type            "alsa"
            name            "Ampli 5.1"
            device          "surround51"
            format          "96000:24:6"
            auto_resample   "no"
    }
    
    audio_output {
            type            "alsa"
            name            "Ampli Stereo to Surround"
            device          "20to51"
            format          "96000:24:2"
            auto_resample   "no"
    }
    

    I set the bitrate and sampling to 24bit and 96000 to prevent some downsampling (I have some high quality audio albums in 96Khz/24bit FLAC format).

    That's all folks !

    #raspberrypi #rpi #music #mpd #alsa #surround #stereo