alsa audio-in with Pure Data and USB dongle


12 posts
by jeffaaronbryant » Wed Oct 03, 2012 9:39 pm
I've been working on getting audio going in both directions with Pure Data and a USB audio dongle
Code: Select all
pi@raspberrypi ~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  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


and I've got audio-out going just fine, with no distortion with:

Code: Select all
#pd -nogui -noadc some_patch.pd


but when I try a simple patch with adc~ straight to dac~, no matter what settings I use with PD, anything with adc enabled crashes the audio- some of the crashes produce a few seconds of audio- at this point, I've tried 4 different configurations for /etc/asound.conf, but always get about a 1.5s of audio in the middle of a crash like this:

Code: Select all
pi@raspberrypi ~ $ pd -audioindev 1 -audiooutdev 1 -inchannels 1 -outchannels 2 -nogui -path ~/Documents/pd_rpi -alsa -r 44100 -rt -blocksize 64 -nomidi adc_dac.pd
sys_nmidiin 0, nmidiindev 0
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
...
...


I've been finding people are getting audio recording to work with arecord and audacity, but has ANYONE gotten audio-in with PD?
Posts: 2
Joined: Wed Oct 03, 2012 9:17 pm
by jeffaaronbryant » Wed Oct 03, 2012 9:56 pm
I should also include that even asking PD about devices produces this crash:

Code: Select all
pi@raspberrypi ~ $ pd -nogui -listdev
audio input devices:
1. USB PnP Sound Device (hardware)
2. USB PnP Sound Device (plug-in)
3. bcm2835 ALSA (hardware)
4. bcm2835 ALSA (plug-in)
audio output devices:
1. USB PnP Sound Device (hardware)
2. USB PnP Sound Device (plug-in)
3. bcm2835 ALSA (hardware)
4. bcm2835 ALSA (plug-in)
API number 1

no midi input devices found
no midi output devices found
snd_pcm_hw_params_set_channels (input): Invalid argument
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
output snd_pcm_delay failed: No such device
output snd_pcm_status failed
...
...
...
Posts: 2
Joined: Wed Oct 03, 2012 9:17 pm
by damian0815 » Fri Nov 16, 2012 6:45 pm
In my experience Pd isn't the most polite when talking to ALSA, it seems to use features of ALSA that are not well implemented on embedded devices -- this has been a consistent problem with Beagleboard, BeagleboardXM and Pandaboards.

The best way to do things is to roll your own audio driver based on RtAudio (it's not actually that difficult) and plug it in to LibPd https://github.com/libpd. One of these days I'll get around to making a pull request to LibPd that does exactly that...
Posts: 3
Joined: Fri Nov 16, 2012 6:42 pm
by millerpuckette » Tue Nov 20, 2012 10:32 pm
Hmmm.. I'd love to fix this (trying myself without success to get audio into
PD on Pi). Any idea what specific alsa features Pd's using that SBCs don't
like?

The ALSA code in Pd is originally by Guenter Geiger (I believe) and my own
understanding of it is less than perfect :)
Posts: 22
Joined: Tue Sep 11, 2012 4:25 am
by newdendrite » Wed Nov 21, 2012 5:58 pm
There are many of us who are also very interested in seeing this fixed. I hope that those of you in the know will keep at it -- and thanks!

Best regards,
Michael
Posts: 12
Joined: Tue Jun 05, 2012 7:29 pm
by robertesler » Wed Nov 21, 2012 8:12 pm
Though this doesn't solve the issue of I/O on a single Pi, I have been quite successful using two Pies, one for input (USB) and one for output and then networking them. I have used both netsend~ and streamout~ for this and I get little to no latency with decent quality. Still a few slips and crackles in the audio, but both work simultaneously.

I documented it here: http://robertesler.com/raspberry-pi-2-pi-io/
Posts: 1
Joined: Wed Nov 21, 2012 8:05 pm
by CaptainBassline » Sat Nov 24, 2012 12:20 am
Hi, forgive my interruption, but I too am having issues with ALSA and Puredata. At one point I had sound output perfectly, but now, even with the same settings that worked, I am getting snd_pcm_open driver or resource busy... This has only happened since I hooked up my USB MIDI keyboard which will only work on ALSA MIDI default......any ideas?

By the way I'm using Pd-ext 0.43.3 rather than Vanilla....

Thanks
Posts: 11
Joined: Thu Nov 15, 2012 9:49 am
by millerpuckette » Sat Nov 24, 2012 4:14 am
I've just been trying to get clean audio input and can't do it no matter what I try
(Pd or audacity; Coby USB headset of Edirol USB interface) - this after bringing
the Pi software and firmware up to date, and with audio output disabled, I still get
wierdness on input. Working at 44100 Hx I get a slowed-down tone, as if the
converters were running at 48K, and lots and lots of irregular glitches. At 48000
I get the right pitch but still glitches all over the place (maybe 5-10 times per second
depending on what software and interface).

Can anyone else figure out a way to record audio that doesn't glitch? Surely there
must be some way to get working audio input.

cheers
Miller
Posts: 22
Joined: Tue Sep 11, 2012 4:25 am
by millerpuckette » Sat Nov 24, 2012 4:36 am
Anyhow, I've got Pd running better on the Pi than it did before... there's a test version
compiled here: http://crca.ucsd.edu/~msp/software.html

cheers
Miller
Posts: 22
Joined: Tue Sep 11, 2012 4:25 am
by millerpuckette » Thu Nov 29, 2012 5:29 am
Found this from sleep_lack on another thread:
viewtopic.php?t=10848&p=191748

Some USB 2.0 features are still not working on the Pi, and the clever
workaraound is simply to restrict USB to 1.1, which forces even USB
2.0-capable devices to revert to the (correctly-supported but more
primiive) 1.1 feature set. I tried this and succeeded with a COBY headset
(straight out of the Pi) and with a Turtle beach USB converter (which I
had to hang off a powered hub as it's too power-hungry to connect
directly to the Pi). OTOH my very trusty Edirol UA-25 didn't work at all
at 1.1.

The magic is to edit /boot/cmdline.txt and add an argument
dwc_otg.speed=1
the reboot. The gotcha is that any other USB devices also must run at 1.1
speeds; the network in particular (which is logically a USB device) slows down
to 10% of its normal speed.

But audio in then works cleanly!
Posts: 22
Joined: Tue Sep 11, 2012 4:25 am
by robotfunk » Mon Sep 09, 2013 2:48 pm
After some tinkering I finally have a cheap Behringer USB audio card working with pd on the RPi. Eventually I want to turn this into a a cv controlled effect/synth box.

This thread has been very helpful in allowing me to use audio input with pd but I have a problem. Even without running any app I always hear the sound of the inputs directly at the outputs. Is there a way to turn off this 'monitoring' so that I could hear the pure pd-processed sound at the outputs?
Posts: 45
Joined: Wed May 30, 2012 7:28 pm
by pkrakow » Wed Oct 09, 2013 3:39 am
Have you tried playing with amixer settings from the command line interface?

Something like:
amixer sset Mic Capture 100%
amixer sset Mic Playback 0%

should do the trick.

That said, I'm on this thread because I can't figure out how to get Audio In to work properly with PD, so I'm just guessing. I just know that works with arecord.
Posts: 14
Joined: Sat May 25, 2013 4:26 pm