somebodyelse
Master Contributor
- Joined
- Dec 5, 2018
- Messages
- 5,095
- Likes
- 4,641
One of the lesser known features of the Raspbery Pi Zero is that you can use its USB port in device mode with the various linux 'gadget' drivers. The audio gadget driver will make the Pi appear to be a USB audio interface when you plug it into a PC, streamer or whatever USB host, with certain limitations we'll come to in a bit. The same is probably true of the Pi 4 via the USB type C socket usually used for power, but I haven't yet seen confirmation that it works. It may also work with the Pi A and A+ but you'd need a non-standard USB cable.
The basic idea is that we use the audio gadget driver to create an audio interface via the USB port, and have another audio interface on I2S, such as the HifiBerry or Allo DAC hats. We can then configure a passthrough from one interface to the other, or put some processing like BruteFIR for room correction in between them. Initially we'll look at configuring this manually via an ssh connection, but once we've decided on what needs to be done it can be committed to config files so that you just need to plug it in and wait for it to boot.
I started with Raspbian Jessie Lite on a Pi Zero W and configured it for headless WiFi and ssh access. Follow a tutorial like this one - a search for "pi zero headless ssh wifi" and your OS should get you something suitable. If you're not familiar with ssh you should look for a tutorial on that too.
The method for enabling this functionality has changed a bit since the Zero was first released, and may change again. The method outlined in Andrew Mulholland's Gist is confirmed working with Raspbian Jessie Lite. I've not tried it with the recently released Buster version. Andrew doesn't detail the g_audio module options for setting the bit depth and sample rate though. You'd use something like:
That will create a capture interface at 192kHz 32 bit (4 byte) and a playback interface at 48kHz 16 bit. I don't remember which perspective capture and playback are from though - I suspect from the Pi. This is where we meet the major limitation - currently it can only present one sample rate and format at a time for each interface. if you want to change it you have to unload the g_audio module, then load it again with the new settings:
I'll follow up later with details of how to route audio between the interfaces.
The basic idea is that we use the audio gadget driver to create an audio interface via the USB port, and have another audio interface on I2S, such as the HifiBerry or Allo DAC hats. We can then configure a passthrough from one interface to the other, or put some processing like BruteFIR for room correction in between them. Initially we'll look at configuring this manually via an ssh connection, but once we've decided on what needs to be done it can be committed to config files so that you just need to plug it in and wait for it to boot.
I started with Raspbian Jessie Lite on a Pi Zero W and configured it for headless WiFi and ssh access. Follow a tutorial like this one - a search for "pi zero headless ssh wifi" and your OS should get you something suitable. If you're not familiar with ssh you should look for a tutorial on that too.
The method for enabling this functionality has changed a bit since the Zero was first released, and may change again. The method outlined in Andrew Mulholland's Gist is confirmed working with Raspbian Jessie Lite. I've not tried it with the recently released Buster version. Andrew doesn't detail the g_audio module options for setting the bit depth and sample rate though. You'd use something like:
Code:
sudo modprobe g_audio c_srate=192000 c_ssize=4 p_srate=48000 p_ssize=2
Code:
sudo modprobe -r g_audio
sudo modprobe g_audio c_srate=96000 c_ssize=4 p_srate=96000 p_ssize=4
I'll follow up later with details of how to route audio between the interfaces.