andrewrk / libsoundio

C library for cross-platform real-time audio input and output
http://libsound.io/
MIT License
1.93k stars 228 forks source link

"incompatible device" when checking layout_error in sio_record.c example #230

Open joprice opened 4 years ago

joprice commented 4 years ago

In order to repro an issue I was having trouble debugging using a rust wrapper to this library (https://github.com/RamiHg/soundio-rs), I tried out a similar example sio_record.c, and it worked. I found that the different is that the rust one by default checks the layout_error field https://github.com/RamiHg/soundio-rs/blob/master/src/device.rs#L473 and the example in this repo doesn't. When I added the following check to the example I get the same error I got in the rust version ("incompatible device"):

 if (instream->layout_error) {
  fprintf(stderr, "unable to open input stream: %s", soundio_strerror(instream->layout_error));
  return 1;
}

Is this a bug in the example, or can this error be ignored in some cases?

joprice commented 4 years ago

It looks like this is based on a call to snd_pcm_set_chmap https://github.com/andrewrk/libsoundio/blob/master/src/alsa.c#L1689. A quick google found me an interesting comment in a random project that lines up with what I'm seeing. https://github.com/moonlight-stream/moonlight-qt/blob/master/app/streaming/audio/renderers/soundioaudiorenderer.cpp#L203. This makes me think that some devices don't allow modifying the channel map. And, if it's already configured as desired, maybe a call to snd_pcm_get_chmap first can detect if the set call is actually needed?