From 658a47bc4eb010a4f5d437d4d8249511cc869806 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 28 Jan 2020 21:44:51 +0100 Subject: [PATCH] Avoid Exxposing a reference to the internal AGC, improve debug info --- ambed/cagc.h | 6 +++--- ambed/cusb3xxxinterface.cpp | 4 +--- ambed/cvocodecchannel.cpp | 6 ++++++ ambed/cvocodecchannel.h | 5 ++++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ambed/cagc.h b/ambed/cagc.h index 20f7800..b549197 100644 --- a/ambed/cagc.h +++ b/ambed/cagc.h @@ -29,6 +29,7 @@ #define cagc_h #include "main.h" +#include "math.h" class CAGC { @@ -38,10 +39,9 @@ public: //methods void Apply(uint8 * voice, int size); - float GetGain(){ return m_scale; }//gets current gain (linear) - + float GetGain(){ return -20.0f*log10(m_g); }//gets current gain + private: - // gain variables float m_g; // current gain value float m_scale; // output scale value diff --git a/ambed/cusb3xxxinterface.cpp b/ambed/cusb3xxxinterface.cpp index 732fe4a..210b01f 100644 --- a/ambed/cusb3xxxinterface.cpp +++ b/ambed/cusb3xxxinterface.cpp @@ -152,9 +152,7 @@ void CUsb3xxxInterface::Task(void) { Queue = Channel->GetVoiceQueue(); CVoicePacket *clone = new CVoicePacket(VoicePacket); - CAGC agc = Channel->GetAGC(); - agc.Apply(clone->GetVoice(), clone->GetVoiceSize()); - std::cout << "Gain : " << agc.GetGain(); + Channel->ApplyAGC(*clone); //clone->ApplyGain(Channel->GetSpeechGain()); Queue->push(clone); Channel->ReleaseVoiceQueue(); diff --git a/ambed/cvocodecchannel.cpp b/ambed/cvocodecchannel.cpp index 04a252c..42c3bf8 100644 --- a/ambed/cvocodecchannel.cpp +++ b/ambed/cvocodecchannel.cpp @@ -92,6 +92,12 @@ uint8 CVocodecChannel::GetCodecOut(void) const return m_InterfaceOut->GetChannelCodec(m_iChannelOut); } +void CVocodecChannel::ApplyAGC(CVoicePacket& voicePacket) +{ + m_AGC.Apply(voicePacket.GetVoice(), voicePacket.GetVoiceSize()); + std::cout << "Gain : " << m_AGC.GetGain() << "\n"; +} + //////////////////////////////////////////////////////////////////////////////////////// // queues helpers diff --git a/ambed/cvocodecchannel.h b/ambed/cvocodecchannel.h index c0983a9..58fdfe5 100644 --- a/ambed/cvocodecchannel.h +++ b/ambed/cvocodecchannel.h @@ -28,6 +28,7 @@ #include "cpacketqueue.h" #include "cagc.h" +#include "cvoicepacket.h" //////////////////////////////////////////////////////////////////////////////////////// // class @@ -54,7 +55,9 @@ public: int GetChannelIn(void) const { return m_iChannelIn; } int GetChannelOut(void) const { return m_iChannelOut; } int GetSpeechGain(void) const { return m_iSpeechGain; } - CAGC& GetAGC() { return m_AGC; }; + + //Processing + void ApplyAGC(CVoicePacket& voicePacket); // interfaces bool IsInterfaceIn(const CVocodecInterface *interface) { return (interface == m_InterfaceIn); }