This morning, I wrote a very quick external for PureData which allows it to read from an MCP3008 via pigpio.

This works well until the DAC is enabled, upon which PureData almost immediately crashes with an ALSA error:

restart alsa output
alsa xrun recovery apparently failed
pd: pcm.c:1168: snd_pcm_prepare: Assertion `pcm' failed.
2021-09-05 21:23:19 sigHandler: Unhandled signal 6, terminating

Looking at this post which suggested a possible cause, I added gpioCfgClock(5, 0, 0); before gpioInitialise(). When this is in place, PureData doesn't crash but I can only hear what sounds like a stream of data through the in-built headphone jack.

I am using CS 25, MISO 6, MOSI 16 and SCLK 5.

This is a mostly bog-standard Raspbian install. Also, I should be receiving a USB audio device soon - not sure if that will magically make the problem go away.

1 Answer 1



Sound isn't working

The Pi contains two pieces of hardware, a PWM peripheral and a PCM peripheral, to generate sound. The PWM peripheral is normally used and generates medium quality audio out of the headphone jack. The PCM peripheral may be used by add-ons such as HATs and generates high quality audio.

pigpio uses at least one of these peripherals during normal operation (for timing DMA transfers). pigpio will use both peripherals if waves or the hardware PWM function is used.

By default pigpio uses the PCM peripheral leaving the PWM peripheral free for medium quality audio.

You can change the default with a configuration option. For C use gpioCfgClock, for the pigpio daemon use the -t option.

If you can't resolve the problem with pigpio and the only use for pigpio is SPI I suggest you use (my) lg library instead.

  • Sorry I didn't think to look at your FAQ. Unfortunately I'm rather relying on pigpio's bit banging functions as I have two MCP2008's and two port expanders that need to be connected. I'll be trying the Patchbox distribution shortly anyway; will be interested to see if this changes anything. Sep 5, 2021 at 9:42
  • Patchbox, using JACK, doesn't result in PureData crashing but does result in choppy audio. Marginally better... Sep 5, 2021 at 11:43
  • Cheap USB audio device arrived today. Curiously, PWM vs PCM made no difference to the output - both resulted in choppy audio via Jack. Then I realised that I had the baud set very low for bbSPIOpen(). Upping it to 250000 did the trick. (Is this a filthy hack? Has my audio been imperceptibly degraded as a result?) Sep 6, 2021 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.