adding audio fifo counters, but audio messed up
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 3 May 2018 01:43:15 +0000 (01:43 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 3 May 2018 01:43:15 +0000 (01:43 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3559 01035d8c-6547-0410-b346-abe4f91aad63

freedv-dev/src/fdmdv2_main.cpp
freedv-dev/src/topFrame.cpp
freedv-dev/src/topFrame.h

index d744622f3d04d5a7cc497c7f5464286748349790..7c937745aa0e501ad366110fe8f7fed95a523017 100644 (file)
@@ -90,6 +90,13 @@ int                 g_soundCard2InDeviceNum;
 int                 g_soundCard2OutDeviceNum;
 int                 g_soundCard2SampleRate;
 
+// PortAudio over/underflow counters
+
+int                 g_infifo1_full;
+int                 g_outfifo1_empty;
+int                 g_infifo2_full;
+int                 g_outfifo2_empty;
+
 // playing and recording from sound files
 
 SNDFILE            *g_sfPlayFile;
@@ -1245,6 +1252,13 @@ void MainFrame::OnTimer(wxTimerEvent &evt)
                 }
             }
         }
+
+        /* FIFO under/overflow debug counters */
+
+        char fifo_counters[80];
+        sprintf(fifo_counters, "%d %d %d %d", g_infifo1_full, g_outfifo1_empty, g_infifo2_full, g_outfifo2_empty);
+        //wxString fifo_counters_string(fifo_counters); m_textFifos->SetLabel(fifo_counters_string);
+
     }
 
     // command from UDP thread that is best processed in main thread to avoid seg faults
@@ -2768,8 +2782,9 @@ void MainFrame::startRxStream()
         g_rxUserdata->outfifo1 = fifo_create(10*N48);
         g_rxUserdata->outfifo2 = fifo_create(10*N48);
         g_rxUserdata->infifo2 = fifo_create(10*N48);
-        fprintf(stderr, "N48: %d 10*N48: %d\n", N48, 10*N48);
-
+        //fprintf(stderr, "N48: %d 10*N48: %d\n", N48, 10*N48);
+        g_infifo1_full = g_outfifo1_empty = g_infifo2_full = g_outfifo2_empty = 0;
+        
         /* TODO: might be able to tune these on a per waveform basis */
         
         g_rxUserdata->rxinfifo = fifo_create(20 * N8);
@@ -3668,6 +3683,7 @@ void per_frame_rx_processing(
 // + In dual sound card mode outfifo1 is the "to radio" modulator signal to the SSB tx.
 //
 //-------------------------------------------------------------------------
+
 int MainFrame::rxCallback(
                             const void      *inputBuffer,
                             void            *outputBuffer,
@@ -3691,9 +3707,6 @@ int MainFrame::rxCallback(
 
     wxMutexLocker lock(g_mutexProtectingCallbackData);
 
-    //fprintf(g_logfile, "cb1 statusFlags: 0x%x framesPerBuffer: %d rptr: 0x%x wptr: 0x%x \n", (int)statusFlags,
-    //        framesPerBuffer, rptr, wptr);
-
     //
     //  RX side processing --------------------------------------------
     //
@@ -3702,22 +3715,18 @@ int MainFrame::rxCallback(
 
     assert(framesPerBuffer < MAX_FPB);
 
-    if(rptr) {
-        //fprintf(g_logfile,"in %ld %d\n",  framesPerBuffer, g_in++);
-        //g_indata += framesPerBuffer;
+    if (rptr) {
         for(i = 0; i < framesPerBuffer; i++, rptr += cbData->inputChannels1)
             indata[i] = rptr[0];                       
         if (fifo_write(cbData->infifo1, indata, framesPerBuffer)) {
-            //fprintf(g_logfile, "infifo1 full\n");
+            g_infifo1_full++;
         }
-        //fifo_write(cbData->outfifo1, indata, framesPerBuffer);
     }
 
     // OK now set up output samples for this callback
 
-    if(wptr) {
-        //fprintf(g_logfile,"out %ld %d\n",  framesPerBuffer, g_out++);
-        if (fifo_read(cbData->outfifo1, outdata, framesPerBuffer) == 0) {
+    if (wptr) {
+         if (fifo_read(cbData->outfifo1, outdata, framesPerBuffer) == 0) {
 
             // write signal to both channels
 
@@ -3726,7 +3735,6 @@ int MainFrame::rxCallback(
                     cbData->voxTonePhase += 2.0*M_PI*VOX_TONE_FREQ/g_soundCard1SampleRate;
                     cbData->voxTonePhase -= 2.0*M_PI*floor(cbData->voxTonePhase/(2.0*M_PI));
                     wptr[0] = VOX_TONE_AMP*cos(cbData->voxTonePhase);                              
-                    //printf("%f %d\n", cbData->voxTonePhase, wptr[0]);
                 }
                 else
                     wptr[0] = outdata[i];
@@ -3735,7 +3743,7 @@ int MainFrame::rxCallback(
             }
         }
         else {
-            //fprintf(g_logfile, "outfifo1 empty\n");
+            g_outfifo1_empty++;
             // zero output if no data available
             for(i = 0; i < framesPerBuffer; i++, wptr += 2) {
                 wptr[0] = 0;
@@ -3769,39 +3777,21 @@ int MainFrame::txCallback(
 
     wxMutexLocker lock(g_mutexProtectingCallbackData);
 
-    //    if (statusFlags)
-    //    printf("cb2 statusFlags: 0x%x\n", (int)statusFlags);
-
     // assemble a mono buffer and write to FIFO
 
     assert(framesPerBuffer < MAX_FPB);
 
-    if(rptr) {
+    if (rptr) {
         for(i = 0; i < framesPerBuffer; i++, rptr += cbData->inputChannels2)
             indata[i] = rptr[0];                        
-    }
-
-    //#define SC2_LOOPBACK
-#ifdef SC2_LOOPBACK
-    //TODO: This doesn't work unless using the same soundcard!
-
-    if(wptr) {
-        for(i = 0; i < framesPerBuffer; i++, wptr += 2) {
-            wptr[0] = indata[i];
-            wptr[1] = indata[i];
-        }
-    }
-
-#else
-    if(rptr) {
         if (fifo_write(cbData->infifo2, indata, framesPerBuffer)) {
-            //fprintf(g_logfile, "infifo2 full\n");
+            g_infifo2_full++;
         }
     }
 
     // OK now set up output samples for this callback
 
-    if(wptr) {
+    if (wptr) {
         if (fifo_read(cbData->outfifo2, outdata, framesPerBuffer) == 0) {
                
             // write signal to both channels */
@@ -3811,7 +3801,7 @@ int MainFrame::txCallback(
             }
         }
         else {
-            //fprintf(g_logfile, "outfifo2 empty\n");
+            g_outfifo2_empty++;
             // zero output if no data available
             for(i = 0; i < framesPerBuffer; i++, wptr += 2) {
                 wptr[0] = 0;
@@ -3819,7 +3809,7 @@ int MainFrame::txCallback(
             }
         }
     }
-#endif
+    
     return paContinue;
 }
 
index d72513145699d9cdbe73f3e0b8263c04f851d33b..ff991f30567b12cfdbf6b4cdfaeb7ce2e01c2b24 100644 (file)
@@ -169,6 +169,9 @@ TopFrame::TopFrame(wxString plugInName, wxWindow* parent, wxWindowID id, const w
     m_textResyncs = new wxStaticText(this, wxID_ANY, wxT("Resyncs: 0"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
     sbSizer_ber->Add(m_textResyncs, 0, wxALIGN_LEFT, 1);
 
+    m_textFifos = new wxStaticText(this, wxID_ANY, wxT("0 0 0 0"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
+    sbSizer_ber->Add(m_textFifos, 0, wxALIGN_LEFT, 1);
+
     leftSizer->Add(sbSizer_ber,0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 3);
 
     //------------------------------
index fe97b0cc4943b939a7548f9ef75fbe7b12a512d8..c59e2dad052b721468e7d457e4c0f76db2e32e86 100644 (file)
@@ -103,6 +103,7 @@ class TopFrame : public wxFrame
         wxStaticText  *m_textErrors;
         wxStaticText  *m_textBER;
         wxStaticText  *m_textResyncs;
+        wxStaticText  *m_textFifos;
 
         wxRadioButton *m_rbSync;
         wxRadioButton *m_rb1400old;