antiprism / mpd_oled

MPD, Volumio, RuneAudio and Moode OLED status and spectrum display for Raspberry Pi (and similar)
Other
168 stars 46 forks source link

Output to USB DAC becomes constant when spectrum analyser is working in mpd_oled #90

Open silentcossack opened 2 weeks ago

silentcossack commented 2 weeks ago

Hi, i'm so lost, hoping this is not a bug, but maybe it is.

This is hard to describe, but i'll try. I got Moode 9 running on rpi 4. Everything works great. I installed mpd_oled from source and it works too. If i run the mpd_oled with default cava settings (i.e. not specifying the source), then the spectrum is not working, but the audio output to my usb dac is great, unmodified, with rate matching that of source. So if source is 48KHZ, then output is 48Khz is well. If source is 44.1, then so is the output.

So if I run this: /usr/local/bin/mpd_oled -o3 -a 3c

Then spectrum does not work, but audio output quality changes with the source, which is perfect.

However, if I run this: /usr/local/bin/mpd_oled -o3 -a 3c -c alsa,hw:Loopback,1

Then spectrum does work, but the audio output quality is stuck at whatever the first song was. So if the first song was 48kHz, then all subsequent music will be output at that rate, not matching the source. If i stop mpd_oled, guess what, output starts matching the source again. If I start mpd_oled with the -c option, same problem. It is as if whenever mpd_oled (or cava) connects to the loopback, something starts resampling all outputs, including my usb dac output.

I have the loopback option enabled in Moode web interface. I tried running mpd_oled_moode_audio_copy_install - didn't change anything. Below is the output of mpd_oled_moode_audio_copy_report in case it helps.

$ sudo mpd_oled_moode_audio_copy_report
===========================================================
Audio Copy Report for mpd_oled
===========================================================
aplay -l
--------
**** List of PLAYBACK Hardware Devices ****
card 0: Lite [E30 II Lite], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 1: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 2: vc4hdmi1 [vc4-hdmi-1], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
===========================================================
aplay -L
--------
null
    Discard all samples (playback) or generate zero samples (capture)
default
    Default Audio Device
sysdefault
    Default Audio Device
_audioout
plug_alsaequal
btstream
camilladsp
crossfeed
plug_bs2b
plug_eqfa12p
invpolarity
trx_send
eqfa12p
eqfa12p_and_copy
alsaequal
alsaequal_and_copy
hw:CARD=Lite,DEV=0
    E30 II Lite, USB Audio
    Direct hardware device without any conversions
plughw:CARD=Lite,DEV=0
    E30 II Lite, USB Audio
    Hardware device with all software conversions
default:CARD=Lite
    E30 II Lite, USB Audio
    Default Audio Device
sysdefault:CARD=Lite
    E30 II Lite, USB Audio
    Default Audio Device
front:CARD=Lite,DEV=0
    E30 II Lite, USB Audio
    Front output / input
surround21:CARD=Lite,DEV=0
    E30 II Lite, USB Audio
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Lite,DEV=0
    E30 II Lite, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Lite,DEV=0
    E30 II Lite, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Lite,DEV=0
    E30 II Lite, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Lite,DEV=0
    E30 II Lite, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Lite,DEV=0
    E30 II Lite, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Lite,DEV=0
    E30 II Lite, USB Audio
    IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=Lite,DEV=0
    E30 II Lite, USB Audio
    Direct sample mixing device
hw:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    Direct hardware device without any conversions
hw:CARD=Loopback,DEV=1
    Loopback, Loopback PCM
    Direct hardware device without any conversions
plughw:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    Hardware device with all software conversions
plughw:CARD=Loopback,DEV=1
    Loopback, Loopback PCM
    Hardware device with all software conversions
default:CARD=Loopback
    Loopback, Loopback PCM
    Default Audio Device
sysdefault:CARD=Loopback
    Loopback, Loopback PCM
    Default Audio Device
front:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    Front output / input
surround21:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
dmix:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    Direct sample mixing device
dmix:CARD=Loopback,DEV=1
    Loopback, Loopback PCM
    Direct sample mixing device
hw:CARD=vc4hdmi1,DEV=0
    vc4-hdmi-1, MAI PCM i2s-hifi-0
    Direct hardware device without any conversions
plughw:CARD=vc4hdmi1,DEV=0
    vc4-hdmi-1, MAI PCM i2s-hifi-0
    Hardware device with all software conversions
default:CARD=vc4hdmi1
    vc4-hdmi-1, MAI PCM i2s-hifi-0
    Default Audio Device
sysdefault:CARD=vc4hdmi1
    vc4-hdmi-1, MAI PCM i2s-hifi-0
    Default Audio Device
hdmi:CARD=vc4hdmi1,DEV=0
    vc4-hdmi-1, MAI PCM i2s-hifi-0
    HDMI Audio Output
dmix:CARD=vc4hdmi1,DEV=0
    vc4-hdmi-1, MAI PCM i2s-hifi-0
    Direct sample mixing device
===========================================================
mpc outputs
-----------
Output 1 (ALSA Default) is enabled
    allowed_formats=""
    dop="0"
Output 2 (ALSA Bluetooth) is disabled
    allowed_formats=""
    dop="0"
Output 3 (HTTP Server) is disabled
===========================================================
cat /etc/asound.conf
--------------------
# MPD_OLED_START_TAG: DO NOT CHANGE THIS LINE
pcm.!eqfa12p {
    type copy
    slave.pcm "eqfa12p_and_copy"
}

pcm.eqfa12p_and_copy {
    type plug
    slave.pcm {
        type multi
        slaves {
            a { channels 2 pcm "plug_eqfa12p" }       # the original output
            b { channels 2 pcm "plughw:Loopback,0" }  # the loopback driver
        }
        bindings {
            0 { slave a channel 0 }
            1 { slave a channel 1 }
            2 { slave b channel 0 }
            3 { slave b channel 1 }
        }
    }
    ttable [
        [ 1 0 1 0 ]   # left  -> a.left,  b.left
        [ 0 1 0 1 ]   # right -> a.right, b.right
    ]
}

pcm.!alsaequal {
    type copy
    slave.pcm "alsaequal_and_copy"
}

pcm.alsaequal_and_copy {
    type plug
    slave.pcm {
        type multi
        slaves {
            a { channels 2 pcm "plug_alsaequal" }     # the original output
            b { channels 2 pcm "plughw:Loopback,0" }  # the loopback driver
        }
        bindings {
            0 { slave a channel 0 }
            1 { slave a channel 1 }
            2 { slave b channel 0 }
            3 { slave b channel 1 }
        }
    }
    ttable [
        [ 1 0 1 0 ]   # left  -> a.left,  b.left
        [ 0 1 0 1 ]   # right -> a.right, b.right
    ]
}
# MPD_OLED_END_TAG: DO NOT CHANGE THIS LINE

===========================================================
cat /etc/modules
----------------
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

i2c-dev
snd-aloop
===========================================================
cat /etc/modprobe.d/alsa-base.conf
----------------------------------
options snd-aloop index=-2
===========================================================
cat /var/local/www/currentsong.txt
----------------------------------
file=NAS/Storage/Metallica/ 72 Seasons [288984589] [2023]/01 - Metallica - 72 Seasons.flac
artist=Metallica
album=72 Seasons
title=72 Seasons
coverurl=/coverart.php/NAS%2FStorage%2FMetallica%2F%2072%20Seasons%20%5B288984589%5D%20%5B2023%5D%2F01%20-%20Metallica%20-%2072%20Seasons.flac
track=1
date=2023-04-14
composer=
encoded=FLAC 16/44.1 kHz, 2ch
bitrate=1.156 Mbps
outrate=Not playing
volume=70
mute=0
state=pause
===========================================================
ps ax | grep mpd_oled
---------------------
    441 ?        Dsl    0:18 /usr/local/bin/mpd_oled -o3 -a 3c -c alsa,hw:Loopback,1
   2468 ?        S      0:00 sh -c mpd_oled_cava -p /tmp/cava_config_oc7xPU
   2469 ?        Sl     0:24 mpd_oled_cava -p /tmp/cava_config_oc7xPU
  26795 pts/0    S+     0:00 sudo mpd_oled_moode_audio_copy_report
  26796 pts/1    Ss     0:00 sudo mpd_oled_moode_audio_copy_report
  26797 pts/1    S+     0:00 /bin/bash /usr/local/bin/mpd_oled_moode_audio_copy_report
  26812 pts/1    S+     0:00 grep mpd_oled
===========================================================

What could be changing the rate of output when spectrum is running?

antiprism commented 2 weeks ago

Hi silentcossack

My understanding is that when cava starts it will set the sample rate at the loopback device to whatever is playing, then, when the audio sample rate should change through playing some different audio, the player finds that the loopback device has a particular rate and so synchronises to that. I believe that the solution would be for mpd_oled to restart cava every time that play resumes after being stopped, but I am no longer developing mpd_oled and so this won't be fixed.

Adrian.

silentcossack commented 2 weeks ago

Ok thanks, that makes sense. I did not realise that you are no longer developing this, too bad. I'll just run it without spectrum for now and see if I change the code to get rid of it and fill it with something else.

silentcossack commented 2 weeks ago

For anybody who comes across this, I decided to fork this repo and remove the spectrum display. I also enlarged the artist and song text to take up more display space and be visible from further away. You can grab the modified code here: https://github.com/silentcossack/mpd_oled

mpd_oled_mod