+ snd_mixer_selem_set_playback_volume_all (dev_ctx_a[num]->mixer_elm, (vol*dev_ctx_a[num]->vol_max)/100);
+}
+
+PUBLIC unsigned char _alsa_get_mute (unsigned int num) {
+
+ int mute = 0;
+ snd_mixer_elem_t *elm_m;
+
+ if (!dev_ctx_a || !dev_ctx_a[num] || !dev_ctx_a[num]->mixer_elm)
+ return;
+
+ dev_ctx_a[num]->mixer_elm_m ? (elm_m = dev_ctx_a[num]->mixer_elm_m) :
+ (elm_m = dev_ctx_a[num]->mixer_elm);
+
+ if (snd_mixer_selem_has_playback_switch (elm_m)) {
+ snd_mixer_selem_get_playback_switch (elm_m, SND_MIXER_SCHN_FRONT_LEFT, &mute);
+ snd_mixer_selem_get_playback_switch (elm_m, SND_MIXER_SCHN_FRONT_RIGHT, &mute);
+ }
+
+ if (dev_ctx_a[num]->mixer_elm_m)
+ return (unsigned char)mute;
+ else
+ return (unsigned char)!mute;
+}
+
+PUBLIC void _alsa_set_mute (unsigned int num, unsigned char tomute) {
+
+ snd_mixer_elem_t *elm_m;
+ int mute;
+
+ if (!dev_ctx_a || !dev_ctx_a[num] || !dev_ctx_a[num]->mixer_elm || 1 < tomute < 0)
+ return;
+
+ if (dev_ctx_a[num]->mixer_elm_m) {
+ elm_m = dev_ctx_a[num]->mixer_elm_m;
+ mute = (int)!tomute;
+ } else {
+ elm_m = dev_ctx_a[num]->mixer_elm;
+ mute = (int)tomute;
+ }
+
+ if (snd_mixer_selem_has_playback_switch (elm_m))
+ snd_mixer_selem_set_playback_switch_all (elm_m, !mute);
+}
+
+PUBLIC void _alsa_set_rate (unsigned 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 (unsigned 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); */