Compare commits

...

2 Commits

Author SHA1 Message Date
Adi Bier / DL1HRC 01081d67ee Merge remote-tracking branch 'sm0svx/master' into ToneEncoder 2019-04-18 10:17:59 +02:00
Adi Bier / DL1HRC 280da76b86 New ToneEncoder that can be used SvxLink wide 2019-04-08 13:06:29 +02:00
3 changed files with 352 additions and 0 deletions

View File

@ -18,6 +18,7 @@ set(LIBSRC
WbRxRtlSdr.cpp SigLevDet.cpp SigLevDetDdr.cpp
SvxSwDtmfDecoder.cpp LocalRxSim.cpp SigLevDetSim.cpp
AfskDtmfDecoder.cpp SigLevDetAfsk.cpp Modulation.cpp
ToneEncoder.cpp
)
include (CheckSymbolExists)
CHECK_SYMBOL_EXISTS(HIDIOCGRAWINFO linux/hidraw.h HAS_HIDRAW_SUPPORT)

View File

@ -0,0 +1,186 @@
/**
@file ToneEncoder.cpp
@brief A tone encoder that can be used SvxLink wide
@author Tobias Blomberg / SM0SVX & Adi Bier / DL1HRC
@date 2019-04-08
\verbatim
SvxLink - A Multi Purpose Voice Services System for Ham Radio Use
Copyright (C) 2004-2019 Tobias Blomberg / SM0SVX
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\endverbatim
*/
/****************************************************************************
*
* System Includes
*
****************************************************************************/
#include <cmath>
/****************************************************************************
*
* Project Includes
*
****************************************************************************/
/****************************************************************************
*
* Local Includes
*
****************************************************************************/
#include "ToneEncoder.h"
/****************************************************************************
*
* Namespaces to use
*
****************************************************************************/
using namespace std;
using namespace Async;
/****************************************************************************
*
* Defines & typedefs
*
****************************************************************************/
/****************************************************************************
*
* Local class definitions
*
****************************************************************************/
/****************************************************************************
*
* Prototypes
*
****************************************************************************/
/****************************************************************************
*
* Exported Global Variables
*
****************************************************************************/
/****************************************************************************
*
* Local Global Variables
*
****************************************************************************/
/****************************************************************************
*
* Public member functions
*
****************************************************************************/
ToneEncoder::ToneEncoder(float tone_hz, int level)
: m_tone(tone_hz), m_level(level), is_enabled(false),
pos(0)
{
} /* ToneEncoder::ToneEncoder */
ToneEncoder::~ToneEncoder(void)
{
setEnable(false);
} /* ToneEncoder::~ToneEncoder */
void ToneEncoder::setEnable(bool enable)
{
is_enabled = enable;
if (is_enabled && m_tone > 0)
{
pos = 0;
writeSamples();
}
} /* ToneEncoder::setEnable */
void ToneEncoder::setLevel(int level)
{
m_level = level / 100.0;
} /* ToneEncoder::setLevel */
void ToneEncoder::setTone(float tone_hz)
{
m_tone = tone_hz;
} /* ToneEncoder::setTone */
void ToneEncoder::resumeOutput(void)
{
writeSamples();
} /* ToneEncoder::resumeOutput */
void ToneEncoder::allSamplesFlushed(void)
{
} /* ToneEncoder::allSamplesFlushed */
/****************************************************************************
*
* Private member functions
*
****************************************************************************/
void ToneEncoder::writeSamples(void)
{
static const int BLOCK_SIZE = 128;
int written;
do {
float buf[BLOCK_SIZE];
for (int i=0; i<BLOCK_SIZE; ++i)
{
buf[i] = m_level * sin(2 * M_PI * m_tone * (pos+i) / INTERNAL_SAMPLE_RATE);
}
written = sinkWriteSamples(buf, BLOCK_SIZE);
pos += written;
} while (written != 0 && is_enabled);
}
/*
* This file has not been truncated
*/

View File

@ -0,0 +1,165 @@
/**
@file ToneEncoder.h
@brief A tone encoder that can be used SvxLink wide
@author Tobias Blomberg / SM0SVX & Adi Bier / DL1HRC
@date 2019-04-08
\verbatim
SvxLink - A Multi Purpose Voice Services System for Ham Radio Use
Copyright (C) 2004-2019 Tobias Blomberg / SM0SVX
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\endverbatim
*/
#ifndef TONE_ENCODER_INCLUDED
#define TONE_ENCODER_INCLUDED
/****************************************************************************
*
* System Includes
*
****************************************************************************/
/****************************************************************************
*
* Project Includes
*
****************************************************************************/
#include <AsyncAudioSource.h>
/****************************************************************************
*
* Local Includes
*
****************************************************************************/
/****************************************************************************
*
* Forward declarations
*
****************************************************************************/
/****************************************************************************
*
* Namespace
*
****************************************************************************/
//namespace MyNameSpace
//{
/****************************************************************************
*
* Defines & typedefs
*
****************************************************************************/
/****************************************************************************
*
* Exported Global Variables
*
****************************************************************************/
/****************************************************************************
*
* Class definitions
*
****************************************************************************/
/**
@brief A tone encoder that can be used SvxLink wide
@author Tobias Blomberg / SM0SVX & Adi Bier / DL1HRC
@date 2019-04-08
*/
class ToneEncoder : public Async::AudioSource
{
public:
/**
* @brief Constructor
* @param tone_hz The frequency in Hz of the tone that should be detected
* @param level The audio level (0-100%)
*/
ToneEncoder(float tone_hz, int level);
/**
* @brief Destructor
*/
~ToneEncoder(void);
/**
* @brief Return the detection frequency
* @param tone_hz The tone frequency in Hertz
*/
void setTone(float tone_hz);
/**
* @brief Set the detection delay
* @param level Set the audio level from 0-100%
*/
void setLevel(int level);
/**
* @brief Set the detection delay in processing blocks
* @param enable Enable/disable the tone generator
*/
void setEnable(bool enabled);
void allSamplesFlushed(void);
void resumeOutput(void);
private:
float m_tone;
float m_level;
bool is_enabled;
int pos;
/**
* @brief Write samples into the audio source
*/
virtual void writeSamples(void);
}; /* class ToneEncoder */
//} /* namespace */
#endif /* TONE_ENCODER_INCLUDED */
/*
* This file has not been truncated
*/