void *mixer_thread(void *data) { int err; ubyte buffer[SOUND_BUFFER_SIZE]; /* Allow ourselves to be asynchronously cancelled */ pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); while (1) { memset(buffer, 0x80, SOUND_BUFFER_SIZE); LOCK(); audio_mixcallback(NULL,buffer,SOUND_BUFFER_SIZE); UNLOCK(); again: err = snd_pcm_writei(snd_devhandle, buffer, SOUND_BUFFER_SIZE/2); if (err == -EPIPE) { // Sound buffer underrun err = snd_pcm_prepare(snd_devhandle); if (err < 0) { con_printf(CON_CRITICAL, "Can't recover from underrun: %s\n", snd_strerror(err)); } } else if (err == -EAGAIN) { goto again; } else if (err != SOUND_BUFFER_SIZE/2) { // Each frame has size 2 bytes - hence we expect SOUND_BUFFER_SIZE/2 // frames to be written. con_printf(CON_CRITICAL, "Unknown err %d: %s\n", err, snd_strerror(err)); } } return 0; }
/* Initialise audio devices. */ int digi_init() { /* this is just here now to stop gcc from complaining about * audio_mixcallback being declared static and not used... */ if (0) audio_mixcallback(NULL,NULL,0); return 1; }