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

Page 98

Advertising
background image

KTD-S0057-I

Page 94 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide


/* Underrun and suspend recovery */
static int xrun_recovery (snd_pcm_t *handle, int err)
{
if

(verbose)

printf("Stream

recovery\n");

if (err == -EPIPE)

/* under-run */

{

err = snd_pcm_prepare (handle);

if (err < 0)

printf ("Can't recovery from underrun, prepare failed: %s\n", snd_strerror (err));

return

0;

}

else if (err == -ESTRPIPE)

{

while ((err = snd_pcm_resume (handle)) == -EAGAIN)

sleep (1);

/* wait until the suspend flag is released */

if (err < 0)

{

err = snd_pcm_prepare (handle);

if (err < 0)

printf ("Can't recovery from suspend, prepare failed: %s\n", snd_strerror (err));

}

return

0;

}

return

err;

}

/* Transfer method - write only */

static int write_loop (snd_pcm_t *handle, signed short *samples, snd_pcm_channel_area_t *areas)
{

double phase = 0;

signed short *ptr;

int err, cptr;

while

(1)

{

generate_sine (areas, 0, period_size, &phase);

ptr = samples;

cptr = period_size;

while (cptr > 0)

{

err = snd_pcm_writei (handle, ptr, cptr);

if (err == -EAGAIN)

continue;

if (err < 0)

{

if (xrun_recovery (handle, err) < 0)

{

printf ("Write error: %s\n", snd_strerror (err));

exit

(EXIT_FAILURE);

}

Advertising
This manual is related to the following products: