Switch to side-by-side view

--- a/sc2src/alsadirect.cpp
+++ b/sc2src/alsadirect.cpp
@@ -62,7 +62,10 @@
    started */
 static bool qinit = false;
 
-static snd_pcm_t *pcm;
+static snd_pcm_t *pcm = nullptr;
+static string alsadevice("default");
+
+static bool alsa_init(const string& dev, AudioMessage *tsk);
 
 // From MPD recovery code
 static int alsa_recover(snd_pcm_t *pcm, int err)
@@ -138,6 +141,14 @@
             return (void*)1;
         }
 
+        if (pcm == nullptr) {
+            if (!alsa_init(alsadevice, tsk)) {
+                LOGERR("alsawriter: error alsa init\n");
+                alsaqueue.workerExit();
+                return (void*)1;
+            }
+        }
+
         snd_pcm_uframes_t frames = tsk->frames();
         char *buf = tsk->m_buf;
         // This loop is copied from the alsa sample, but it should not
@@ -302,18 +313,22 @@
 static void alsa_close()
 {
     LOGDEB("alsawriter: alsa close\n");
-    snd_pcm_close(pcm);
+    if (pcm != nullptr) {
+        snd_pcm_close(pcm);
+        pcm = nullptr;
+    }
 }
 
 // Current in-driver delay in samples
 static int alsadelay()
 {
     snd_pcm_sframes_t delay;
-    if (snd_pcm_delay(pcm, &delay) >= 0) {
-        return delay;
-    } else {
-        return 0;
-    }
+    if (pcm != nullptr) {
+        if (snd_pcm_delay(pcm, &delay) >= 0) {
+            return delay;
+        }
+    }
+    return 0;
 }
 
 class Filter {
@@ -680,7 +695,6 @@
     LOGDEB("audioEater: alsadirect. Will use converter type " << 
            cvt_type << endl);
 
-    string alsadevice("default");
     ctxt->config->get("scalsadevice", alsadevice);    
 
     WorkQueue<AudioMessage*> *queue = ctxt->queue;
@@ -716,9 +730,6 @@
 
         // 1st time: init. We don't want to do this before we have data.
         if (src_state == 0) {
-            if (!alsa_init(alsadevice, tsk)) {
-                goto done;
-            }
             if (cvt_type != -1) {
                 src_state = src_new(cvt_type, tsk->m_chans, &src_error);
             } else {