Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


USB Audio Gadget (Raspberry as USB DSP/DAC)
#1
Hello, I know it's possible to use the raspberry pi 4 as USB audio input.

This is usually referred as USB Audio Gadget mode (dtoverlay=dwc2).
This allows the raspberry to be seen as a soundcard via usb connector, aka you get audio input via the usb socket without adding another HAT.

It was a cumbersome procedure years ago as it was not supported in kernel and there wasn't camilladsp around at the time...
but then it got full support in 5.18 kernel and we also have camilladsp in moode.

It seems it works both over ethernet and USB. (I'd prefer leaving the ethernet untouched and just use the usb...)
rpi4 and rpi0 have the usb host capability, older raspberries not?

A few lines and it will show up as new alsa capture device, then one could enable within the moode or camilladsp gui.

Has anyone here tried it with moode? I plan to do some tests soon.
Could it be included into moode somehow?
thank you.

instructions on how to enable it on rpi4 (ignore the hw requirements and kernel mods sections):
https://www.audiosciencereview.com/forum...st-1180356

the main discussion (long) on diyaudio:
https://www.diyaudio.com/community/threa...tg.342070/

the older discussion (too old):
https://www.diyaudio.com/community/threa...ac.341590/


Quote:quote from CharlieLaub
It turns out that the new Raspberry Pi 4B also has an OTG capabilities via the USB-C port (typically used to provide power to the Pi). We can use this OTG host to convert the USB-C port into a USB gadget connection as long as we power the Pi via other means (e.g. via the GPIO pins).

As luck would have it, I have been using an 8-channel HDMI audio extractor HAT that can power the Pi via the GPIO pins and can provide 8 analog outputs at up to 24/192. When combined with the Pi 4 running as a USB gadget, the Pi can receive audio, perform DSP on it, and then output up to 8 independent channels. This would comprise a very nice USB DSP+DAC unit!
Pi4 1gb - Moode 8.3.9 / 9.1.4
Suptronics X6000 7.1ch HDMI hat
Reply
#2
I'm not exactly sure what OTG mode requires as far configurations and UI but eventually it will be integrated into moOde.

The challenge is that the work effort is not trivial and would need the expertise of @bitlab to help define the requirements and test cases.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
I still don't understand what this might be useful for...
Reply
#4
@Nutul
You can use your Pi as USB device for your computer/tablet/other streamer or whatever device that support USB UAC audio devices.
In combination with CamillaDSP that is very a very flexible DSP solution. Reason for enough people to use usb device 'input device > camilladsp > output' as a standalone solution.

@challenge
I have a very restricted version setup of the usb gadget working. My personal use case is running REW from laptop directly on Pi based I2S dac.
For music streaming I use the moode core functionality :-)

For configuration of the usb gadget I use [url= https://github.com/linux-usb-gadgets/gt]gt[/url] in combination with libusbg:
Code:
# personal build from libusgbx and gt as pacakge:
sudo apt install ./libusbgx_0.2.0~git20230410.721e3a1-1moode1_arm64.deb ./gt_0.0.1-1moode1_arm64.deb

sudo bash -c 'echo "dtoverlay=dwc2,dr_mode=peripheral" >> /boot/config.txt'
sudo bash -c 'echo "libcomposite" >> /etc/modules'
sudo reboot

# and after the reboot load agadget schemea
sudo gt load ./uac.scheme g1
Down side is that gt currently doesn't setting up usb uac gadgets with multiple samplerate support. Still on my list to do fix that, but wasn't very trival to do.

An example scheme for an UAC USB gadget configuration:
Code:
attrs :
{
   idVendor = 0x1D6B;
   idProduct = 0x104;
};
strings = (
       {
               lang = 0x409;
               manufacturer = "moode";
               product = "moode-player";
       }
);
functions :
{
   uac2_usb0 :
   {
       instance = "usb0";
       type = "uac2";
       attrs :
       {
           c_chmask = 3;
           c_srate = 44100;
           c_ssize = 3;
           p_chmask = 0;
           p_srate = 44100;
           p_ssize = 3;
       };
   };
};
configs = (
   {
       id = 1;
       name = "c";
       functions = (
           {
               name = "uac2.usb0";
               function = "uac2_usb0";
           } );
       p_ssize = "3";
   }
);
Normally with moode CamalliaDSP is controlled by alsa_cdsp (cammiladsp doesn't run as a service).
Found using the usb gadget as an MPD input to slow and has a few other quirks.
But in case of the usb gadget is more desirable, when usb gadget activity is detected,  to start the camilladsp systemd service instead.


Required, over-simplified, steps:
* setup usb gadget mode support
* gt/libusbg multiple sample rate support for generating gadget configs
* detect gadget use
* when active use it to change the default camilladsp config start the camilladsp service 
* and when stop reverse it again
* and some gui support for it to
Reply
#5
This capability would definitely lift moOde into the prosumer category. I easily could have used it in the audio reinforcement system for the high school theater I was supporting technically during my grandkids’ years there.

Wish I were 60 years younger. Back when I was getting started, stereo was still in its infancy, audio gear was all vacuum tubes, noisy pots, and patch cords, and audio filters were black magic. What we have at our fingertips now is truly amazing (and amazingly cheap).

And I still hope to grok the innards of ALSA before I die!

Regards,
Kent
Reply
#6
@bitlab  thank you for the guide.
Yeah you got it, would be really nice to be able to use REW to correct your room/position calibration by just hooking usb cable and load a REW generated EQ'd camilladsp curve. :-)
I think many could use it, even on desk to fix their frequency response. Even on cheap speakers is quite an upgrade...
Well, I play with diy speakers and multi-channel active Xover too (I saw your website Big Grin  ), but not much time these days. For that I have other equipment. But still, quickly hooking a cable to do REW measurements and see if things are right, can be a time saver.

@TheOldPresbyope true. I am much younger than you and hear that everyday from older folks. There's a lot of knowledge these days available for free and there are no excuses/low barriers to thinker/learn how stuff works these day. 

@Tim Curtis as I said, not urgent, but was just to write it here otherwise I would've forgotten about it. Just posted to see if there is any need for this.
Aside us RoomEqWizard nerds, using moode/Camilla (with a DAC) as a usb DAC/soundcard pretty much it kinda gives it new meaning.
I read there are issues to an automatic sampling rates switching, but don't think it's really a deal breaker.
Can't code enough for this kind of stuff, but will be available to test if needed.
Pi4 1gb - Moode 8.3.9 / 9.1.4
Suptronics X6000 7.1ch HDMI hat
Reply


Forum Jump: