+ snd_pcm_hw_params_set_channels (dev_ctx_a[num]->dev, dev_ctx_a[num]->params, channels);
+}
+
+ /* ---- LOCAL THREADED FUNCTIONS ---- */
+
+void* _alsa_play_thread_fn (void *ctx) {
+
+ dev_ctx_alsa_T *dev_ctx_a = (dev_ctx_alsa_T *)ctx;
+ FILE *file = NULL;
+ char *buf = NULL;
+ long size;
+ int frames, res;
+
+ file = fopen (AUDIO_BUFFER, "rb");
+
+ while (dev_ctx_a->thr_should_run && file && (access (AUDIO_BUFFER, F_OK) != -1) ) {
+ fseek (file, 0, SEEK_END);
+ size = ftell (file);
+ buf = (char*) realloc (buf, size * sizeof(char));
+ frames = (size * sizeof(char)) / 4;
+
+ fseek (file, 0, SEEK_SET);
+ fread (buf, 1, size, file);
+ fflush (file);
+
+ if ((res = snd_pcm_writei (dev_ctx_a->dev, buf, frames)) != frames) {
+ snd_pcm_recover (dev_ctx_a->dev, res, 0);
+ snd_pcm_prepare (dev_ctx_a->dev);
+ }
+ /* snd_pcm_drain (dev_ctx->dev); */
+ }
+ if (buf) free(buf);
+ if (file) fclose(file);
+
+ dev_ctx_a->thr_finished = 1;
+ return 0;