+/* ------ BACKEND FUNCTIONS ------- */
+
+void _backend_init (const char *name, audioCtxHandleT *ctx) {
+
+ char *backend_env = getenv ("AFB_AUDIO_OUTPUT");
+ unsigned char res = -1;
+
+# ifdef HAVE_PULSE
+ if (!backend_env || (strcasecmp (backend_env, "Alsa") != 0))
+ res = _pulse_init (name, ctx);
+ if (res < 0)
+#endif
+ res = _alsa_init (name, ctx);
+
+ if (res < 0 && verbose)
+ fprintf (stderr, "Could not initialize Audio backend\n");
+}
+
+void _backend_free (audioCtxHandleT *ctx) {
+
+# ifdef HAVE_PULSE
+ if (ctx->audio_dev) _pulse_free (ctx); else
+# endif
+ _alsa_free (ctx->idx);
+}
+
+void _backend_play (audioCtxHandleT *ctx) {
+
+# ifdef HAVE_PULSE
+ if (ctx->audio_dev) _pulse_play (ctx); else
+# endif
+ _alsa_play (ctx->idx);
+}
+
+void _backend_stop (audioCtxHandleT *ctx) {
+
+# ifdef HAVE_PULSE
+ if (ctx->audio_dev) _pulse_stop (ctx); else
+# endif
+ _alsa_stop (ctx->idx);
+}
+
+int _backend_get_volume (audioCtxHandleT *ctx, unsigned int channel) {
+
+# ifdef HAVE_PULSE
+ if (ctx->audio_dev) return _pulse_get_volume (ctx, channel); else
+# endif
+ return _alsa_get_volume (ctx->idx, channel);
+}
+
+void _backend_set_volume (audioCtxHandleT *ctx, unsigned int channel, int vol) {
+
+# ifdef HAVE_PULSE
+ if (ctx->audio_dev) _pulse_set_volume (ctx, channel, vol); else
+# endif
+ _alsa_set_volume (ctx->idx, channel, vol);
+}
+
+void _backend_set_volume_all (audioCtxHandleT *ctx, int vol) {
+
+# ifdef HAVE_PULSE
+ if (ctx->audio_dev) _pulse_set_volume_all (ctx, vol); else
+# endif
+ _alsa_set_volume_all (ctx->idx, vol);
+}
+
+unsigned char _backend_get_mute (audioCtxHandleT *ctx) {
+
+# ifdef HAVE_PULSE
+ if (ctx->audio_dev) return _pulse_get_mute (ctx); else
+# endif
+ return _alsa_get_mute (ctx->idx);
+}
+
+void _backend_set_mute (audioCtxHandleT *ctx, unsigned char mute) {
+
+# ifdef HAVE_PULSE
+ if (ctx->audio_dev) _pulse_set_mute (ctx, mute); else
+# endif
+ _alsa_set_mute (ctx->idx, mute);
+}
+
+void _backend_set_channels (audioCtxHandleT *ctx, unsigned int channels) {
+
+# ifdef HAVE_PULSE
+ if (ctx->audio_dev) return; else
+# endif
+ _alsa_set_channels (ctx->idx, channels);
+}