func ptr based callback functions from plugin to main() working OK, first pass at...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 6 Feb 2016 03:33:24 +0000 (03:33 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 6 Feb 2016 03:33:24 +0000 (03:33 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2685 01035d8c-6547-0410-b346-abe4f91aad63

freedv-dev/src/afreedvplugin.c
freedv-dev/src/fdmdv2_main.cpp
freedv-dev/src/fdmdv2_main.h

index fbb0a379bc2fa60e9ae7fff616c3078d3c29b92f..d7cbad8d53959a71fab6babc45cfbb3918e9f1a9 100644 (file)
@@ -37,14 +37,17 @@ int plugin_alert(char string[]);
 int plugin_get_persistant(char name[], char value[]);
 int plugin_set_persistant(char name[], char value[]);
 #endif
+static int (*plugin_get_persistant)(char name[], char value[]);
 
 struct APLUGIN_STATES {
+    int symbol_rate;
     int counter;
 };
 
 /* plugin functions called by host, we need to write these */
 
 void DLL plugin_name(char name[]) {
+
     sprintf(name, "aFreeDVplugIn");
 }
 
@@ -54,20 +57,31 @@ void DLL plugin_name(char name[]) {
    storage as name/param_names[0], name/param_names[1] ....
 */
 
-void DLL *plugin_open(char *param_names[], int *nparams) {
+void DLL *plugin_open(char *param_names[], 
+                      int *nparams, 
+                      int (*aplugin_get_persistant)(char *, char *))
+{
     struct APLUGIN_STATES *states;
 
+    /* set up function ptrs */
+
+    plugin_get_persistant = aplugin_get_persistant;
+    /* tell host how many persistent parameters we have and their names */
+
     strcpy(param_names[0], "SymbolRate");
     strcpy(param_names[1], "NumTones");
     *nparams = 2;
 
+    /* init local states */
+
     states = (struct APLUGIN_STATES *)malloc(sizeof(struct APLUGIN_STATES));
     if (states == NULL) {
         // TODO: plugin_alert("Problem starting plugin!");
         return NULL;
     }
     states->counter = 0;
-
+    
     return (void*)states;
 }
 
@@ -75,7 +89,12 @@ void DLL plugin_close(void *states) {
     free(states);
 }
 
-void DLL plugin_start(void *states) {
+void DLL plugin_start(void *s) {
+    struct APLUGIN_STATES *states = (struct APLUGIN_STATES*)s;
+    char txt[80];
+
+    (plugin_get_persistant)("SymbolRate",txt);
+    states->symbol_rate = atoi(txt);
 }
 
 void DLL plugin_stop(void *states) {
index 50f48a47ec0137b3191648cb63e937f1a1cad162..4097ce722b0c380ac17a6832e339b22003805dfb 100644 (file)
@@ -182,14 +182,16 @@ bool MainApp::OnInit()
         // lets get some information abt the plugIn
 
         void (*plugin_namefp)(char s[]);
-        void *(*plugin_openfp)(char *param_names[], int *nparams);
+        void *(*plugin_openfp)(char *param_names[], int *nparams, int (*aplugin_get_persistant)(char *, char *));
 
         #ifdef __WXMSW__
         plugin_namefp = (void (*)(char*))GetProcAddress((HMODULE)m_plugInHandle, "plugin_name");
         plugin_openfp = (void* (*)(char**,int *))GetProcAddress((HMODULE)m_plugInHandle, "plugin_open");
+        m_plugin_startfp = (void (*)(void *))GetProcAddress((HMODULE)m_plugInHandle, "plugin_start");
         #else
         plugin_namefp = (void (*)(char*))dlsym(m_plugInHandle, "plugin_name");
-        plugin_openfp = (void* (*)(char**,int *))dlsym(m_plugInHandle, "plugin_open");
+        plugin_openfp = (void* (*)(char**,int *, int (*)(char *, char *)))dlsym(m_plugInHandle, "plugin_open");
+        m_plugin_startfp = (void (*)(void *))dlsym(m_plugInHandle, "plugin_start");
         #endif
         
         if ((plugin_namefp != NULL) && (plugin_openfp != NULL)) {
@@ -203,13 +205,14 @@ bool MainApp::OnInit()
             char param_name1[80], param_name2[80];
             char *param_names[2] = {param_name1, param_name2};
             int  nparams, i;
-            m_plugInStates = (plugin_openfp)(param_names, &nparams);
+            m_plugInStates = (plugin_openfp)(param_names, &nparams, plugin_get_persistant);
             m_numPlugInParam = nparams;
             for(i=0; i<nparams; i++) {
-                fprintf(stderr, "  plugin param name[%d]: %s\n", i, param_names[i]);
                 m_plugInParamName[i] = param_names[i];
                 wxString configStr = "/" + m_plugInName + "/" + m_plugInParamName[i];
                 m_txtPlugInParam[i] = pConfig->Read(configStr, wxT(""));
+                //fprintf(stderr, "  plugin param name[%d]: %s\n", i, param_names[i]);
+                fprintf(stderr, "  plugin param name[%d]: %s values: %s\n", i, m_plugInParamName[i].mb_str().data(), m_txtPlugInParam[i].mb_str().data());
             }
         }
         
@@ -2325,6 +2328,8 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event)
 
         m_rb1600->Disable();
         m_rb700b->Disable();
+        if (m_rbPlugIn)
+            m_rbPlugIn->Disable();
 
         // determine what mode we are using
 
@@ -2338,41 +2343,55 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event)
             g_Nc = 14;
             m_panelScatter->setNc(g_Nc/2-1);  /* due to diversity, -1 due to no pilot like FreeDV 1600 */
         }
-   
-        // init freedv states
+        if (m_rbPlugIn->GetValue()) {
+            g_mode = -1;
 
-        g_pfreedv = freedv_open(g_mode);
-        freedv_set_callback_txt(g_pfreedv, &my_put_next_rx_char, &my_get_next_tx_char, NULL);
+            /* scale plots assuming Fs = 8000 Hz for now */
 
-        freedv_set_callback_error_pattern(g_pfreedv, my_freedv_put_error_pattern, (void*)m_panelTestFrameErrors);
-        g_error_pattern_fifo = fifo_create(2*freedv_get_sz_error_pattern(g_pfreedv));
-        g_error_hist = new short[FDMDV_NC_MAX*2];
-        int i;
-        for(i=0; i<2*FDMDV_NC_MAX; i++)
-            g_error_hist[i] = 0;
+            m_panelSpectrum->setFreqScale(MODEM_STATS_NSPEC*((float)MAX_F_HZ)/8000.0);
+            m_panelWaterfall->setFs(8000.0);
 
-        assert(g_pfreedv != NULL);
-        modem_stats_open(&g_stats);
+            (wxGetApp().m_plugin_startfp)(wxGetApp().m_plugInStates);
+        }
 
-        // Init Speex pre-processor states
-        // by inspecting Speex source it seems that only denoiser is on be default
+        if (g_mode != -1) { 
+            // init freedv states
 
-        g_speex_st = speex_preprocess_state_init(freedv_get_n_speech_samples(g_pfreedv), FS); 
+            g_pfreedv = freedv_open(g_mode);
+            freedv_set_callback_txt(g_pfreedv, &my_put_next_rx_char, &my_get_next_tx_char, NULL);
 
-        // adjust spectrum and waterfall freq scaling base on mode
+            freedv_set_callback_error_pattern(g_pfreedv, my_freedv_put_error_pattern, (void*)m_panelTestFrameErrors);
+            g_error_pattern_fifo = fifo_create(2*freedv_get_sz_error_pattern(g_pfreedv));
+            g_error_hist = new short[FDMDV_NC_MAX*2];
+            int i;
+            for(i=0; i<2*FDMDV_NC_MAX; i++)
+                g_error_hist[i] = 0;
 
-        m_panelSpectrum->setFreqScale(MODEM_STATS_NSPEC*((float)MAX_F_HZ/(freedv_get_modem_sample_rate(g_pfreedv)/2)));
-        m_panelWaterfall->setFs(freedv_get_modem_sample_rate(g_pfreedv));
+            assert(g_pfreedv != NULL);
+            modem_stats_open(&g_stats);
+
+            // init Codec 2 LPC Post Filter
+
+            codec2_set_lpc_post_filter(freedv_get_codec2(g_pfreedv),
+                                       wxGetApp().m_codec2LPCPostFilterEnable,
+                                       wxGetApp().m_codec2LPCPostFilterBassBoost,
+                                       wxGetApp().m_codec2LPCPostFilterBeta,
+                                       wxGetApp().m_codec2LPCPostFilterGamma);
+
+            // Init Speex pre-processor states
+            // by inspecting Speex source it seems that only denoiser is on be default
+
+            g_speex_st = speex_preprocess_state_init(freedv_get_n_speech_samples(g_pfreedv), FS); 
+
+            // adjust spectrum and waterfall freq scaling base on mode
 
-        // adjust scatter diagram for Number of FDM carriers
+            m_panelSpectrum->setFreqScale(MODEM_STATS_NSPEC*((float)MAX_F_HZ/(freedv_get_modem_sample_rate(g_pfreedv)/2)));
+            m_panelWaterfall->setFs(freedv_get_modem_sample_rate(g_pfreedv));
 
-        // init Codec 2 LPC Post Filter
+            // Init text msg decoding
 
-        codec2_set_lpc_post_filter(freedv_get_codec2(g_pfreedv),
-                                   wxGetApp().m_codec2LPCPostFilterEnable,
-                                   wxGetApp().m_codec2LPCPostFilterBassBoost,
-                                   wxGetApp().m_codec2LPCPostFilterBeta,
-                                   wxGetApp().m_codec2LPCPostFilterGamma);
+            freedv_set_varicode_code_num(g_pfreedv, wxGetApp().m_textEncoding);
+        }
 
         g_State = 0;
         g_snr = 0.0;
@@ -2391,9 +2410,6 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event)
         m_textLevel->SetLabel(wxT(""));
         m_gaugeLevel->SetValue(0);
 
-        // Init text msg decoding
-
-        freedv_set_varicode_code_num(g_pfreedv, wxGetApp().m_textEncoding);
         //printf("m_textEncoding = %d\n", wxGetApp().m_textEncoding);
         //printf("g_stats.snr: %f\n", g_stats.snr_est);
 
@@ -2452,11 +2468,14 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event)
 
         // free up states
 
-        modem_stats_close(&g_stats);
-        delete g_error_hist;
-        fifo_destroy(g_error_pattern_fifo);
-        freedv_close(g_pfreedv);
-        speex_preprocess_state_destroy(g_speex_st);
+        if (g_mode == -1) {
+            modem_stats_close(&g_stats);
+            delete g_error_hist;
+            fifo_destroy(g_error_pattern_fifo);
+            freedv_close(g_pfreedv);
+            speex_preprocess_state_destroy(g_speex_st);
+        }
+
         m_newMicInFilter = m_newSpkOutFilter = true;
 
         m_togBtnSplit->Disable();
@@ -2468,6 +2487,9 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event)
         m_togBtnOnOff->SetLabel(wxT("Start"));
         m_rb1600->Enable();
         m_rb700b->Enable();
+        if (m_rbPlugIn)
+            m_rbPlugIn->Enable();
+           
 #ifdef DISABLED_FEATURE
         m_rb700->Enable();
         m_rb1400old->Enable();
@@ -3930,3 +3952,11 @@ void freq_shift_coh(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, float Fs, CO
     foff_phase_rect->real /= mag;       
     foff_phase_rect->imag /= mag;       
 }
+
+int plugin_get_persistant(char name[], char value[]) {
+    wxString s = wxGetApp().m_txtPlugInParam[0];
+    strcpy(value, s.mb_str().data());
+    fprintf(stderr, "plugin_get_persistant called name: %s value: %s\n", name, s.mb_str().data());
+    return 0;
+}
+
index aedcf7838d2e70c563f89731296caf48cdc12c2e..3553b4934b97ced9c8dddadd7a1f587bee1f30eb 100644 (file)
@@ -282,6 +282,7 @@ class MainApp : public wxApp
         int        m_numPlugInParam;
         wxString   m_plugInParamName[PLUGIN_MAX_PARAMS];
         void      *m_plugInStates;
+        void     (*m_plugin_startfp)(void *);
 
         // misc
 
@@ -668,4 +669,8 @@ void my_put_next_rx_char(void *callback_state, char c);
 
 void freq_shift_coh(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, float Fs, COMP *foff_phase_rect, int nin);
 
+// Helper function called by plugin
+
+int plugin_get_persistant(char name[], char value[]);
+
 #endif //__FDMDV2_MAIN__