Skip to content

Instantly share code, notes, and snippets.

@csete
Created November 5, 2010 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csete/664132 to your computer and use it in GitHub Desktop.
Save csete/664132 to your computer and use it in GitHub Desktop.
OBSOLETE. Fix "audio_alsa_sink[hw:0,0]: snd_pcm_hw_params failed: File descriptor in bad state".
diff --git a/gr-audio-alsa/src/audio_alsa_sink.cc b/gr-audio-alsa/src/audio_alsa_sink.cc
index d6b7f84..38ed86b 100644
--- a/gr-audio-alsa/src/audio_alsa_sink.cc
+++ b/gr-audio-alsa/src/audio_alsa_sink.cc
@@ -219,9 +219,15 @@ audio_alsa_sink::check_topology (int ninputs, int noutputs)
int nchan = ninputs;
int err;
- // FIXME check_topology may be called more than once.
+ // Check the state of the stream
// Ensure that the pcm is in a state where we can still mess with the hw_params
-
+ snd_pcm_state_t state;
+ state=snd_pcm_state(d_pcm_handle);
+ if ( state== SND_PCM_STATE_RUNNING)
+ return true; // If stream is running, don't change any parameters
+ else if(state == SND_PCM_STATE_XRUN )
+ snd_pcm_prepare ( d_pcm_handle ); // Prepare stream on underrun, and we can set parameters;
+
bool special_case = nchan == 1 && d_special_case_mono_to_stereo;
if (special_case)
nchan = 2;
@bz94
Copy link

bz94 commented Jan 22, 2019

hi thanks for this patch
how can i apply this patch in raspbian version of gnu_companion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment