minimal changes.
authorwittend99 <wittend99@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 17 Oct 2012 12:53:44 +0000 (12:53 +0000)
committerwittend99 <wittend99@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 17 Oct 2012 12:53:44 +0000 (12:53 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@766 01035d8c-6547-0410-b346-abe4f91aad63

fdmdv2/src/fdmdv2_main.cpp

index 820046210dae1a0a85d119ace84a3b4a65715941..be7854968a7630fdcef46902d7913c779b724170 100644 (file)
@@ -763,7 +763,8 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event)
 {
     if((!m_RxRunning))
     {
-       printf("starting ...\n");
+        printf("starting ...\n");
+
         m_togBtnSplit->Enable();
         m_togRxID->Enable();
         m_togTxID->Enable();
@@ -775,17 +776,20 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event)
         g_pCodec2 = codec2_create(CODEC2_MODE_1400);
 
 #ifdef _USE_TIMER
-       // DR: disable this puppy for now as it's causing a lot of error messages
+        // DR: disable this puppy for now as it's causing a lot of error messages
         //m_plotTimer.Start(500, wxTIMER_CONTINUOUS);
 #endif // _USE_TIMER
         startRxStream();
 //        startTxStream();
         if (m_RxRunning)
-           m_togBtnOnOff->SetLabel(wxT("Stop"));
+        {
+            m_togBtnOnOff->SetLabel(wxT("Stop"));
+        }
     }
     else
     {
-       printf("stopping ...\n");
+        printf("stopping ...\n");
+
         m_togBtnSplit->Disable();
         m_togRxID->Disable();
         m_togTxID->Disable();
@@ -879,9 +883,9 @@ void MainFrame::startRxStream()
         if(m_rxDevIn == paNoDevice)
         {
             wxMessageBox(wxT("Rx Error: No default input device."), wxT("Error"), wxOK);
-           delete m_rxPa;
-           m_RxRunning = false;
-           return;
+            delete m_rxPa;
+            m_RxRunning = false;
+            return;
         }
         m_rxErr = m_rxPa->setInputDevice(m_rxDevIn);
         m_rxErr = m_rxPa->setInputChannelCount(2);                          // stereo input
@@ -893,8 +897,8 @@ void MainFrame::startRxStream()
         if (m_rxDevOut == paNoDevice)
         {
             wxMessageBox(wxT("Rx Error: No default output device."), wxT("Error"), wxOK);
-           delete m_rxPa;
-           m_RxRunning = false;
+            delete m_rxPa;
+            m_RxRunning = false;
             return;
         }
         m_rxErr = m_rxPa->setOutputDevice(m_rxDevOut);
@@ -904,7 +908,8 @@ void MainFrame::startRxStream()
         m_rxErr = m_rxPa->setOutputLatency(m_rxPa->getOutputDefaultLowLatency());
         m_rxPa->setOutputHostApiStreamInfo(NULL);
 
-       m_rxErr = m_rxPa->setFramesPerBuffer(PA_FPB);
+        m_rxErr = m_rxPa->setFramesPerBuffer(PA_FPB);
+
         m_rxErr = m_rxPa->setSampleRate(SAMPLE_RATE);
         m_rxErr = m_rxPa->setStreamFlags(0);
 
@@ -921,8 +926,8 @@ void MainFrame::startRxStream()
             m_rxUserdata->in48k[i] = 0.0;
         }
 
-       m_rxUserdata->infifo = fifo_create(2*N48);
-       m_rxUserdata->outfifo = fifo_create(2*N48);
+        m_rxUserdata->infifo = fifo_create(2*N48);
+        m_rxUserdata->outfifo = fifo_create(2*N48);
 
         m_rxPa->setUserData(m_rxUserdata);
         m_rxErr = m_rxPa->setCallback(rxCallback);
@@ -931,19 +936,19 @@ void MainFrame::startRxStream()
         if(m_rxErr != paNoError)
         {
             wxMessageBox(wxT("Rx Stream Open/Setup error."), wxT("Error"), wxOK);
-           delete m_rxPa;
-           fifo_destroy(m_rxUserdata->infifo);
-           fifo_destroy(m_rxUserdata->outfifo);
-           return;
+            delete m_rxPa;
+            fifo_destroy(m_rxUserdata->infifo);
+            fifo_destroy(m_rxUserdata->outfifo);
+            return;
         }
         m_rxErr = m_rxPa->streamStart();
         if(m_rxErr != paNoError)
         {
             wxMessageBox(wxT("Rx Stream Start Error."), wxT("Error"), wxOK);
-           delete m_rxPa;
-           fifo_destroy(m_rxUserdata->infifo);
-           fifo_destroy(m_rxUserdata->outfifo);
-           return;
+            delete m_rxPa;
+            fifo_destroy(m_rxUserdata->infifo);
+            fifo_destroy(m_rxUserdata->outfifo);
+            return;
         }
     }
 }
@@ -961,8 +966,8 @@ void MainFrame::stopRxStream()
         fdmdv_destroy(g_pFDMDV);
         codec2_destroy(g_pCodec2);
 //        delete g_RxInBuf;
-       fifo_destroy(m_rxUserdata->infifo);
-       fifo_destroy(m_rxUserdata->outfifo);
+    fifo_destroy(m_rxUserdata->infifo);
+    fifo_destroy(m_rxUserdata->outfifo);
         delete m_rxUserdata;
     }
 /*
@@ -1154,103 +1159,105 @@ int MainFrame::rxCallback(
     /* assemble a mono buffer (just use left channel) and write to FIFO */
 
     assert(framesPerBuffer < MAX_FPB);
-    for(i=0; i<framesPerBuffer; i++,rptr+=2)
-       indata[i] = *rptr;
+    for(i = 0; i < framesPerBuffer; i++, rptr += 2)
+    {
+        indata[i] = *rptr;
+    }
     fifo_write(cbData->infifo, indata, framesPerBuffer);
 
     /* while we have enough samples available ... */
+    while (fifo_read(cbData->infifo, in48k_short, N48) == 0)
+    {
+        /* convert to float */
+
+        for(i=0; i<N48; i++)
+            in48k[FDMDV_OS_TAPS + i] = in48k_short[i];
+
+        // downsample and update filter memory
+        fdmdv_48_to_8(out8k, &in48k[FDMDV_OS_TAPS], N8);
+        for(i = 0; i < FDMDV_OS_TAPS; i++)
+        {
+            in48k[i] = in48k[i + N48];
+        }
 
-    while (fifo_read(cbData->infifo, in48k_short, N48) == 0) {
-
-       /* convert to float */
-
-       for(i=0; i<N48; i++)
-           in48k[FDMDV_OS_TAPS + i] = in48k_short[i];
-
-       // downsample and update filter memory
-       fdmdv_48_to_8(out8k, &in48k[FDMDV_OS_TAPS], N8);
-       for(i = 0; i < FDMDV_OS_TAPS; i++)
-       {
-           in48k[i] = in48k[i + N48];
-       }
-
-       assert((g_nInputBuf + N8) <= 2 * FDMDV_NOM_SAMPLES_PER_FRAME);
-       // run demod, decoder and update GUI info
-       for(i = 0; i < N8; i++)
-       {
-           g_RxInBuf[g_nInputBuf + i] = (short)out8k[i];
-       }
-       g_nInputBuf += FDMDV_NOM_SAMPLES_PER_FRAME;
-       per_frame_rx_processing(g_pRxOutBuf, &g_nOutputBuf, g_CodecBits, g_RxInBuf, &g_nInputBuf, &g_nRxIn, &g_State, g_pCodec2);
-       //cbData->pWFPanel->m_newdata = true;
-       //cbData->pSPPanel->m_newdata = true;
-
-       // if demod out of sync copy input audio from A/D to aid in tuning
-       if (g_nOutputBuf >= N8)
+        assert((g_nInputBuf + N8) <= 2 * FDMDV_NOM_SAMPLES_PER_FRAME);
+        // run demod, decoder and update GUI info
+        for(i = 0; i < N8; i++)
         {
-           if(g_State == 0)
+            g_RxInBuf[g_nInputBuf + i] = (short)out8k[i];
+        }
+        g_nInputBuf += FDMDV_NOM_SAMPLES_PER_FRAME;
+        per_frame_rx_processing(g_pRxOutBuf, &g_nOutputBuf, g_CodecBits, g_RxInBuf, &g_nInputBuf, &g_nRxIn, &g_State, g_pCodec2);
+        //cbData->pWFPanel->m_newdata = true;
+        //cbData->pSPPanel->m_newdata = true;
+
+        // if demod out of sync copy input audio from A/D to aid in tuning
+        if (g_nOutputBuf >= N8)
+        {
+            if(g_State == 0)
             {
-               for(i = 0; i < N8; i++)
+                for(i = 0; i < N8; i++)
                 {
-                   in8k[MEM8 + i] = out8k[i];       // A/D signal
-               }
-           }
-           else
-           {
-               for(i = 0; i < N8; i++)
+                    in8k[MEM8 + i] = out8k[i];       // A/D signal
+                }
+            }
+            else
+            {
+                for(i = 0; i < N8; i++)
                 {
-                   in8k[MEM8+i] = g_pRxOutBuf[i];   // decoded spech
-               }
-           }
-           g_nOutputBuf -= N8;
-       }
-       assert(g_nOutputBuf >= 0);
-       // shift speech samples in output buffer
-       for(i = 0; i < (unsigned int)g_nOutputBuf; i++)
+                    in8k[MEM8+i] = g_pRxOutBuf[i];   // decoded spech
+                }
+            }
+            g_nOutputBuf -= N8;
+        }
+        assert(g_nOutputBuf >= 0);
+        // shift speech samples in output buffer
+        for(i = 0; i < (unsigned int)g_nOutputBuf; i++)
         {
-           g_pRxOutBuf[i] = g_pRxOutBuf[i + N8];
-       }
+            g_pRxOutBuf[i] = g_pRxOutBuf[i + N8];
+        }
 
-       /* test: echo input to output, make this loopback option */
-       for(i=0; i<N8; i++)
-           in8k[MEM8+i] = out8k[i];
+        /* test: echo input to output, make this loopback option */
+        for(i=0; i<N8; i++)
+            in8k[MEM8+i] = out8k[i];
 
-       // Convert output speech to 48 kHz sample rate
-       // upsample and update filter memory
-       fdmdv_8_to_48(out48k, &in8k[MEM8], N8);
-       for(i = 0; i < MEM8; i++)
-        {
-           in8k[i] = in8k[i + N8];
-        }
-       assert(outputBuffer != NULL);
+        // Convert output speech to 48 kHz sample rate
+        // upsample and update filter memory
+        fdmdv_8_to_48(out48k, &in8k[MEM8], N8);
+        for(i = 0; i < MEM8; i++)
+            {
+            in8k[i] = in8k[i + N8];
+            }
+        assert(outputBuffer != NULL);
 
-       // write signal to fifo
-       for(i = 0; i < N48; i++)
-        {
-           out48k_short[i] = (short)out48k[i];
-       }
+        // write signal to fifo
+        for(i = 0; i < N48; i++)
+            {
+            out48k_short[i] = (short)out48k[i];
+        }
 
-       fifo_write(cbData->outfifo, out48k_short, N48);
+        fifo_write(cbData->outfifo, out48k_short, N48);
     }
 
     /* OK now set up output samples */
-
-    if (fifo_read(cbData->outfifo, outdata, framesPerBuffer) == 0) {
-
-       /* write signal to both channels */
-
-       for(i=0; i<framesPerBuffer; i++,wptr+=2) {
-           wptr[0] = outdata[i];
-           wptr[1] = outdata[i];
-       }
+    if (fifo_read(cbData->outfifo, outdata, framesPerBuffer) == 0)
+    {
+        /* write signal to both channels */
+        for(i=0; i<framesPerBuffer; i++,wptr+=2)
+        {
+            wptr[0] = outdata[i];
+            wptr[1] = outdata[i];
+        }
     }
-    else {
-       //printf("no data\n");
-       /* zero output if no data available */
-       for(i=0; i<framesPerBuffer; i++,wptr+=2) {
-           wptr[0] = 0;
-           wptr[1] = 0;
-       }
+    else
+    {
+        //printf("no data\n");
+        /* zero output if no data available */
+        for(i=0; i<framesPerBuffer; i++,wptr+=2)
+        {
+            wptr[0] = 0;
+            wptr[1] = 0;
+        }
     }
 
     return paContinue;
@@ -1479,43 +1486,3 @@ void MainFrame::OnSave(wxCommandEvent& WXUNUSED(event))
     }
 */
 }
-
-/*
-//-------------------------------------------------------------------------
-// rxCallback()
-//-------------------------------------------------------------------------
-int MainFrame::rxCallback(
-                            const void *inBuffer,
-                            void *outBuffer,
-                            unsigned long framesPerBuffer,
-                            const PaStreamCallbackTimeInfo *outTime,
-                            PaStreamCallbackFlags statusFlags,
-                            void *userData
-                        )
-{
-#ifdef _AUDIO_PASSTHROUGH
-    float *out = (float *) outBuffer;
-    float *in  = (float *) inBuffer;
-    float leftIn;
-    float rightIn;
-    unsigned int i;
-
-    if(inBuffer == NULL)
-    {
-        return 0;
-    }
-    // Read input buffer, process data, and fill output buffer.
-    for(i = 0; i < framesPerBuffer; i++)
-    {
-        leftIn  = *in++;                            // Get interleaved samples from input buffer.
-        rightIn = *in++;
-        *out++  = leftIn * rightIn;                 // ring modulation
-        *out++  = 0.5f * (leftIn + rightIn);        // mixing
-    }
-#else   // _AUDIO_PASSTHROUGH
-//    per_frame_rx_processing((short *) outBuffer, &framesPerBuffer, int codec_bits[], (short *) inBuffer, &framesPerBuffer, int *nin, int *state, m_rxPa);//
-//    per_frame_rx_processing(outBuffer, &framesPerBuffer, int codec_bits[], inBuffer, &framesPerBuffer, int *nin, int *state, m_rxPa);
-#endif  // _AUDIO_PASSTHROUGH
-    return paContinue;                              // 0;
-}
-*/