A patch to fix audio_alsa_sink[hw:0,0]: snd_pcm_hw_params failed

Last night, while I was preparing for the AMSAT-OZ satellite weekend, I noticed that my gqrx receiver didn’t work very well on my laptops. Every time I tried to change operating mode the receiver stopped with a runtime error:

audio_alsa_sink[hw:0,0]: snd_pcm_hw_params failed: File descriptor in bad state
terminate called after throwing an instance of 'std::runtime_error'
what():  check topology failed on audio_alsa_sink(1) using ninputs=1, noutputs=0

This happened on both my Acer and my MacBook Pro; both running the lates git of GNU Radio v3.3.1git-96-g1fa9a8ea. This was bad news because I was hoping to show off my new software receiver with Qt GUI during the weekend. Fortunately, there is an easy workaround that eliminates the problem.

A quick search in my mail archive reminded me of this thread from October, suggesting that the problem can be fixed by adding a static boolean flag and use it to only call snd_pcm_hw_params() once. The changes are trivial and fix the problem even though it may not be the right way to do so. I can imagine cases where this may not work, e.g. if the audio parameters are reconfigured at runtime. For now it is sufficient.


With this patch applied I think we could also implement a multi-mode receiver in GNU Radio Companion using the selector block.

Author: Alexandru Csete

Embedded software engineer in the satcom industry during the day. Radio amateur and SDR hacker during the night.