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

Chirp spread spectrum modulator (LoRa-like): the written bytes are collected and sent as frame when CSSConfig::max_frame bytes are available or when you call endTransmission() (or flush()). A frame consists of the preamble (up chirps), 2 down chirps, the header and the payload. Each symbol is a chirp which starts at the frequency of its value and wraps around at the end of the band. The phase is continuous. More...

#include <CSSEncoder.h>

Inheritance diagram for tinymodem::CSSEncoder:
Collaboration diagram for tinymodem::CSSEncoder:

Public Member Functions

 CSSEncoder ()=default
 CSSEncoder (Print &out)
CSSConfig defaultConfig ()
 Provides a default configuration: css7 (SF 7, 1000 Hz).
void setOutput (Print &out) override
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 (CSSConfig 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
 Collects the data: a frame is sent when max_frame bytes are available.
bool endTransmission (size_t silence_samples=0) override
bool isTransmitting () override
 true while data is waiting to be sent
float symbolRate () override
 Symbols per second.
size_t frameCount ()
 Number of sent frames.
CSSConfig & 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 sendFrame ()
void sendChirp (int value, bool up)

Static Protected Member Functions

static double sawIntegral (double x)
 Integral of frac(x): the normalized frequency of a chirp is a saw tooth.

Protected Attributes

CSSConfig cfg
SampleOutput samples
bool is_active = false
uint8_t frame [CSSConfig::MAX_FRAME]
int frame_len = 0
size_t frames = 0
double phase = 0
uint64_t symbol_index = 0
size_t ramp = 0
size_t total = 0
size_t written = 0
Protected Attributes inherited from tinymodem::ModemEncoder
ToneOutput tones

Static Protected Attributes

static constexpr float RAMP_SEC = 0.002f

Detailed Description

Chirp spread spectrum modulator (LoRa-like): the written bytes are collected and sent as frame when CSSConfig::max_frame bytes are available or when you call endTransmission() (or flush()). A frame consists of the preamble (up chirps), 2 down chirps, the header and the payload. Each symbol is a chirp which starts at the frequency of its value and wraps around at the end of the band. The phase is continuous.

Constructor & Destructor Documentation

◆ CSSEncoder() [1/2]

tinymodem::CSSEncoder::CSSEncoder ( )
default

◆ CSSEncoder() [2/2]

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

Member Function Documentation

◆ audioInfo()

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

◆ begin() [1/2]

bool tinymodem::CSSEncoder::begin ( )
inlineoverride

◆ begin() [2/2]

bool tinymodem::CSSEncoder::begin ( CSSConfig config)
inline

Starts the processing with the indicated configuration.

◆ config()

CSSConfig & tinymodem::CSSEncoder::config ( )
inline

The configuration which was provided in begin().

◆ defaultConfig()

CSSConfig tinymodem::CSSEncoder::defaultConfig ( )
inline

Provides a default configuration: css7 (SF 7, 1000 Hz).

◆ end()

void tinymodem::CSSEncoder::end ( )
inlineoverride

◆ endTransmission()

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

Sends the collected data (and adds optional silence): returns true if a frame was sent

Implements tinymodem::ModemEncoder.

◆ frameCount()

size_t tinymodem::CSSEncoder::frameCount ( )
inline

Number of sent frames.

◆ isTransmitting()

bool tinymodem::CSSEncoder::isTransmitting ( )
inlineoverridevirtual

true while data is waiting to be sent

Implements tinymodem::ModemEncoder.

◆ operator bool()

tinymodem::CSSEncoder::operator bool ( )
inlineoverride

◆ sawIntegral()

double tinymodem::CSSEncoder::sawIntegral ( double x)
inlinestaticprotected

Integral of frac(x): the normalized frequency of a chirp is a saw tooth.

◆ sendChirp()

void tinymodem::CSSEncoder::sendChirp ( int value,
bool up )
inlineprotected

Writes an up chirp (starting at the frequency of the value) or a down chirp. The phase is calculated exactly: the frequency jump at the end of the band happens between two samples.

◆ sendFrame()

void tinymodem::CSSEncoder::sendFrame ( )
inlineprotected

◆ setAudioInfo()

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

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

◆ setOutput()

void tinymodem::CSSEncoder::setOutput ( Print & out)
inlineoverride

◆ symbolRate()

float tinymodem::CSSEncoder::symbolRate ( )
inlineoverridevirtual

Symbols per second.

Implements tinymodem::ModemEncoder.

◆ write()

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

Collects the data: a frame is sent when max_frame bytes are available.

Member Data Documentation

◆ cfg

CSSConfig tinymodem::CSSEncoder::cfg
protected

◆ frame

uint8_t tinymodem::CSSEncoder::frame[CSSConfig::MAX_FRAME]
protected

◆ frame_len

int tinymodem::CSSEncoder::frame_len = 0
protected

◆ frames

size_t tinymodem::CSSEncoder::frames = 0
protected

◆ is_active

bool tinymodem::CSSEncoder::is_active = false
protected

◆ phase

double tinymodem::CSSEncoder::phase = 0
protected

◆ ramp

size_t tinymodem::CSSEncoder::ramp = 0
protected

◆ RAMP_SEC

float tinymodem::CSSEncoder::RAMP_SEC = 0.002f
staticconstexprprotected

◆ samples

SampleOutput tinymodem::CSSEncoder::samples
protected

◆ symbol_index

uint64_t tinymodem::CSSEncoder::symbol_index = 0
protected

◆ total

size_t tinymodem::CSSEncoder::total = 0
protected

◆ written

size_t tinymodem::CSSEncoder::written = 0
protected

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