beautypg.com

Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual

Page 96

background image

KTD-S0057-I

Page 92 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide


/* set the stream rate */

rrate = rate;

err = snd_pcm_hw_params_set_rate_near (handle, params, &rrate, 0);

if (err < 0)

{

printf ("Rate %iHz not available for playback: %s\n", rate, snd_strerror (err));

return

err;

}

if (rrate != rate)

{

printf ("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err);

return

-EINVAL;

}

/* set the buffer time */

err = snd_pcm_hw_params_set_buffer_time_near (handle, params, &buffer_time, &dir);

if (err < 0)

{

printf ("Unable to set buffer time %i for playback: %s\n", buffer_time, snd_strerror (err));

return

err;

}

err = snd_pcm_hw_params_get_buffer_size (params, &size);

if (err < 0)

{

printf ("Unable to get buffer size for playback: %s\n", snd_strerror (err));

return

err;

}

buffer_size = size;

/* set the period time */

err = snd_pcm_hw_params_set_period_time_near (handle, params, &period_time, &dir);

if (err < 0)

{

printf ("Unable to set period time %i for playback: %s\n", period_time, snd_strerror (err));

return

err;

}

err = snd_pcm_hw_params_get_period_size (params, &size, &dir);

if (err < 0)

{

printf ("Unable to get period size for playback: %s\n", snd_strerror (err));

return

err;

}

period_size = size;

/* write the parameters to device */

err = snd_pcm_hw_params (handle, params);

if (err < 0)

{

printf ("Unable to set hw params for playback: %s\n", snd_strerror (err));

return

err;

}
return

0;

}

This manual is related to the following products: