+
+ if (snd_mixer_selem_has_playback_switch (elm_m))
+ snd_mixer_selem_set_playback_switch_all (elm_m, !mute);
+}
+
+PUBLIC void _alsa_set_rate (int num, unsigned int rate) {
+
+ if (!dev_ctx_a || !dev_ctx_a[num])
+ return;
+
+ snd_pcm_hw_params_set_rate_near (dev_ctx_a[num]->dev, dev_ctx_a[num]->params, &rate, 0);
+}
+
+PUBLIC void _alsa_set_channels (int num, unsigned int channels) {
+
+ if (!dev_ctx_a || !dev_ctx_a[num])
+ return;
+
+ snd_pcm_hw_params_set_channels (dev_ctx_a[num]->dev, dev_ctx_a[num]->params, channels);
+}
+
+ /* ---- LOCAL THREADED FUNCTIONS ---- */
+
+STATIC 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;
+}