I am trying to get the minimum and maximum number of channels supported by my device. The results are unexpected and random. They change at each execution. Did I miss something?
// file : capture_nb_chan.c
#include <stdio.h>
#include <alsa/asoundlib.h>
int main(int argc, char* argv[])
{
int err;
snd_pcm_t *capture_handle;
snd_pcm_hw_params_t *hw_params;
unsigned int min, max;
// Open audio device
if ((err = snd_pcm_open (&capture_handle, "hw:0,0", SND_PCM_STREAM_CAPTURE, 0)) < 0)
exit (1);
// Allocate hardware parameters
if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0)
exit (1);
// Initialize parameters
if ((err = snd_pcm_hw_params_any (capture_handle, hw_params)) < 0)
exit (1);
// Get min and max number of channels
err = snd_pcm_hw_params_get_channels_min(hw_params, &min);
if (err < 0)
exit (1);
fprintf(stdout, "Min channels: %u. (%d)\n", min, err);
err = snd_pcm_hw_params_get_channels_max(hw_params, &max);
if (err < 0)
exit (1);
fprintf(stdout, "Max channels: %u. (%d)\n", max, err);
}
Compile the script with
gcc -o capture_nb_chan capture_nb_chan.c -lasound
Execute it with
./capture_nb_chan
Output is
Min channels: 22031. (2)
Max channels: 681205789. (2)
Output values are random while error code is 2
when it's expected to be 0
or negative according to documentation.