[alsa-devel] Using snd_pcm_set_params() on a capture handle

Erik de Castro Lopo mle+la at mega-nerd.com
Mon Oct 26 10:23:21 CET 2015


Clemens Ladisch wrote:

> Erik de Castro Lopo wrote:
> >     RATE: [44100 96000]
> 
> snd_pcm_set_params() should have chosen a single rate.
> Did you dump this after that call?

Yep, the code is:

    snd_pcm_format_t format = SND_PCM_FORMAT_S32_LE;
    snd_pcm_hw_params_t *hw_params;
    snd_output_t *output ;
    unsigned int rate = 48000 ;

    if ((err = snd_pcm_set_params (capture_handle, format, SND_PCM_ACCESS_RW_INTERLEAVED, 2, rate, 0, 25000)) < 0) {   /* 0.5sec */
        printf ("Capture open error: %s\n", snd_strerror (err));exit(1);
    }

    if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
        printf ("Cannot allocate hardware parameter structure (%s)\n", snd_strerror (err));exit(1);
    }

    if ((err = snd_pcm_hw_params_any (capture_handle, hw_params)) < 0) {
        printf ("Cannot initialize hardware parameter structure (%s)\n", snd_strerror (err));exit(1);
    }

    snd_output_stdio_attach (&output, stderr, 0) ;
    snd_pcm_hw_params_dump (hw_params, output) ;
    snd_output_close (output) ;

    snd_pcm_hw_params_free (hw_params);


Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/


More information about the Alsa-devel mailing list