2017-08-09 07:26:01 -04:00
|
|
|
//
|
|
|
|
// cvocodecchannel.cpp
|
|
|
|
// ambed
|
|
|
|
//
|
|
|
|
// Created by Jean-Luc Deltombe (LX3JL) on 23/04/2017.
|
|
|
|
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// This file is part of ambed.
|
|
|
|
//
|
|
|
|
// xlxd is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// xlxd is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "ctimepoint.h"
|
|
|
|
#include "cvocodecchannel.h"
|
|
|
|
#include "cvocodecinterface.h"
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// constructor
|
|
|
|
|
|
|
|
CVocodecChannel::CVocodecChannel(CVocodecInterface *InterfaceIn, int iChIn, CVocodecInterface *InterfaceOut, int iChOut, int iSpeechGain)
|
|
|
|
{
|
|
|
|
m_bOpen = false;
|
|
|
|
m_InterfaceIn = InterfaceIn;
|
|
|
|
m_iChannelIn = iChIn;
|
|
|
|
m_InterfaceOut = InterfaceOut;
|
|
|
|
m_iChannelOut = iChOut;
|
|
|
|
m_iSpeechGain = iSpeechGain;
|
2020-02-03 14:52:14 -05:00
|
|
|
#if USE_AGC == 1
|
|
|
|
m_AGC = new CAGC((float)iSpeechGain);
|
|
|
|
#endif
|
|
|
|
#if USE_BANDPASSFILTER == 1
|
|
|
|
m_filter = new CFIRFilter(FILTER_TAPS, FILTER_TAPS_LENGTH);
|
|
|
|
#endif
|
2017-08-09 07:26:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// destructor
|
|
|
|
|
|
|
|
CVocodecChannel::~CVocodecChannel()
|
|
|
|
{
|
|
|
|
PurgeAllQueues();
|
2020-02-03 14:52:14 -05:00
|
|
|
#if USE_AGC == 1
|
|
|
|
delete m_AGC;
|
|
|
|
#endif
|
|
|
|
#if USE_BANDPASSFILTER == 1
|
|
|
|
delete m_filter;
|
|
|
|
#endif
|
2017-08-09 07:26:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// open & close
|
|
|
|
|
|
|
|
bool CVocodecChannel::Open(void)
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
if ( !m_bOpen )
|
|
|
|
{
|
|
|
|
m_bOpen = true;
|
|
|
|
ok = true;
|
|
|
|
PurgeAllQueues();
|
|
|
|
std::cout << "Vocodec channel " <<
|
|
|
|
m_InterfaceIn->GetName() << ":" << (int)m_iChannelIn << " -> " <<
|
|
|
|
m_InterfaceOut->GetName() << ":" << (int)m_iChannelOut << " open" << std::endl;
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CVocodecChannel::Close(void)
|
|
|
|
{
|
|
|
|
if ( m_bOpen )
|
|
|
|
{
|
|
|
|
m_bOpen = false;
|
|
|
|
PurgeAllQueues();
|
|
|
|
std::cout << "Vocodec channel " <<
|
|
|
|
m_InterfaceIn->GetName() << ":" << (int)m_iChannelIn << " -> " <<
|
2017-08-23 09:00:23 -04:00
|
|
|
m_InterfaceOut->GetName() << ":" << (int)m_iChannelOut << " closed" << std::endl;
|
2017-08-09 07:26:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// get
|
|
|
|
|
|
|
|
uint8 CVocodecChannel::GetCodecIn(void) const
|
|
|
|
{
|
|
|
|
return m_InterfaceIn->GetChannelCodec(m_iChannelIn);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8 CVocodecChannel::GetCodecOut(void) const
|
|
|
|
{
|
|
|
|
return m_InterfaceOut->GetChannelCodec(m_iChannelOut);
|
|
|
|
}
|
|
|
|
|
2020-02-03 14:52:14 -05:00
|
|
|
#if USE_AGC == 1
|
2020-01-28 15:44:51 -05:00
|
|
|
void CVocodecChannel::ApplyAGC(CVoicePacket& voicePacket)
|
|
|
|
{
|
2020-02-03 14:52:14 -05:00
|
|
|
m_AGC->Apply(voicePacket.GetVoice(), voicePacket.GetVoiceSize());
|
2020-01-29 14:08:20 -05:00
|
|
|
//std::cout << "Gain : " << m_AGC.GetGain() << "\n";
|
2020-01-28 15:44:51 -05:00
|
|
|
}
|
2020-02-03 14:52:14 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USE_BANDPASSFILTER == 1
|
|
|
|
void CVocodecChannel::ApplyFilter(CVoicePacket& voicePacket)
|
|
|
|
{
|
|
|
|
m_filter->Process(voicePacket.GetVoice(), voicePacket.GetVoiceSize());
|
|
|
|
}
|
|
|
|
#endif
|
2020-01-28 15:44:51 -05:00
|
|
|
|
2017-08-09 07:26:01 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// queues helpers
|
|
|
|
|
|
|
|
void CVocodecChannel::PurgeAllQueues(void)
|
|
|
|
{
|
|
|
|
GetPacketQueueIn()->Purge();
|
|
|
|
ReleasePacketQueueIn();
|
|
|
|
GetPacketQueueOut()->Purge();
|
|
|
|
ReleasePacketQueueOut();
|
|
|
|
GetVoiceQueue()->Purge();
|
|
|
|
ReleaseVoiceQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|