From a3c49722e3dda0f18d9fbf8f631d297c2eb2fbd7 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Sat, 4 Mar 2023 07:50:16 -0700 Subject: [PATCH] redo run-time config --- Configure.cpp | 12 +++---- Controller.cpp | 95 +++++++++++++++++++++++--------------------------- Controller.h | 5 ++- DV3000.cpp | 1 + DV3003.cpp | 1 + DVSIDevice.cpp | 3 -- config/tcd.ini | 6 ++-- 7 files changed, 57 insertions(+), 66 deletions(-) diff --git a/Configure.cpp b/Configure.cpp index 34342bd..78d00d8 100644 --- a/Configure.cpp +++ b/Configure.cpp @@ -153,15 +153,15 @@ bool CConfigure::ReadData(const std::string &path) int CConfigure::getSigned(const std::string &key, const std::string &value) const { auto i = std::stoi(value.c_str()); - if (i < -36) + if (i < -24) { - std::cout << "WARNING: " << key << " = " << value << " is too low. Limit to -36!" << std::endl; - i = -36; + std::cout << "WARNING: " << key << " = " << value << " is too low. Limit to -24!" << std::endl; + i = -24; } - else if (i > 36) + else if (i > 24) { - std::cout << "WARNING: " << key << " = " << value << " is too high. Limit to 36!" << std::endl; - i = 36; + std::cout << "WARNING: " << key << " = " << value << " is too high. Limit to 24!" << std::endl; + i = 24; } return i; } diff --git a/Controller.cpp b/Controller.cpp index 6dd8723..ad8cf95 100644 --- a/Controller.cpp +++ b/Controller.cpp @@ -22,34 +22,29 @@ #include #include #include - #ifdef USE_SW_AMBE2 #include #endif -#include "Configure.h" #include "TranscoderPacket.h" #include "Controller.h" +#include "Configure.h" extern CConfigure g_Conf; -int16_t calcGainVal(float db) +int32_t CController::calcNumerator(int32_t db) const { - float ratio = powf(10.0f, (db/20.0f)); - - if(db < 0.0f){ - ratio = (-1.0f/ratio); - } + float num = 256.0f * powf(10.0f, (float(db)/20.0f)); - return (int16_t)roundf(ratio); + return int32_t(roundf(num)); } CController::CController() : keep_running(true) {} bool CController::Start() { - usrp_rxgain = calcGainVal(g_Conf.GetGain(EGainType::usrprx)); - usrp_txgain = calcGainVal(g_Conf.GetGain(EGainType::usrptx)); + usrp_rx_num = calcNumerator(g_Conf.GetGain(EGainType::usrprx)); + usrp_tx_num = calcNumerator(g_Conf.GetGain(EGainType::usrptx)); if (InitVocoders() || reader.Open(REF2TC)) { @@ -129,7 +124,7 @@ bool CController::InitVocoders() { // M17 "devices", one for each module const std::string modules(g_Conf.GetTCMods()); - for (auto c : modules) + for ( auto c : modules) { c2_16[c] = std::unique_ptr(new CCodec2(false)); c2_32[c] = std::unique_ptr(new CCodec2(true)); @@ -194,7 +189,8 @@ bool CController::InitVocoders() dstar_device = std::unique_ptr(new CDV3000(Encoding::dstar)); #ifdef USE_SW_AMBE2 md380_init(); - ambe_gain = calcGainVal(DMR_IN_GAIN); + ambe_in_num = calcNumerator(g_Conf.GetGain(EGainType::dmrin)); + ambe_out_num = calcNumerator(g_Conf.GetGain(EGainType::dmrout)); #else dmrsf_device = std::unique_ptr(new CDV3000(Encoding::dmrsf)); #endif @@ -211,7 +207,7 @@ bool CController::InitVocoders() if (dstar_device) { - if (dstar_device->OpenDevice(deviceset.front().first, deviceset.front().second, dvtype, g_Conf.GetGain(EGainType::dstarin), g_Conf.GetGain(EGainType::dstarout))) + if (dstar_device->OpenDevice(deviceset.front().first, deviceset.front().second, dvtype, int8_t(g_Conf.GetGain(EGainType::dstarin)), int8_t(g_Conf.GetGain(EGainType::dstarout)))) return true; deviceset.pop_front(); } @@ -223,7 +219,7 @@ bool CController::InitVocoders() #ifndef USE_SW_AMBE2 if (dmrsf_device) { - if (dmrsf_device->OpenDevice(deviceset.front().first, deviceset.front().second, dvtype, g_Conf.GetGain(EGainType::dmrin), g_Conf.GetGain(EGainType::dmrout))) + if (dmrsf_device->OpenDevice(deviceset.front().first, deviceset.front().second, dvtype, int8_t(g_Conf.GetGain(EGainType::dmrin)), int8_t(g_Conf.GetGain(EGainType::dmrout)))) return true; deviceset.pop_front(); } @@ -375,11 +371,10 @@ void CController::Codec2toAudio(std::shared_ptr packet) #ifdef USE_SW_AMBE2 md380_encode_fec(ambe2, packet->GetAudioSamples()); + packet->SetDMRData(ambe2); #else dmrsf_device->AddPacket(packet); #endif - - packet->SetDMRData(ambe2); p25vocoder.encode_4400((int16_t*)packet->GetAudioSamples(), imbe); packet->SetP25Data(imbe); packet->SetUSRPData((int16_t*)packet->GetAudioSamples()); @@ -414,22 +409,19 @@ void CController::ProcessC2Thread() #ifdef USE_SW_AMBE2 void CController::AudiotoSWAMBE2(std::shared_ptr packet) { - const auto m = packet->GetModule(); uint8_t ambe2[9]; - int16_t tmp[160]; const int16_t *p = packet->GetAudioSamples(); - const uint32_t g = abs(ambe_gain); - for(int i = 0; i < 160; ++i){ - if(ambe_gain < 0){ - tmp[i] = p[i] / g; - } - else{ - tmp[i] = p[i] * g; - } + if (ambe_in_num != 256) + { + int16_t tmp[160]; + for(int i = 0; i < 160; ++i) + tmp[i] = int16_t((p[i] * ambe_in_num) >> 8); + md380_encode_fec(ambe2, tmp); } + else + md380_encode_fec(ambe2, p); - md380_encode_fec(ambe2, tmp); packet->SetDMRData(ambe2); // we might be all done... @@ -440,9 +432,15 @@ void CController::AudiotoSWAMBE2(std::shared_ptr packet) void CController::SWAMBE2toAudio(std::shared_ptr packet) { - int16_t tmp[160] = {0}; + int16_t tmp[160]; md380_decode_fec(packet->GetDMRData(), tmp); + if (ambe_out_num != 256) + { + for (int i=0; i<160; i++) + tmp[i] = (tmp[i] * ambe_out_num) >> 8; + } packet->SetAudioSamples(tmp, false); + dstar_device->AddPacket(packet); codec2_queue.push(packet); imbe_queue.push(packet); @@ -487,7 +485,7 @@ void CController::AudiotoIMBE(std::shared_ptr packet) void CController::IMBEtoAudio(std::shared_ptr packet) { - int16_t tmp[160] = {0}; + int16_t tmp[160] = { 0 }; p25vocoder.decode_4400(tmp, (uint8_t*)packet->GetP25Data()); packet->SetAudioSamples(tmp, false); dstar_device->AddPacket(packet); @@ -527,20 +525,18 @@ void CController::ProcessIMBEThread() void CController::AudiotoUSRP(std::shared_ptr packet) { - int16_t tmp[160]; const int16_t *p = packet->GetAudioSamples(); - const uint32_t g = abs(usrp_txgain); - for(int i = 0; i < 160; ++i){ - if(usrp_txgain < 0){ - tmp[i] = p[i] / g; - } - else{ - tmp[i] = p[i] * g; - } + if (usrp_tx_num != 256) + { + int16_t tmp[160]; + for(int i = 0; i < 160; ++i) + tmp[i] = int16_t((p[i] * usrp_tx_num) >> 8); + packet->SetUSRPData(tmp); } + else + packet->SetUSRPData(p); - packet->SetUSRPData(tmp); // we might be all done... send_mux.lock(); @@ -550,21 +546,18 @@ void CController::AudiotoUSRP(std::shared_ptr packet) void CController::USRPtoAudio(std::shared_ptr packet) { - int16_t tmp[160]; const int16_t *p = packet->GetUSRPData(); - const uint32_t g = abs(usrp_rxgain); - for(int i = 0; i < 160; ++i){ - if(usrp_rxgain < 0){ - tmp[i] = p[i] / g; - } - else{ - tmp[i] = p[i] * g; - } + if (usrp_rx_num != 256) + { + int16_t tmp[160]; + for(int i = 0; i < 160; ++i) + tmp[i] = int16_t((p[i] * usrp_rx_num) >> 8); + packet->SetAudioSamples(tmp, false); } + else + packet->SetAudioSamples(p, false); - //packet->SetAudioSamples(packet->GetUSRPData(), false); - packet->SetAudioSamples(tmp, false); dstar_device->AddPacket(packet); codec2_queue.push(packet); diff --git a/Controller.h b/Controller.h index 1566027..0b65473 100644 --- a/Controller.h +++ b/Controller.h @@ -58,11 +58,10 @@ protected: CPacketQueue imbe_queue; CPacketQueue usrp_queue; std::mutex send_mux; - int16_t ambe_gain; - int16_t usrp_rxgain; - int16_t usrp_txgain; + int32_t ambe_in_num, ambe_out_num, usrp_rx_num, usrp_tx_num; imbe_vocoder p25vocoder; + int32_t calcNumerator(int32_t db) const; bool DiscoverFtdiDevices(std::list> &found); bool InitVocoders(); // processing threads diff --git a/DV3000.cpp b/DV3000.cpp index 6c1e2b6..e707273 100644 --- a/DV3000.cpp +++ b/DV3000.cpp @@ -33,6 +33,7 @@ #include #include "DV3000.h" +#include "Configure.h" #include "Controller.h" extern CController g_Cont; diff --git a/DV3003.cpp b/DV3003.cpp index ea42bea..b1dec1e 100644 --- a/DV3003.cpp +++ b/DV3003.cpp @@ -33,6 +33,7 @@ #include #include "DV3003.h" +#include "Configure.h" #include "Controller.h" extern CController g_Cont; diff --git a/DVSIDevice.cpp b/DVSIDevice.cpp index 08868d1..61409ca 100644 --- a/DVSIDevice.cpp +++ b/DVSIDevice.cpp @@ -34,13 +34,10 @@ #include #include "DVSIDevice.h" -#include "Controller.h" #include "Configure.h" extern CConfigure g_Conf; -extern CController Controller; - CDVDevice::CDVDevice(Encoding t) : type(t), ftHandle(nullptr), buffer_depth(0), keep_running(true) { } diff --git a/config/tcd.ini b/config/tcd.ini index 2a8f23f..0b7ede4 100644 --- a/config/tcd.ini +++ b/config/tcd.ini @@ -7,9 +7,9 @@ # up to three modules (for DVSI-3003). Transcoded = A -# In dB, 6 dB is a factor of 2 in amplitude, 4 in power. -# Gain values are limited to -36 to +36. Typical values will usually be less. -# Below are suggested values that seem to work well with us +# 6 dB is a factor of 2 in amplitude, 4 in power. +# Gain values are limited to -24 to +24. Typical values will usually be less. +# Below are suggested values. DStarGainIn = 16 DStarGainOut = -16 DmrYsfGainIn = -3