+static size_t alsa_play(void *buffer, size_t samples, unsigned flags) {
+ /* If we're paused we just pretend. We rely on snd_pcm_writei() blocking so
+ * we have to fake up a sleep here. However it doesn't have to be all that
+ * accurate - in particular it's quite acceptable to greatly underestimate
+ * the required wait time. For 'lengthy' waits we do this by the blunt
+ * instrument of halving it. */
+ if(flags & UAUDIO_PAUSED) {
+ if(samples > 64)
+ samples /= 2;
+ const uint64_t ns = ((uint64_t)samples * 1000000000
+ / (uaudio_rate * uaudio_channels));
+ struct timespec ts[1];
+ ts->tv_sec = ns / 1000000000;
+ ts->tv_nsec = ns % 1000000000;
+ while(nanosleep(ts, ts) < 0 && errno == EINTR)
+ ;
+ return samples;
+ }