moOde with USB input

moOde supports various audio sources. The most common used sources are (network) files and streaming (UPnP/Airplay/Bluetooth). Also alternative renders like Roon and LMS are available. But what if you want to capture external source like SPDIF or analog?

Maybe you just want to select you source digital, or stream it over the air or you just want to apply CamillaDSP to everything you play. Currently this isn’t supported out of the box with moOde. Luckily it can be accomplished with very small effort.

What will we do?

Sorry but this is going to be a long read:

  1. First we will collect some info about the available audio inputs.
  2. Next make a configuration which make dealing with the inputs easier.
  3. The main dish; how to use the inputs in a little bit fancier way with MPD/moOde.
  4. And for the hardcore audience; as dessert followed by an how to use the inputs with CamillaDSP directly.

None of the activities involves programming or changing code of moOde. Just changing setting and creating/update some configuration files.

Because we concentrate on the inputs this time, I assume that you already have setup a working audio output on your Pi with moOde. (At the moment of writing moOde 8.0.2 is used). And checked that CamillaDSP flat config works fine.

The used device

As example device we will use a MOTO AVB device, with the following input mapping:

  • analog 1 input (device channels 0,1)
  • analog 2 input (device channels 2,3)
  • analog 3 input (device channels 4,5)
  • toslink (device channels 6,7)

This mapping will differ per used device, with most MOTU devices you can setup a mapping in the settings of the device:

Used MOTU Routing table

Disclaimer: I’m using this device because this is what I have at hand. It’s a fantastic device for what I normally use it for. But in the context of this blog, inputs, it (or the drivers) has some quirks. The UAC compatibility is not straight forward. And yes I also tried the Drumfix drivers from github. If you’re interested I have a prebuilt debian package for moOde available.

Device details

Before we start configuring the system, we need some details about the device. The same tools can also come in handy when solving problems.

List available usb devices

pi@moode:~ $ lsusb -tv
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
    ID 1d6b:0003 Linux Foundation 3.0 root hub
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
        ID 2109:3431 VIA Labs, Inc. Hub
        |__ Port 1: Dev 3, If 0, Class=Audio, Driver=snd-usb-audio, 480M
            ID 07fd:0005 Mark of the Unicorn
        |__ Port 1: Dev 3, If 1, Class=Audio, Driver=snd-usb-audio, 480M
            ID 07fd:0005 Mark of the Unicorn
        |__ Port 1: Dev 3, If 2, Class=Audio, Driver=snd-usb-audio, 480M
            ID 07fd:0005 Mark of the Unicorn
        |__ Port 1: Dev 3, If 3, Class=Audio, Driver=snd-usb-audio, 480M
            ID 07fd:0005 Mark of the Unicorn
        |__ Port 1: Dev 3, If 4, Class=Audio, Driver=snd-usb-audio, 480M
            ID 07fd:0005 Mark of the Unicorn
        |__ Port 1: Dev 3, If 5, Class=Vendor Specific Class, Driver=, 480M
            ID 07fd:0005 Mark of the Unicorn
        |__ Port 1: Dev 3, If 6, Class=Vendor Specific Class, Driver=, 480M
            ID 07fd:0005 Mark of the Unicorn
        |__ Port 1: Dev 3, If 7, Class=Vendor Specific Class, Driver=, 480M
            ID 07fd:0005 Mark of the Unicorn

Notice the Class=audio with the Driver=snd-usb-audio (or motu when using the drumfix drivers); that is a UAC comptabile interface.

List the available capture devices

Lets see which capture devices are available with Alsa:

pi@moode:~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 2: AVB [UltraLite AVB], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

From this output we learned that the capture device has card number 2.

Get details of the capture device

Now we know the card number we can dive deeper for more details:

pi@moode:~ $ arecord -D hw:2,0,0 --dump-hw-params
Recording WAVE 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono
HW Params of device "hw:2,0,0":
--------------------
ACCESS:  MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT:  S24_3LE
SUBFORMAT:  STD
SAMPLE_BITS: 24
FRAME_BITS: 576
CHANNELS: 24
RATE: [44100 192000]
PERIOD_TIME: [125 165103)
PERIOD_SIZE: [6 7281]
PERIOD_BYTES: [432 524232]
PERIODS: [2 1024]
BUFFER_TIME: (62 330227)
BUFFER_SIZE: [12 14563]
BUFFER_BYTES: [864 1048536]
TICK_TIME: ALL
--------------------

This time we learned:

  • The sample format of the device is S24_3LE.
  • It haves 24 input channels available.
  • Is supports a sample rate from 44.1kHz till 192kHz.

Splitting the inputs

To make it easier to select the correct input, you can split up the input. Nice background article about how to do that is Audio multi-channel routing and mixing using alsalib.

For this we will create a file /etc/alsa/conf.d/motu_avb_inputs.conf, with the content below.
The name of the file can be anything, as long as it is put in the correct location.

pcm_slave.motu {
        pcm "hw:2,0,0"
        rate 44100
        channels 24
}

pcm.ainput1 {
        type dsnoop
        ipc_key 12378
        slave motu
        bindings.0 0
        bindings.1 1
}

pcm.ainput2 {
        type dsnoop
        ipc_key 12378
        slave motu
        bindings.0 2
        bindings.1 3
}

pcm.ainput3 {
        type dsnoop
        ipc_key 12378
        slave motu
        bindings.0 4
        bindings.1 5
}


pcm.toslink {
        type dsnoop
        ipc_key 12378
        slave motu
        bindings.0 6
        bindings.1 7
}

If you copied the new configuration file to the correct location, you can check the availabity of the new named input devices

pi@moode:~ $ arecord -L
...
ainput1
ainput2
ainput3
toslink
...

Next you can optional test if you can record from a specific input:

pi@moode:~ $ sudo arecord -D ainput1 -f S24_3LE -r 44100 -c 2 test.wav

(ctr+c will abort the recording)

And if you want to play it back (of course use your own device here):

aplay -D plughw:2,0 test.wav

If you came this far for own device, you will have now a working input(s). Next is to simultaneous capture and play it back.

Using inputs with MPD and the moOde user interface

In this mode the audio input is captured by MPD before handing over to CamillaDSP or audio device.
This is as simple as creating a playlist with the inputs mapping of above :

#ETM3U

#EXTINF:-1, input 1
alsa://plug:ainput1?format=44100:24:2
#EXTINF:-1, input 2
alsa://plug:ainput2?format=44100:24:2
#EXTINF:-1, input 3
alsa://plug:ainput3?format=44100:24:2
#EXTINF:-1, toslink
alsa://plug:toslink?format=44100:24:2

Place this file in the playlist directory of your moOde system:

  • By using the network share \\<moode host name or ip>\Playlists
  • Or place it directly local on the moode system at the location /var/lib/mpd/playlists/.

In this case I named it motu.m3u.

Unfortunately the EXT information isn’t shown by MPD. It would nicer if the EXT info name was shown instead of the full alsa plugin config.

If it is possible to use the EXTINF, please let me know.

You can find back the playlist in library view of moOde:

Library view of moOde
  • Press on hamburger menu left from playlist name
  • And press Add, Play or Clear/Play

Now the playlist is active of the main screen. You can select a different input by click it on in the current playqueue.

And of course proof that it is playing as expect from the audio information dialog (press the M in the upper right corner and select audio info):

audio information of selected input source

Below is a screenshot with the CPU load of simultaneous capture and playback on a Pi 4:

CPU load simultaneous capture and playback

Despite the fact that the input selection is not fully integrated in moOde, that wasn’t so hard to do. I think we come a long way with the playlist.

Any DSP function like the Peq or CamillaDSP can be applied just like with regular MPD playback.

Using the inputs directly with CamillaDSP

This chapter isn’t needed unless you want to bypass MPD between the capture input and CamillaDSP. But it will be less flexible than the MPD solution.

If you just want to directly use the source with CamillaDSP you can arrange this from the CamillaDSP configuration file.

Only the default configuration of CamillaDSP with moOde doesn’t allow using the inputs from the CamillaDSP configuration file. This is because moOde is using the great alsa_cdsp module from scripple. This module makes automatic rate, format and channel switching possible with CamillaDSP.

But when alsa_cdsp is used alsa_cdsp also is in control of starting and stopping CamillaDSP, which is required when changing rate, format or channels.

To use the inputs directly with CamillaDSP we need to:

Downside is that as long as CamillaDSP standalone is used the output device, no other device can use the output device directly.

Copy a clean config:

  • Select the configuration flat
  • Press copy
  • Named it cdsp_direct
Copy config

Make it the active configuration:

  • Select if as the active config
  • Make sure default device is turned ON
  • Press save
  • Toggle default device OFF
  • Press save again
Set active config

Open the CamillaDSP pipeline editor:

  • Toggle Expert mode to ON
  • Toggle Status to ON
  • Press OPEN
Open the pipeline editor

Set the capture device

  • Change the capture device to alsa
  • Set as device the desired input, in my case ainput1
  • Step 3 is optional

Start CamillaDSP standalone

Login to the terminal (with SSH or the onboard webterminal from moOde in system config)

Type in the following commands:

pi@moode:~ $ mpc stop
pi@moode:~ $ wget https://raw.githubusercontent.com/moode-player/pkgbuild/main/packages/camilladsp/camilladsp.service
pi@moode:~ $ sudo mv ./camilladsp.service /lib/systemd/system
pi@moode:~ $ sudo systemctl start camilladsp
pi@moode:~ $ sudo systemctl status camilladsp

If you are happy with the result, after testing, you can the command below to make sure CamillaDSP is started again after a boot:

pi@moode:~ $ sudo systemctl enable camilladsp

If you play music at input source, you should be able to see it at the volume bar in the pipeline editor:

11 Replies to “moOde with USB input”

  1. hi there,
    so far moode has been updated to version 8.02 and it works great.
    but i want to ask for help from you since i see your blog and you are also a big fan of moode while at the same time, you are good ate linux computing lanagues.
    so i think you might be kind enough to help me out with your ability.

    i love to use music format of the sacd-iso which is originated DSD files .
    and Tim (owner of moode) refused to add sacd-iso mdp into the moode source becaue he think the sacd-iso is not updated from time to time.
    the official mdp source is made by MAX keller mann in below link:
    https://github.com/MaxKellermann/MPD

    but i do know that there is a man who is updating the un-official MPD file with the sacd-iso in below link by ManIsiutkin who is also the same writher for the sacd-iso decoder for foobar, of which works great and world know. this is the source for his work:
    http://git.musicpd.org/cgit/manisiutkin/mpd.git

    so i ask for you help that would you help to teach me or post how to update (or replace) the existing mdp in Moode (any version will be fine) and since i am a noobie in linux lanuages, so a detail tutorial of post iwll be very kind of you.
    i know it is an unreasonable request but just want to check if you can help.
    thanks
    by james

  2. Hi, many thanks for this very useful post.
    I am trying this to get phono input from my turntable, which has a Rega A2D mini preamp with a USB digital output, into Moode. This way I can control volume and use DRC via Camilla with my vinyl.
    I’m almost there. I have successfully recorded and played back vinyl using the arecord and aplay commands above.
    I have now created a playlist file, but when I try to start it, I get the error “Open MpdSock () failed” . Any suggestions for how to debug?
    My playlist file has the contents –
    #EXTINF:-1, input 1
    alsa://plughw:1,0?format 44100:16:2

    Many thanks
    Paul Evans

      1. Hi Marcel,

        I’m having issues as well with the same device. Can’t make it work.

        My parameters are below. Can you help?

        Recording WAVE ‘stdin’ : Unsigned 8 bit, Rate 8000 Hz, Mono
        HW Params of device “hw:1,0,0”:
        ——————–
        ACCESS: MMAP_INTERLEAVED RW_INTERLEAVED
        FORMAT: S8 S16_LE
        SUBFORMAT: STD
        SAMPLE_BITS: [8 16]
        FRAME_BITS: [8 32]
        CHANNELS: [1 2]
        RATE: [8000 48000]
        PERIOD_TIME: [1000 1000000]
        PERIOD_SIZE: [16 48000]
        PERIOD_BYTES: [64 192000]
        PERIODS: [2 1024]
        BUFFER_TIME: (666 2000000]
        BUFFER_SIZE: [32 96000]
        BUFFER_BYTES: [64 384000]
        TICK_TIME: ALL
        ——————–
        arecord: set_params:1343: Sample format non available
        Available formats:
        – S8
        – S16_LE

  3. Hi,
    I’m trying to use an analog stereo input with moode
    to route the audio from an DVD/CD player
    to a Behringer UCA222 usb dac.
    It appears correctly with arecord -l
    The sample format of the device is S16_LE
    has two channels (stereo)
    resolution 8-48 Khz
    So I don’t need to split channels
    only 1 input that will capture/play 2 channels stereo

    How must be the config in alsa?
    /etc/alsa/conf.d/inputs.conf

    just this?

    pcm_slave.ins {
    pcm “hw:2,0,0”
    rate 48000
    channels 2
    }

    Thanks in advance,
    Pedro

  4. Hi Pedro,
    In your case you can leave out the inputs.conf at all.
    You can directly use the device in the playlist.

    Marcel

  5. Been trying this for a couple of days but can’t make it work.

    I’m using an RPI4 and a usb Behringer sound card (UCA222).

    The setup is as follows:

    Turntable -> Preamp -> USB sound card -> RPI4 -> HiFiBerry AMP2 -> Speakers

    Can you help me with this please?

    1. No problem to provide some support, but please request support by starting a thread in the moode forum.

  6. Fantastic write up.

    I’m attempting to get sound into a stubborn Audi with no aux inputs from a 3.5mm source!

    I’ve got it working but the latency is nearly 10 seconds…even after I reduce the Bluetooth Output buffer in Mo0de to 40ms. Believe it’s a buffer on the USB input. Any thoughts how I could improve this?

    Thanks!

  7. Hi,
    Thanks for the wonderful post.
    I am using moode audio 8.3.7 64bit version on raspberry pi 4 2gb variant.
    I have connected an usb sound card which has one channel only.
    I think i can use it without splitting channels as described in your post but i can’t find the syntax to add it to a playlist so i followed your tutorial.

    I followed all the steps you have mentioned:
    My usb sound card setup as per the post is as follows:

    Content in /etc/alsa/conf.d/motu_avb_inputs.conf

    pcm_slave.motu {
    pcm “hw:2,0,0”
    rate 44100
    channels 1
    }
    pcm.ainput1 {
    type dsnoop
    ipc_key 12378
    slave motu
    bindings.0 0
    }

    Content in /var/lib/mpd/playlists/

    alsa://plug:ainput1?format=44100:1:1

    Now when i select motu.m3u from playlist and hit play, i get an error saying:
    “Failed to decode alsa://plug:ainput1?format=44100:1:1; Invalid sample format: 1”

    When i remove the “=” sign from Content in /var/lib/mpd/playlists/
    alsa://plug:ainput1?format44100:1:1

    Now when i select motu.m3u from playlist and hit play, i get an error saying:
    “openMpdSock() failed”

    Could you please help.

  8. Satyam
    10 DECEMBER 2023 AT 15:55
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.
    Hi,
    Thanks for the wonderful post.
    I am using moode audio 8.3.7 64bit version on raspberry pi 4 2gb variant.
    I have connected an usb sound card which has one channel only.
    I think i can use it without splitting channels as described in your post but i can’t find the syntax to add it to a playlist so i followed your tutorial.

    I followed all the steps you have mentioned:
    My usb sound card setup as per the post is as follows:

    Content in /etc/alsa/conf.d/motu_avb_inputs.conf

    pcm_slave.motu {
    pcm “hw:2,0,0”
    rate 44100
    channels 1
    }
    pcm.ainput1 {
    type dsnoop
    ipc_key 12378
    slave motu
    bindings.0 0
    }

    Content in /var/lib/mpd/playlists/

    alsa://plug:ainput1?format=44100:1:1

    Now when i select motu.m3u from playlist and hit play, i get an error saying:
    “Failed to decode alsa://plug:ainput1?format=44100:1:1; Invalid sample format: 1”

    When i remove the “=” sign from Content in /var/lib/mpd/playlists/
    alsa://plug:ainput1?format44100:1:1

    Now when i select motu.m3u from playlist and hit play, i get an error saying:
    “openMpdSock() failed”

    Could you please help.

Leave a Reply

Your email address will not be published.