summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gr-vocoder/lib/freedv_tx_ss_impl.cc34
-rw-r--r--gr-vocoder/lib/freedv_tx_ss_impl.h16
2 files changed, 16 insertions, 34 deletions
diff --git a/gr-vocoder/lib/freedv_tx_ss_impl.cc b/gr-vocoder/lib/freedv_tx_ss_impl.cc
index 310a2137e6..1f3dadeb52 100644
--- a/gr-vocoder/lib/freedv_tx_ss_impl.cc
+++ b/gr-vocoder/lib/freedv_tx_ss_impl.cc
@@ -19,24 +19,6 @@
#include <iostream>
#include <stdexcept>
-extern "C" {
-char get_next_tx_char(void* callback_state)
-{
- char c;
- struct freedv_tx_callback_state* pstate;
-
- pstate = (struct freedv_tx_callback_state*)callback_state;
- c = *pstate->ptx_str++;
-
- if (*pstate->ptx_str == 0) {
- pstate->ptx_str = pstate->tx_str;
- c = 0x0d; // FreeDV uses Carriage Return termination
- }
-
- return c;
-}
-}
-
namespace gr {
namespace vocoder {
@@ -69,9 +51,8 @@ freedv_tx_ss_impl::freedv_tx_ss_impl(int mode,
if ((d_freedv = freedv_open(mode)) == NULL)
throw std::runtime_error("freedv_tx_ss_impl: freedv_open failed");
#endif
- snprintf(d_cb_state.tx_str, 79, "%s", d_msg_text.c_str());
- d_cb_state.ptx_str = d_cb_state.tx_str;
- freedv_set_callback_txt(d_freedv, NULL, get_next_tx_char, (void*)&d_cb_state);
+ d_tx_str = msg_txt + "\r"; // FreeDV uses Carriage Return termination
+ freedv_set_callback_txt(d_freedv, NULL, get_next_tx_char, this);
d_nom_modem_samples = freedv_get_n_nom_modem_samples(d_freedv);
set_output_multiple(d_nom_modem_samples);
}
@@ -124,5 +105,16 @@ int freedv_tx_ss_impl::work(int noutput_items,
return noutput_items;
}
+char freedv_tx_ss_impl::get_next_tx_char(void* callback_state)
+{
+ freedv_tx_ss_impl* instance = static_cast<freedv_tx_ss_impl*>(callback_state);
+ char c = instance->d_tx_str[instance->d_tx_str_offset++];
+
+ if (instance->d_tx_str_offset == instance->d_tx_str.length())
+ instance->d_tx_str_offset = 0;
+
+ return c;
+}
+
} /* namespace vocoder */
} /* namespace gr */
diff --git a/gr-vocoder/lib/freedv_tx_ss_impl.h b/gr-vocoder/lib/freedv_tx_ss_impl.h
index 31ed023eb7..f4f341b97e 100644
--- a/gr-vocoder/lib/freedv_tx_ss_impl.h
+++ b/gr-vocoder/lib/freedv_tx_ss_impl.h
@@ -13,18 +13,6 @@
#include <gnuradio/vocoder/freedv_tx_ss.h>
-extern "C" {
-struct freedv_tx_callback_state {
- char tx_str[80];
- char* ptx_str;
- int calls;
-};
-char get_next_tx_char(void* callback_state);
-void get_next_proto(void* callback_state, char* proto_bits);
-void datarx(void* callback_state, unsigned char* packet, size_t size);
-void datatx(void* callback_state, unsigned char* packet, size_t* size);
-}
-
namespace gr {
namespace vocoder {
@@ -33,7 +21,9 @@ class freedv_tx_ss_impl : public freedv_tx_ss
private:
short* d_speech_in;
short* d_mod_out;
- struct freedv_tx_callback_state d_cb_state;
+ std::string d_tx_str;
+ std::string::size_type d_tx_str_offset = 0;
+ static char get_next_tx_char(void* callback_state);
struct freedv* d_freedv;
int d_mode;
std::string d_msg_text;