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

Multi-tone FSK modulator: converts the written bytes into 16 bit PCM audio. Each symbol is one of MFSKConfig::tones tones and carries log2(tones) bits (Gray coded, most significant bit first). More...

#include <MFSKEncoder.h>

Inheritance diagram for tinymodem::MFSKEncoder:
Collaboration diagram for tinymodem::MFSKEncoder:

Public Member Functions

 MFSKEncoder ()=default
 MFSKEncoder (Print &out)
MFSKConfig defaultConfig ()
 Provides a default configuration: mfsk16.
void setAudioInfo (audio_tools::AudioInfo info) override
 Defines the sample rate and number of channels of the generated audio.
audio_tools::AudioInfo audioInfo () override
bool begin (MFSKConfig config)
 Starts the processing with the indicated configuration.
bool begin () override
void end () override
size_t write (const uint8_t *data, size_t len) override
 Modulates the bytes.
bool endTransmission (size_t silence_samples=0) override
bool isTransmitting () override
 true between the first byte and endTransmission()
float symbolRate () override
 Symbols per second.
MFSKConfig & config ()
 The configuration which was provided in begin().
 operator bool () override
Public Member Functions inherited from tinymodem::ModemEncoder
void setOutput (Print &out) override
void setGenerator (audio_tools::SoundGenerator< int16_t > &generator)
audio_tools::SoundGenerator< int16_t > & getGenerator ()
 Provides the active tone generator.
virtual bool writeIdle (size_t nsamples)
 Sends an idle carrier: returns false if this is not supported.
void writeSilence (size_t nsamples)
 Writes the indicated number of samples of silence.
void writeTone (float freq, size_t nsamples)
 Writes a tone for the indicated number of samples.
void flush ()
 Ends the transmission.
const char * mime () override

Protected Member Functions

void startTransmission ()
void writeBits ()
 Writes the next bits_per_symbol bits from the bit buffer.
void writeSymbol (int tone)

Protected Attributes

MFSKConfig cfg
bool is_active = false
bool transmitting = false
int bits_per_symbol = 4
double samples_per_symbol = 0
uint32_t symbol_index = 0
uint32_t bit_buffer = 0
int bit_count = 0
Protected Attributes inherited from tinymodem::ModemEncoder
ToneOutput tones

Static Protected Attributes

static constexpr int TRAILER_SYMBOLS = 2

Detailed Description

Multi-tone FSK modulator: converts the written bytes into 16 bit PCM audio. Each symbol is one of MFSKConfig::tones tones and carries log2(tones) bits (Gray coded, most significant bit first).

A transmission starts with a preamble (alternating lowest and highest tone) for the receiver's timing, followed by the sync symbols (see MFSKConfig::syncSymbol()) and the data. Call endTransmission() (or flush()) when the data is complete: the last symbol is padded with 0 bits and 2 symbols of silence mark the end.

Constructor & Destructor Documentation

◆ MFSKEncoder() [1/2]

tinymodem::MFSKEncoder::MFSKEncoder ( )
default

◆ MFSKEncoder() [2/2]

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

Member Function Documentation

◆ audioInfo()

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

◆ begin() [1/2]

bool tinymodem::MFSKEncoder::begin ( )
inlineoverride

◆ begin() [2/2]

bool tinymodem::MFSKEncoder::begin ( MFSKConfig config)
inline

Starts the processing with the indicated configuration.

◆ config()

MFSKConfig & tinymodem::MFSKEncoder::config ( )
inline

The configuration which was provided in begin().

◆ defaultConfig()

MFSKConfig tinymodem::MFSKEncoder::defaultConfig ( )
inline

Provides a default configuration: mfsk16.

◆ end()

void tinymodem::MFSKEncoder::end ( )
inlineoverride

◆ endTransmission()

bool tinymodem::MFSKEncoder::endTransmission ( size_t silence_samples = 0)
inlineoverridevirtual

Sends the remaining bits and the end marker (and optional silence): returns true if a transmission was ended.

Implements tinymodem::ModemEncoder.

◆ isTransmitting()

bool tinymodem::MFSKEncoder::isTransmitting ( )
inlineoverridevirtual

true between the first byte and endTransmission()

Implements tinymodem::ModemEncoder.

◆ operator bool()

tinymodem::MFSKEncoder::operator bool ( )
inlineoverride

◆ setAudioInfo()

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

Defines the sample rate and number of channels of the generated audio.

◆ startTransmission()

void tinymodem::MFSKEncoder::startTransmission ( )
inlineprotected

◆ symbolRate()

float tinymodem::MFSKEncoder::symbolRate ( )
inlineoverridevirtual

Symbols per second.

Implements tinymodem::ModemEncoder.

◆ write()

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

Modulates the bytes.

◆ writeBits()

void tinymodem::MFSKEncoder::writeBits ( )
inlineprotected

Writes the next bits_per_symbol bits from the bit buffer.

◆ writeSymbol()

void tinymodem::MFSKEncoder::writeSymbol ( int tone)
inlineprotected

Writes the tone with the indicated index (-1 = silence). The symbol boundaries are rounded from the exact (fractional) symbol length.

Member Data Documentation

◆ bit_buffer

uint32_t tinymodem::MFSKEncoder::bit_buffer = 0
protected

◆ bit_count

int tinymodem::MFSKEncoder::bit_count = 0
protected

◆ bits_per_symbol

int tinymodem::MFSKEncoder::bits_per_symbol = 4
protected

◆ cfg

MFSKConfig tinymodem::MFSKEncoder::cfg
protected

◆ is_active

bool tinymodem::MFSKEncoder::is_active = false
protected

◆ samples_per_symbol

double tinymodem::MFSKEncoder::samples_per_symbol = 0
protected

◆ symbol_index

uint32_t tinymodem::MFSKEncoder::symbol_index = 0
protected

◆ TRAILER_SYMBOLS

int tinymodem::MFSKEncoder::TRAILER_SYMBOLS = 2
staticconstexprprotected

◆ transmitting

bool tinymodem::MFSKEncoder::transmitting = false
protected

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