From 96836e7ff66aae4e7f4d1fbea6e65d433954912b Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 5 Mar 2019 01:23:25 +0100 Subject: [PATCH] libfreedv: use in FreeDV mod --- plugins/channelrx/demodfreedv/freedvdemod.cpp | 16 +++---- plugins/channeltx/modfreedv/CMakeLists.txt | 2 + plugins/channeltx/modfreedv/freedvmod.cpp | 48 +++++++++---------- plugins/channeltx/modfreedv/freedvmod.h | 5 +- 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/plugins/channelrx/demodfreedv/freedvdemod.cpp b/plugins/channelrx/demodfreedv/freedvdemod.cpp index b2c2a9506..797e50cf6 100644 --- a/plugins/channelrx/demodfreedv/freedvdemod.cpp +++ b/plugins/channelrx/demodfreedv/freedvdemod.cpp @@ -446,7 +446,7 @@ void FreeDVDemod::pushSampleToDV(int16_t sample) if (m_iModem == m_nin) { - int nout = freedv_rx(m_freeDV, m_speechOut, m_modIn); + int nout = FreeDV::freedv_rx(m_freeDV, m_speechOut, m_modIn); m_freeDVStats.collect(m_freeDV); m_freeDVSNR.accumulate(m_freeDVStats.m_snrEst); @@ -566,7 +566,7 @@ void FreeDVDemod::applyFreeDVMode(FreeDVDemodSettings::FreeDVMode mode) // FreeDV object if (m_freeDV) { - freedv_close(m_freeDV); + FreeDV::freedv_close(m_freeDV); } int fdv_mode = -1; @@ -595,7 +595,7 @@ void FreeDVDemod::applyFreeDVMode(FreeDVDemodSettings::FreeDVMode mode) { struct FreeDV::freedv_advanced adv; adv.interleave_frames = 1; - m_freeDV = freedv_open_advanced(fdv_mode, &adv); + m_freeDV = FreeDV::freedv_open_advanced(fdv_mode, &adv); } else { @@ -615,10 +615,10 @@ void FreeDVDemod::applyFreeDVMode(FreeDVDemodSettings::FreeDVMode mode) FreeDV::freedv_set_callback_protocol(m_freeDV, nullptr, nullptr, nullptr); FreeDV::freedv_set_callback_data(m_freeDV, nullptr, nullptr, nullptr); - int nSpeechSamples = freedv_get_n_speech_samples(m_freeDV); - int nMaxModemSamples = freedv_get_n_max_modem_samples(m_freeDV); - int Fs = freedv_get_modem_sample_rate(m_freeDV); - int Rs = freedv_get_modem_symbol_rate(m_freeDV); + int nSpeechSamples = FreeDV::freedv_get_n_speech_samples(m_freeDV); + int nMaxModemSamples = FreeDV::freedv_get_n_max_modem_samples(m_freeDV); + int Fs = FreeDV::freedv_get_modem_sample_rate(m_freeDV); + int Rs = FreeDV::freedv_get_modem_symbol_rate(m_freeDV); m_freeDVStats.init(); if (nSpeechSamples != m_nSpeechSamples) @@ -643,7 +643,7 @@ void FreeDVDemod::applyFreeDVMode(FreeDVDemodSettings::FreeDVMode mode) m_iSpeech = 0; m_iModem = 0; - m_nin = freedv_nin(m_freeDV); + m_nin = FreeDV::freedv_nin(m_freeDV); if (m_nin > 0) { m_freeDVStats.m_fps = m_modemSampleRate / m_nin; diff --git a/plugins/channeltx/modfreedv/CMakeLists.txt b/plugins/channeltx/modfreedv/CMakeLists.txt index f32208bbb..cec33ece3 100644 --- a/plugins/channeltx/modfreedv/CMakeLists.txt +++ b/plugins/channeltx/modfreedv/CMakeLists.txt @@ -24,6 +24,7 @@ include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client + ${CMAKE_SOURCE_DIR}/libfreedv ${CODEC2_INCLUDE_DIR} ) @@ -44,6 +45,7 @@ target_link_libraries(modfreedv sdrbase sdrgui swagger + freedv ${CODEC2_LIBRARIES} ) diff --git a/plugins/channeltx/modfreedv/freedvmod.cpp b/plugins/channeltx/modfreedv/freedvmod.cpp index dacafa678..3ac5e48ac 100644 --- a/plugins/channeltx/modfreedv/freedvmod.cpp +++ b/plugins/channeltx/modfreedv/freedvmod.cpp @@ -27,7 +27,7 @@ #include #include -#include "codec2/freedv_api.h" +#include "libfreedv.h" #include "SWGChannelSettings.h" #include "SWGChannelReport.h" @@ -137,7 +137,7 @@ FreeDVMod::~FreeDVMod() delete[] m_SSBFilterBuffer; if (m_freeDV) { - freedv_close(m_freeDV); + FreeDV::freedv_close(m_freeDV); } } @@ -230,7 +230,7 @@ void FreeDVMod::pullAF(Complex& sample) calculateLevel(m_speechIn[i]); } } - freedv_tx(m_freeDV, m_modOut, m_speechIn); + FreeDV::freedv_tx(m_freeDV, m_modOut, m_speechIn); break; case FreeDVModSettings::FreeDVModInputFile: if (m_iModem >= m_nNomModemSamples) @@ -270,7 +270,7 @@ void FreeDVMod::pullAF(Complex& sample) } } - freedv_tx(m_freeDV, m_modOut, m_speechIn); + FreeDV::freedv_tx(m_freeDV, m_modOut, m_speechIn); } } else @@ -295,7 +295,7 @@ void FreeDVMod::pullAF(Complex& sample) calculateLevel(m_speechIn[i]); } } - freedv_tx(m_freeDV, m_modOut, m_speechIn); + FreeDV::freedv_tx(m_freeDV, m_modOut, m_speechIn); break; case FreeDVModSettings::FreeDVModInputCWTone: for (int i = 0; i < m_nSpeechSamples; i++) @@ -324,12 +324,12 @@ void FreeDVMod::pullAF(Complex& sample) calculateLevel(m_speechIn[i]); } } - freedv_tx(m_freeDV, m_modOut, m_speechIn); + FreeDV::freedv_tx(m_freeDV, m_modOut, m_speechIn); break; case FreeDVModSettings::FreeDVModInputNone: default: std::fill(m_speechIn, m_speechIn + m_nSpeechSamples, 0); - freedv_tx(m_freeDV, m_modOut, m_speechIn); + FreeDV::freedv_tx(m_freeDV, m_modOut, m_speechIn); break; } @@ -641,7 +641,7 @@ void FreeDVMod::applyFreeDVMode(FreeDVModSettings::FreeDVMode mode) // FreeDV object if (m_freeDV) { - freedv_close(m_freeDV); + FreeDV::freedv_close(m_freeDV); } int fdv_mode = -1; @@ -673,32 +673,32 @@ void FreeDVMod::applyFreeDVMode(FreeDVModSettings::FreeDVMode mode) if (fdv_mode == FREEDV_MODE_700D) { - struct freedv_advanced adv; + struct FreeDV::freedv_advanced adv; adv.interleave_frames = 1; - m_freeDV = freedv_open_advanced(fdv_mode, &adv); + m_freeDV = FreeDV::freedv_open_advanced(fdv_mode, &adv); } else { - m_freeDV = freedv_open(fdv_mode); + m_freeDV = FreeDV::freedv_open(fdv_mode); } if (m_freeDV) { - freedv_set_test_frames(m_freeDV, 0); - freedv_set_snr_squelch_thresh(m_freeDV, -100.0); - freedv_set_squelch_en(m_freeDV, 1); - freedv_set_clip(m_freeDV, 0); - freedv_set_tx_bpf(m_freeDV, 1); - freedv_set_ext_vco(m_freeDV, 0); + FreeDV::freedv_set_test_frames(m_freeDV, 0); + FreeDV::freedv_set_snr_squelch_thresh(m_freeDV, -100.0); + FreeDV::freedv_set_squelch_en(m_freeDV, 1); + FreeDV::freedv_set_clip(m_freeDV, 0); + FreeDV::freedv_set_tx_bpf(m_freeDV, 1); + FreeDV::freedv_set_ext_vco(m_freeDV, 0); - freedv_set_callback_txt(m_freeDV, nullptr, nullptr, nullptr); - freedv_set_callback_protocol(m_freeDV, nullptr, nullptr, nullptr); - freedv_set_callback_data(m_freeDV, nullptr, nullptr, nullptr); + FreeDV::freedv_set_callback_txt(m_freeDV, nullptr, nullptr, nullptr); + FreeDV::freedv_set_callback_protocol(m_freeDV, nullptr, nullptr, nullptr); + FreeDV::freedv_set_callback_data(m_freeDV, nullptr, nullptr, nullptr); - int nSpeechSamples = freedv_get_n_speech_samples(m_freeDV); - int nNomModemSamples = freedv_get_n_nom_modem_samples(m_freeDV); - int Fs = freedv_get_modem_sample_rate(m_freeDV); - int Rs = freedv_get_modem_symbol_rate(m_freeDV); + int nSpeechSamples = FreeDV::freedv_get_n_speech_samples(m_freeDV); + int nNomModemSamples = FreeDV::freedv_get_n_nom_modem_samples(m_freeDV); + int Fs = FreeDV::freedv_get_modem_sample_rate(m_freeDV); + int Rs = FreeDV::freedv_get_modem_symbol_rate(m_freeDV); if (nSpeechSamples != m_nSpeechSamples) { diff --git a/plugins/channeltx/modfreedv/freedvmod.h b/plugins/channeltx/modfreedv/freedvmod.h index ec2e6934c..1f3b92238 100644 --- a/plugins/channeltx/modfreedv/freedvmod.h +++ b/plugins/channeltx/modfreedv/freedvmod.h @@ -44,7 +44,10 @@ class QNetworkReply; class DeviceSinkAPI; class ThreadedBasebandSampleSource; class UpChannelizer; + +namespace FreeDV { struct freedv; +} class FreeDVMod : public BasebandSampleSource, public ChannelSourceAPI { Q_OBJECT @@ -318,7 +321,7 @@ private: QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; - struct freedv *m_freeDV; + struct FreeDV::freedv *m_freeDV; int m_nSpeechSamples; int m_nNomModemSamples; int m_iSpeech;