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

KTD-S0057-I
Page 97 Linux® Programming Examples (DebianTM)
KTAM3874/pITX Software Guide
/* it is possible that the initial buffer cannot store all data from the last period - so wait awhile */
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;
}
}
}
}
}
/* Transfer method - asynchronous notification */
static void async_callback (snd_async_handler_t *ahandler)
{
snd_pcm_t *handle = snd_async_handler_get_pcm (ahandler);
struct async_private_data *data = snd_async_handler_get_callback_private (ahandler);
signed short *samples = data->samples;
snd_pcm_channel_area_t *areas = data->areas;
snd_pcm_sframes_t
avail;
int
err;
avail = snd_pcm_avail_update (handle);
while (avail >= period_size)
{
generate_sine (areas, 0, period_size, &data->phase);
err = snd_pcm_writei (handle, samples, period_size);
if (err < 0)
{
printf ("Write error: %s\n", snd_strerror (err));
exit
(EXIT_FAILURE);
}
if (err != period_size)
{
printf ("Write error: written %i expected %li\n", err, period_size);
exit
(EXIT_FAILURE);
}
avail = snd_pcm_avail_update (handle);
}
}