Hello

I wonder why this code below makes a Seg. Fault, after playing one
period of PCM samples, when I comment infinite while loop ?

while (1) {
make_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);
}
break; /* skip one period */
}
ptr += err;
cptr -= err;
}

}

This is a part of example from: http://www.alsa-project.org/alsa-doc...c-example.html
(functions make_sine and xrun_recovery was taken from there).

All I want to do is to play only one period of sine sound, than change
sine frequency and play again the sound (in real time). I need it for
AFSK (http://en.wikipedia.org/wiki/AFSK) modulation, so if anyone can
explain to me why this code make seg. fault I will be grateful.

Ign.