mirror of https://github.com/LX3JL/xlxd.git
parent
5356f37fd8
commit
02a583f0b3
@ -0,0 +1,44 @@
|
||||
//
|
||||
// cfixedgain.cpp
|
||||
// ambed
|
||||
//
|
||||
// Created by Jean-Luc Deltombe (LX3JL) on 28/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/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
// Geoffrey Merck F4FXL / KC3FRA AGC
|
||||
|
||||
#include "cfixedgain.h"
|
||||
#include <math.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// constructor
|
||||
|
||||
CFixedGain::CFixedGain(float gaindB)
|
||||
{
|
||||
m_gaindB = gaindB;
|
||||
m_gainLinear = pow(10.0f, m_gaindB/20.0f);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// processing
|
||||
|
||||
inline float CFixedGain::ProcessSample(float input)
|
||||
{
|
||||
return input * m_gainLinear;
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
//
|
||||
// cfixedgain.h
|
||||
// ambed
|
||||
//
|
||||
// Created by Jean-Luc Deltombe (LX3JL) on 26/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/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
// Geoffrey Merck F4FXL / KC3FRA
|
||||
|
||||
#ifndef cfixedgain_h
|
||||
#define cfixedgain_h
|
||||
|
||||
#include "csampleprocessor.h"
|
||||
|
||||
class CFixedGain : CSampleProcessor
|
||||
{
|
||||
public:
|
||||
//Constructor
|
||||
CFixedGain(float gaindB);
|
||||
|
||||
//processing
|
||||
float ProcessSample(float input);
|
||||
|
||||
private:
|
||||
float m_gaindB; //gain in dB
|
||||
float m_gainLinear; //linearized gain
|
||||
};
|
||||
|
||||
#endif /* cfixedgain_h */
|
||||
@ -0,0 +1,36 @@
|
||||
//
|
||||
// csampleprocessor.h
|
||||
// ambed
|
||||
//
|
||||
// Created by Jean-Luc Deltombe (LX3JL) on 26/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/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
// Geoffrey Merck F4FXL / KC3FRA
|
||||
|
||||
#ifndef csampleprocessor_h
|
||||
#define csampleprocessor_h
|
||||
|
||||
class CSampleProcessor
|
||||
{
|
||||
public:
|
||||
//processing
|
||||
virtual float ProcessSample(float input) = 0;
|
||||
};
|
||||
|
||||
#endif /* csampleprocessor_h */
|
||||
@ -0,0 +1,89 @@
|
||||
//
|
||||
// cagc.cpp
|
||||
// ambed
|
||||
//
|
||||
// Created by Jean-Luc Deltombe (LX3JL) on 28/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/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
// Geoffrey Merck F4FXL / KC3FRA AGC
|
||||
|
||||
#include "main.h"
|
||||
#include "csignalprocessor.h"
|
||||
|
||||
#if USE_AGC == 1
|
||||
#include "cagc.h"
|
||||
#else
|
||||
#include "cfixedgain.h"
|
||||
#endif
|
||||
|
||||
#if USE_BANDPASSFILTER == 1
|
||||
#include "cfirfilter.h"
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// constructor
|
||||
|
||||
CSignalProcessor::CSignalProcessor(float gaindB)
|
||||
{
|
||||
#if USE_BANDPASSFILTER
|
||||
m_sampleProcessors.push_back((CSampleProcessor*)new CFIRFilter(FILTER_TAPS, FILTER_TAPS_LENGTH));
|
||||
#endif
|
||||
#if USE_AGC == 1
|
||||
m_sampleProcessors.push_back((CSampleProcessor*)new CAGC(gaindB));
|
||||
#else
|
||||
m_sampleProcessors.push_back((CSampleProcessor*)new CFixedGain(gaindB));
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// destructor
|
||||
|
||||
CSignalProcessor::~CSignalProcessor()
|
||||
{
|
||||
for(int i = 0; i < m_sampleProcessors.size(); i++)
|
||||
{
|
||||
delete m_sampleProcessors[i];
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// processing
|
||||
|
||||
void CSignalProcessor::Process(uint8* voice, int length)
|
||||
{
|
||||
float sample;
|
||||
int i;
|
||||
auto processorsSize = m_sampleProcessors.size();
|
||||
|
||||
for(int i = 0; i < length; i += 2)
|
||||
{
|
||||
//Get the sample
|
||||
sample = (float)(short)MAKEWORD(voice[i+1], voice[i]);
|
||||
|
||||
for(i = 0; i < processorsSize; i++)
|
||||
{
|
||||
sample = m_sampleProcessors[i]->ProcessSample(sample);
|
||||
}
|
||||
|
||||
//write processed sample back
|
||||
voice[i] = HIBYTE((short)sample);
|
||||
voice[i+1] = LOBYTE((short)sample);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
//
|
||||
// csignalprocessor.h
|
||||
// ambed
|
||||
//
|
||||
// Created by Jean-Luc Deltombe (LX3JL) on 26/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/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
// Geoffrey Merck F4FXL / KC3FRA
|
||||
|
||||
#ifndef csignalprocessor_h
|
||||
#define csignalprocessor_h
|
||||
|
||||
#include <vector>
|
||||
#include "csampleprocessor.h"
|
||||
|
||||
class CSignalProcessor
|
||||
{
|
||||
public:
|
||||
//Constructor
|
||||
CSignalProcessor(float gaindB);
|
||||
|
||||
//Destructor
|
||||
~CSignalProcessor();
|
||||
|
||||
//Processing
|
||||
void Process(uint8* voice, int length);
|
||||
|
||||
private:
|
||||
std::vector<CSampleProcessor *> m_sampleProcessors;
|
||||
};
|
||||
|
||||
#endif /* csignalprocessor_h */
|
||||
Loading…
Reference in new issue