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

Page 99

Advertising
background image

KTD-S0057-I

Page 95 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide


break;

/* skip one period */

}

ptr += err * channels;

cptr -= err;

}

}
}

/* Transfer method - write and wait for room in buffer using poll */

static int wait_for_poll (snd_pcm_t *handle, struct pollfd *ufds, unsigned int count)
{

unsigned short revents;

while

(1)

{

poll (ufds, count, -1);

snd_pcm_poll_descriptors_revents

(handle, ufds, count, &revents);

if (revents & POLLERR)

return

-EIO;

if (revents & POLLOUT)

return

0;

}
}


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

struct pollfd *ufds;

double phase = 0;

signed short *ptr;

int err, count, cptr, init;

count = snd_pcm_poll_descriptors_count (handle);

if (count <= 0)

{

printf ("Invalid poll descriptors count\n");

return

count;

}

ufds = malloc (sizeof (struct pollfd) * count);

if (ufds == NULL)

{

printf ("Not enough memory\n");

return

-ENOMEM;

}

if ((err = snd_pcm_poll_descriptors (handle, ufds, count)) < 0)

{

printf ("Unable to obtain poll descriptors for playback: %s\n", snd_strerror (err));

return

err;

}

Advertising
This manual is related to the following products: