TinyModem
Header-only software audio modem library
Loading...
Searching...
No Matches
tinymodem::MorseDecoder Class Reference

Morse code demodulator (CW): the PCM audio data is written to the decoder and the decoded characters (upper case) are written to the output. The input can be 8, 16 or 32 bit signed samples with any number of channels (only MorseConfig::channel is evaluated). More...

#include <MorseDecoder.h>

Inheritance diagram for tinymodem::MorseDecoder:
Collaboration diagram for tinymodem::MorseDecoder:

Public Member Functions

 MorseDecoder ()=default
 MorseDecoder (Print &out)
MorseConfig defaultConfig ()
 Provides a default configuration: International Morse code, 20 wpm.
void setAudioInfo (audio_tools::AudioInfo info) override
 Defines the format of the input audio data.
audio_tools::AudioInfo audioInfo () override
bool begin (MorseConfig config)
 Starts the processing with the indicated configuration.
bool begin () override
void end () override
 Processes the remaining samples and reports the end of the carrier.
void flush () override
 Processes the remaining samples (e.g. at the end of the input).
size_t write (const uint8_t *data, size_t len) override
 Provide PCM data to the decoder.
bool isCarrier () override
 true while a transmission is received
bool isFinished () override
 true if the decoding was stopped (rx_one)
float wpm ()
 Current speed of the sender in words per minute.
MorseConfig & config ()
 The configuration which was provided in begin().
 operator bool () override
Public Member Functions inherited from tinymodem::ModemDecoder
void setStatusOutput (Print &out)
 Defines the output for the ### CARRIER / ### NOCARRIER messages.
void setQuiet (bool quiet)
 Suppresses the status messages.
const char * mime () override

Protected Member Functions

void resetState ()
float noise ()
 uniform random value in the range -0.5 to 0.5
void addSample (float x, bool add_noise)
void recalculate ()
 Avoids the accumulation of rounding errors.
void processBlock (float level)
 On/off decision of one block with the level of the tone.
void endOfMark (float raw_length)
void endOfSpace (float raw_length)
void checkSpace (float raw_length)
 Ends the character, the word or the transmission during a space.
void finishCharacter ()
void output (char ch)
void startOfCarrier ()
void endOfCarrier ()
Protected Member Functions inherited from tinymodem::ModemDecoder
void status (const char *fmt,...)

Protected Attributes

MorseConfig cfg
bool is_active = false
bool is_finished = false
PcmInput input
uint32_t noise_seed = 1
int block = 96
int window = 480
int count = 0
audio_tools::Vector< float > history
int pos = 0
float sum_i = 0
float sum_q = 0
float re = 1
float im = 0
float step_re = 1
float step_im = 0
uint32_t sample_count = 0
float signal_level = 0
float noise_level = 0
float noise_mean = 0
bool first_block = true
bool tone_on = false
int pending = 0
float duration = 0
float unit = 0.06f
float bias = 0
float last_mark = 0
char last_element = 0
bool carrier = false
bool word_pending = false
char code [MAX_CODE+1]
int code_len = 0
unsigned ndata = 0
Protected Attributes inherited from tinymodem::ModemDecoder
Print * p_status = nullptr
bool is_quiet = false

Static Protected Attributes

static constexpr float BLOCK_SEC = 0.002f
static constexpr float WINDOW_UNITS = 0.5f
 length of the measurement window in units
static constexpr float DEBOUNCE_UNITS = 0.3f
 changes which are shorter than this (in units) are ignored
static constexpr int MAX_CODE = 16
static constexpr float MIN_SNR = 5.0f
 min ratio of the tone level to the average noise level

Detailed Description

Morse code demodulator (CW): the PCM audio data is written to the decoder and the decoded characters (upper case) are written to the output. The input can be 8, 16 or 32 bit signed samples with any number of channels (only MorseConfig::channel is evaluated).

The level of the tone is measured with a mixer and a sliding sum over half a dot, every 2 ms. The tone is on when the level is above the middle between the signal and the noise level (with hysteresis), and short changes are ignored. The length of the marks and spaces in units provides the dots and dashes and the spaces between the elements, characters and words. The length of a unit adapts to the speed of the sender. The rise and fall time of the tone shortens the marks and lengthens the spaces by the same amount: this is measured with the dots and the following element spaces (both are 1 unit) and corrected.

A transmission ends after MorseConfig::rx_timeout_units without a tone: this is reported with ### NOCARRIER.

Constructor & Destructor Documentation

◆ MorseDecoder() [1/2]

tinymodem::MorseDecoder::MorseDecoder ( )
default

◆ MorseDecoder() [2/2]

tinymodem::MorseDecoder::MorseDecoder ( Print & out)
inline

Member Function Documentation

◆ addSample()

void tinymodem::MorseDecoder::addSample ( float x,
bool add_noise )
inlineprotected

◆ audioInfo()

audio_tools::AudioInfo tinymodem::MorseDecoder::audioInfo ( )
inlineoverride

◆ begin() [1/2]

bool tinymodem::MorseDecoder::begin ( )
inlineoverride

◆ begin() [2/2]

bool tinymodem::MorseDecoder::begin ( MorseConfig config)
inline

Starts the processing with the indicated configuration.

◆ checkSpace()

void tinymodem::MorseDecoder::checkSpace ( float raw_length)
inlineprotected

Ends the character, the word or the transmission during a space.

◆ config()

MorseConfig & tinymodem::MorseDecoder::config ( )
inline

The configuration which was provided in begin().

◆ defaultConfig()

MorseConfig tinymodem::MorseDecoder::defaultConfig ( )
inline

Provides a default configuration: International Morse code, 20 wpm.

◆ end()

void tinymodem::MorseDecoder::end ( )
inlineoverride

Processes the remaining samples and reports the end of the carrier.

◆ endOfCarrier()

void tinymodem::MorseDecoder::endOfCarrier ( )
inlineprotected

◆ endOfMark()

void tinymodem::MorseDecoder::endOfMark ( float raw_length)
inlineprotected

◆ endOfSpace()

void tinymodem::MorseDecoder::endOfSpace ( float raw_length)
inlineprotected

◆ finishCharacter()

void tinymodem::MorseDecoder::finishCharacter ( )
inlineprotected

◆ flush()

void tinymodem::MorseDecoder::flush ( )
inlineoverridevirtual

Processes the remaining samples (e.g. at the end of the input).

Implements tinymodem::ModemDecoder.

◆ isCarrier()

bool tinymodem::MorseDecoder::isCarrier ( )
inlineoverridevirtual

true while a transmission is received

Implements tinymodem::ModemDecoder.

◆ isFinished()

bool tinymodem::MorseDecoder::isFinished ( )
inlineoverridevirtual

true if the decoding was stopped (rx_one)

Implements tinymodem::ModemDecoder.

◆ noise()

float tinymodem::MorseDecoder::noise ( )
inlineprotected

uniform random value in the range -0.5 to 0.5

◆ operator bool()

tinymodem::MorseDecoder::operator bool ( )
inlineoverride

◆ output()

void tinymodem::MorseDecoder::output ( char ch)
inlineprotected

◆ processBlock()

void tinymodem::MorseDecoder::processBlock ( float level)
inlineprotected

On/off decision of one block with the level of the tone.

◆ recalculate()

void tinymodem::MorseDecoder::recalculate ( )
inlineprotected

Avoids the accumulation of rounding errors.

◆ resetState()

void tinymodem::MorseDecoder::resetState ( )
inlineprotected

◆ setAudioInfo()

void tinymodem::MorseDecoder::setAudioInfo ( audio_tools::AudioInfo info)
inlineoverride

Defines the format of the input audio data.

◆ startOfCarrier()

void tinymodem::MorseDecoder::startOfCarrier ( )
inlineprotected

◆ wpm()

float tinymodem::MorseDecoder::wpm ( )
inline

Current speed of the sender in words per minute.

◆ write()

size_t tinymodem::MorseDecoder::write ( const uint8_t * data,
size_t len )
inlineoverride

Provide PCM data to the decoder.

Member Data Documentation

◆ bias

float tinymodem::MorseDecoder::bias = 0
protected

◆ block

int tinymodem::MorseDecoder::block = 96
protected

◆ BLOCK_SEC

float tinymodem::MorseDecoder::BLOCK_SEC = 0.002f
staticconstexprprotected

◆ carrier

bool tinymodem::MorseDecoder::carrier = false
protected

◆ cfg

MorseConfig tinymodem::MorseDecoder::cfg
protected

◆ code

char tinymodem::MorseDecoder::code[MAX_CODE+1]
protected

◆ code_len

int tinymodem::MorseDecoder::code_len = 0
protected

◆ count

int tinymodem::MorseDecoder::count = 0
protected

◆ DEBOUNCE_UNITS

float tinymodem::MorseDecoder::DEBOUNCE_UNITS = 0.3f
staticconstexprprotected

changes which are shorter than this (in units) are ignored

◆ duration

float tinymodem::MorseDecoder::duration = 0
protected

◆ first_block

bool tinymodem::MorseDecoder::first_block = true
protected

◆ history

audio_tools::Vector<float> tinymodem::MorseDecoder::history
protected

◆ im

float tinymodem::MorseDecoder::im = 0
protected

◆ input

PcmInput tinymodem::MorseDecoder::input
protected

◆ is_active

bool tinymodem::MorseDecoder::is_active = false
protected

◆ is_finished

bool tinymodem::MorseDecoder::is_finished = false
protected

◆ last_element

char tinymodem::MorseDecoder::last_element = 0
protected

◆ last_mark

float tinymodem::MorseDecoder::last_mark = 0
protected

◆ MAX_CODE

int tinymodem::MorseDecoder::MAX_CODE = 16
staticconstexprprotected

◆ MIN_SNR

float tinymodem::MorseDecoder::MIN_SNR = 5.0f
staticconstexprprotected

min ratio of the tone level to the average noise level

◆ ndata

unsigned tinymodem::MorseDecoder::ndata = 0
protected

◆ noise_level

float tinymodem::MorseDecoder::noise_level = 0
protected

◆ noise_mean

float tinymodem::MorseDecoder::noise_mean = 0
protected

◆ noise_seed

uint32_t tinymodem::MorseDecoder::noise_seed = 1
protected

◆ pending

int tinymodem::MorseDecoder::pending = 0
protected

◆ pos

int tinymodem::MorseDecoder::pos = 0
protected

◆ re

float tinymodem::MorseDecoder::re = 1
protected

◆ sample_count

uint32_t tinymodem::MorseDecoder::sample_count = 0
protected

◆ signal_level

float tinymodem::MorseDecoder::signal_level = 0
protected

◆ step_im

float tinymodem::MorseDecoder::step_im = 0
protected

◆ step_re

float tinymodem::MorseDecoder::step_re = 1
protected

◆ sum_i

float tinymodem::MorseDecoder::sum_i = 0
protected

◆ sum_q

float tinymodem::MorseDecoder::sum_q = 0
protected

◆ tone_on

bool tinymodem::MorseDecoder::tone_on = false
protected

◆ unit

float tinymodem::MorseDecoder::unit = 0.06f
protected

◆ window

int tinymodem::MorseDecoder::window = 480
protected

◆ WINDOW_UNITS

float tinymodem::MorseDecoder::WINDOW_UNITS = 0.5f
staticconstexprprotected

length of the measurement window in units

◆ word_pending

bool tinymodem::MorseDecoder::word_pending = false
protected

The documentation for this class was generated from the following file: