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

KTD-S0057-I
Page 96 Linux® Programming Examples (DebianTM)
KTAM3874/pITX Software Guide
init = 1;
while
(1)
{
if (! init)
{
err = wait_for_poll (handle, ufds, count);
if (err < 0)
{
if (snd_pcm_state (handle) == SND_PCM_STATE_XRUN ||
snd_pcm_state (handle) == SND_PCM_STATE_SUSPENDED)
{
err = snd_pcm_state (handle) == SND_PCM_STATE_XRUN ? -EPIPE : -ESTRPIPE;
if (xrun_recovery (handle, err) < 0)
{
printf ("Write error: %s\n", snd_strerror (err));
exit (EXIT_FAILURE);
}
init
=
1;
}
else
{
printf ("Wait for poll failed\n");
return
err;
}
}
}
generate_sine (areas, 0, period_size, &phase);
ptr = samples;
cptr = period_size;
while (cptr > 0)
{
err = snd_pcm_writei (handle, ptr, cptr);
if (err < 0)
{
if (xrun_recovery (handle, err) < 0)
{
printf ("Write error: %s\n", snd_strerror (err));
exit
(EXIT_FAILURE);
}
init
=
1;
break;
/* skip one period */
}
if (snd_pcm_state (handle) == SND_PCM_STATE_RUNNING)
init
=
0;
ptr += err * channels;
cptr -= err;
if (cptr == 0)
break;