improved detection of erros due to removed sound card
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 11 Nov 2012 21:58:29 +0000 (21:58 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 11 Nov 2012 21:58:29 +0000 (21:58 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@958 01035d8c-6547-0410-b346-abe4f91aad63

fdmdv2/src/dlg_audiooptions.cpp
fdmdv2/src/fdmdv2_main.cpp
fdmdv2/src/fdmdv2_main.h

index c5d65b49aa1658cda7b089eae201035320aa9c79..01b4d5ca6bb891dd317763d7ee3e65a3a8979fba 100644 (file)
@@ -297,7 +297,12 @@ void AudioOptsDialog::OnInitDialog( wxInitDialogEvent& event )
 
 int AudioOptsDialog::setTextCtrlIfDevNumValid(wxTextCtrl *textCtrl, wxListCtrl *listCtrl, int devNum)
 {
-    if (devNum > listCtrl->GetItemCount()) {
+    // listCtrl->GetItemCount() will be one more than the number of
+    // sound devices as "none" is at the end of the list.  This test
+    // traps if a sound device devNum no longer exists.
+    
+    int maxDevNum = listCtrl->GetItemCount() - 2;
+    if (devNum > maxDevNum) {
         textCtrl->SetValue("none");
         return -1;
     }
index 44225212f1089c586768d8387ae61316defa7d16..06db53f109db38cb47763730711cbe43777d1e1f 100644 (file)
@@ -1145,20 +1145,13 @@ void MainFrame::autoDetectSoundCards(PortAudioWrap *pa)
     }
 }
 
-int MainFrame::initPortAudioDevice(PortAudioWrap *pa, int inDevice, int outDevice, int soundCard, int sampleRate)
+void  MainFrame::initPortAudioDevice(PortAudioWrap *pa, int inDevice, int outDevice, int soundCard, int sampleRate)
 {
-    char s[256];
+    char    s[256];
 
-    if (inDevice == paNoDevice) {
-        sprintf(s,"No input audio device available for Sound Card %d", soundCard);
-        wxString wxs(s);
-        wxMessageBox(wxs, wxT("Error"), wxOK);
-    }
-    if (outDevice == paNoDevice) {
-        sprintf(s,"No output audio device available for Sound Card %d", soundCard);
-        wxString wxs(s);
-        wxMessageBox(wxs, wxT("Error"), wxOK);
-    }
+    // Note all of the wrapper functions below just set values in a
+    // portaudio struct so can't return any errors. So no need to trap
+    // any errors in this function.
 
     // init input params
 
@@ -1188,8 +1181,6 @@ int MainFrame::initPortAudioDevice(PortAudioWrap *pa, int inDevice, int outDevic
     pa->setFramesPerBuffer(PA_FPB);
     pa->setSampleRate(sampleRate);
     pa->setStreamFlags(0);
-
-    return 0;
 }
 
 //-------------------------------------------------------------------------
@@ -1212,8 +1203,7 @@ void MainFrame::startRxStream()
         }
 
         m_rxPa = new PortAudioWrap();
-        //autoDetectSoundCards(m_rxPa);
-
         if (g_nSoundCards == 0) {
             wxMessageBox(wxT("No Sound Cards configured, use Tools - Audio Config to configure"), wxT("Error"), wxOK);
             delete m_rxPa;
@@ -1223,29 +1213,17 @@ void MainFrame::startRxStream()
                 
         // Init Sound card 1 ----------------------------------------------
 
-        assert((g_soundCard1InDeviceNum != -1) && (g_soundCard1OutDeviceNum != -1));
-
         // sanity check on sound card device numbers
 
-        printf("m_rxPa->getDeviceCount() %d\n", m_rxPa->getDeviceCount());
-
-        if ((m_rxPa->getDeviceCount() < g_soundCard1InDeviceNum) ||
-            (m_rxPa->getDeviceCount() < g_soundCard1OutDeviceNum)) {
+        if ((m_rxPa->getDeviceCount() <= g_soundCard1InDeviceNum) ||
+            (m_rxPa->getDeviceCount() <= g_soundCard1OutDeviceNum)) {
             wxMessageBox(wxT("Sound Card 1 not present"), wxT("Error"), wxOK);
             delete m_rxPa;
             m_RxRunning = false;
             return;
         }
 
-        m_rxDevIn = g_soundCard1InDeviceNum;
-        m_rxDevOut = g_soundCard1OutDeviceNum;
-
-        if (initPortAudioDevice(m_rxPa, m_rxDevIn, m_rxDevOut, 1, g_soundCard1SampleRate) != 0) {
-            wxMessageBox(wxT("Can't start Sound Card 1"), wxT("Error"), wxOK);
-            delete m_rxPa;
-            m_RxRunning = false;
-            return;
-        }
+        initPortAudioDevice(m_rxPa, g_soundCard1InDeviceNum, g_soundCard1OutDeviceNum, 1, g_soundCard1SampleRate);
 
         // Init Sound Card 2 ------------------------------------------------
 
@@ -1253,12 +1231,14 @@ void MainFrame::startRxStream()
 
             m_txPa = new PortAudioWrap();
 
-            assert((g_soundCard2InDeviceNum != -1) && (g_soundCard2OutDeviceNum != -1) );
-
             // sanity check on sound card device numbers
 
-            if ((m_txPa->getDeviceCount() < g_soundCard2InDeviceNum) ||
-                (m_txPa->getDeviceCount() < g_soundCard2OutDeviceNum)) {
+            //printf("m_txPa->getDeviceCount(): %d\n", m_txPa->getDeviceCount());
+            //printf("g_soundCard2InDeviceNum: %d\n", g_soundCard2InDeviceNum);
+            //printf("g_soundCard2OutDeviceNum: %d\n", g_soundCard2OutDeviceNum);
+
+            if ((m_txPa->getDeviceCount() <= g_soundCard2InDeviceNum) ||
+                (m_txPa->getDeviceCount() <= g_soundCard2OutDeviceNum)) {
                 wxMessageBox(wxT("Sound Card 2 not present"), wxT("Error"), wxOK);
                 delete m_rxPa;
                 delete m_txPa;
@@ -1266,16 +1246,8 @@ void MainFrame::startRxStream()
                 return;
             }
 
-            m_txDevIn = g_soundCard2InDeviceNum;
-            m_txDevOut = g_soundCard2OutDeviceNum;
 
-            if (initPortAudioDevice(m_txPa, m_txDevIn, m_txDevOut, 2, g_soundCard2SampleRate) != 0) {
-                wxMessageBox(wxT("Can't start Sound Card 2"), wxT("Error"), wxOK);
-                delete m_rxPa;
-                delete m_txPa;
-                m_RxRunning = false;
-                return;
-            }
+            initPortAudioDevice(m_txPa, g_soundCard2InDeviceNum, g_soundCard2OutDeviceNum, 2, g_soundCard2SampleRate);
         }
 
         // Init call back data structure ----------------------------------------------
@@ -1359,8 +1331,7 @@ void MainFrame::startRxStream()
         // Start sound card 2 ----------------------------------------------------------
 
         if (g_nSoundCards == 2) {
-            printf("starting sound card 2...\n");
-
             // question: can we use same callback data
             // (m_rxUserdata)or both sound card callbacks?  Is there a
             // chance of them both being called at the same time?  We
index 7c543df3a25a6543d4d04788a65fb5e3126a71be..64edc46cb04896c028d70827e4f3ba0ef2cc5a70 100644 (file)
@@ -192,11 +192,6 @@ class MainFrame : public TopFrame
         PortAudioWrap           *m_rxPa;
         PortAudioWrap           *m_txPa;
         paCallBackData          *m_rxUserdata;
-        paCallBackData          *m_txUserdata;
-        PaDeviceIndex           m_rxDevIn;
-        PaDeviceIndex           m_rxDevOut;
-        PaDeviceIndex           m_txDevIn;
-        PaDeviceIndex           m_txDevOut;
         PaError                 m_rxErr;
         PaError                 m_txErr;
 #ifdef _USE_TIMER
@@ -240,7 +235,7 @@ class MainFrame : public TopFrame
                                             CODEC2  *c2              // Codec 2 states
                         );
 
-    int initPortAudioDevice(PortAudioWrap *pa, int inDevice, int outDevice, int soundCard, int sampleRate);
+    void initPortAudioDevice(PortAudioWrap *pa, int inDevice, int outDevice, int soundCard, int sampleRate);
 
  protected:
         // protected event handlers