0

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.

nullPainter
  • 115
  • 4

1 Answers1

2

http://abyz.me.uk/rpi/pigpio/faq.html#Sound_isnt_working

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.

joan
  • 71,852
  • 5
  • 76
  • 108