+PUBLIC void _alsa_play (unsigned int num) {
+
+ if (!dev_ctx || !dev_ctx[num] || dev_ctx[num]->thr_should_run ||
+ access (AUDIO_BUFFER, F_OK) == -1)
+ return;
+
+ dev_ctx[num]->thr_should_run = 1;
+ dev_ctx[num]->thr_finished = 0;
+ pthread_create(&dev_ctx[num]->thr, NULL, _play_thread_fn, (void*)dev_ctx[num]);
+}
+
+PUBLIC void _alsa_stop (unsigned int num) {
+
+ if (!dev_ctx || !dev_ctx[num] || !dev_ctx[num]->thr_should_run)
+ return;
+
+ /* stop the "while" loop in thread */
+ dev_ctx[num]->thr_should_run = 0;
+
+ while (!dev_ctx[num]->thr_finished)
+ usleep(100000);
+
+ pthread_join(dev_ctx[num]->thr, NULL);
+}
+
+PUBLIC int _alsa_get_volume (unsigned int num, unsigned int channel) {
+
+ if (!dev_ctx || !dev_ctx[num] || !dev_ctx[num]->mixer_elm)
+ return;
+
+ snd_mixer_selem_get_playback_volume (dev_ctx[num]->mixer_elm, SCHANNELS[channel], &dev_ctx[num]->vol);
+
+ return (int)(dev_ctx[num]->vol*100)/dev_ctx[num]->vol_max;
+}
+
+PUBLIC void _alsa_set_volume (unsigned int num, unsigned int channel, int vol) {
+
+ if (!dev_ctx || !dev_ctx[num] || !dev_ctx[num]->mixer_elm ||
+ 0 > vol > 100)
+ return;
+
+ snd_mixer_selem_set_playback_volume (dev_ctx[num]->mixer_elm, SCHANNELS[channel], (vol*dev_ctx[num]->vol_max)/100);
+
+}
+
+PUBLIC void _alsa_set_volume_all (unsigned int num, int vol) {
+
+ if (!dev_ctx || !dev_ctx[num] || !dev_ctx[num]->mixer_elm ||
+ 0 > vol > 100)
+
+ snd_mixer_selem_set_playback_volume_all (dev_ctx[num]->mixer_elm, (vol*dev_ctx[num]->vol_max)/100);
+}
+
+PUBLIC unsigned char _alsa_get_mute (unsigned int num) {
+
+ int mute = 0;
+
+ if (!dev_ctx || !dev_ctx[num] || !dev_ctx[num]->mixer_elm)
+ return;
+
+ if (snd_mixer_selem_has_playback_switch (dev_ctx[num]->mixer_elm)) {
+ snd_mixer_selem_get_playback_switch (dev_ctx[num]->mixer_elm, SND_MIXER_SCHN_FRONT_LEFT, &mute);
+ snd_mixer_selem_get_playback_switch (dev_ctx[num]->mixer_elm, SND_MIXER_SCHN_FRONT_RIGHT, &mute);
+
+ }
+
+ return (unsigned char)!mute;
+}
+
+PUBLIC void _alsa_set_mute (unsigned int num, unsigned char mute) {
+
+ if (!dev_ctx || !dev_ctx[num] || !dev_ctx[num]->mixer_elm || 1 < mute < 0)
+ return;
+
+ if (snd_mixer_selem_has_playback_switch (dev_ctx[num]->mixer_elm))
+ snd_mixer_selem_set_playback_switch_all (dev_ctx[num]->mixer_elm, !mute);
+}
+
+PUBLIC void _alsa_set_rate (unsigned int num, unsigned int rate) {