1
0
mirror of https://github.com/ShaYmez/xlxd.git synced 2024-11-16 05:01:49 -05:00
xlxd/ambed/cvocodecchannel.cpp

136 lines
3.8 KiB
C++
Raw Normal View History

//
// 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;
#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
}
////////////////////////////////////////////////////////////////////////////////////////
// destructor
CVocodecChannel::~CVocodecChannel()
{
PurgeAllQueues();
#if USE_AGC == 1
delete m_AGC;
#endif
#if USE_BANDPASSFILTER == 1
delete m_filter;
#endif
}
////////////////////////////////////////////////////////////////////////////////////////
// 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 << " -> " <<
m_InterfaceOut->GetName() << ":" << (int)m_iChannelOut << " closed" << std::endl;
}
}
////////////////////////////////////////////////////////////////////////////////////////
// get
uint8 CVocodecChannel::GetCodecIn(void) const
{
return m_InterfaceIn->GetChannelCodec(m_iChannelIn);
}
uint8 CVocodecChannel::GetCodecOut(void) const
{
return m_InterfaceOut->GetChannelCodec(m_iChannelOut);
}
#if USE_AGC == 1
void CVocodecChannel::ApplyAGC(CVoicePacket& voicePacket)
{
m_AGC->Apply(voicePacket.GetVoice(), voicePacket.GetVoiceSize());
2020-01-29 14:08:20 -05:00
//std::cout << "Gain : " << m_AGC.GetGain() << "\n";
}
#endif
#if USE_BANDPASSFILTER == 1
void CVocodecChannel::ApplyFilter(CVoicePacket& voicePacket)
{
m_filter->Process(voicePacket.GetVoice(), voicePacket.GetVoiceSize());
}
#endif
////////////////////////////////////////////////////////////////////////////////////////
// queues helpers
void CVocodecChannel::PurgeAllQueues(void)
{
GetPacketQueueIn()->Purge();
ReleasePacketQueueIn();
GetPacketQueueOut()->Purge();
ReleasePacketQueueOut();
GetVoiceQueue()->Purge();
ReleaseVoiceQueue();
}