This is my initialization of the sound card.
First of all, I set the necessary parameters
static
int init_soundcard (snd_pcm_t *handle, unsigned *rate, uint8_t channels,
snd_pcm_uframes_t *nframes, unsigned *period)
{
snd_pcm_hw_params_t *hwparams;
int err;
snd_pcm_hw_params_alloca(&hwparams);
err = snd_pcm_hw_params_any(handle, hwparams);
if (err < 0) return err;
err = snd_pcm_hw_params_set_rate_near(handle, hwparams, rate, NULL);
if (err < 0) return err;
err = snd_pcm_hw_params_set_access(handle, hwparams,
SND_PCM_ACCESS_RW_INTERLEAVED);
if (err < 0) return err;
err = snd_pcm_hw_params_set_format(handle, hwparams,
SND_PCM_FORMAT_S16_LE);
if (err < 0) return err;
err = snd_pcm_hw_params_set_channels(handle, hwparams, channels);
if (err < 0) return err;
When each parameter is configured correctly, the parameters are applied to the descriptor:
err = snd_pcm_hw_params(handle, hwparams);
if (err < 0) return err;
After it has been applied, a brave programmer can get the required data as follows:
get_period_size_min () gives the minimum frame size of the buffer that will contain the selection. A buffer having this size is wide enough.
err = snd_pcm_hw_params_get_period_size_min(hwparams, nframes, NULL);
if (err < 0) return err;
, 1/, . get_period_time()!
err = snd_pcm_hw_params_get_period_time(hwparams, period, NULL);
if (err < 0) return err;
return 0;
}