arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ReedSolomonFEC< bytecount, additional_bytes > Class Template Reference

Forward error correction using Reed-Solomon: write is encoding and readBytes does the decoding. More...

#include <ReedSolomonFEC.h>

Inheritance diagram for ReedSolomonFEC< bytecount, additional_bytes >:
Inheritance graph
[legend]
Collaboration diagram for ReedSolomonFEC< bytecount, additional_bytes >:
Collaboration graph
[legend]

Public Member Functions

 ReedSolomonFEC (Print &print)
 
 ReedSolomonFEC (Stream &stream)
 
int available () override
 Number of decoded bytes which can be read without blocking.
 
int availableForWrite () override
 Number of bytes which can be written until the next block is encoded.
 
bool begin () override
 
virtual void end ()
 
size_t failedBlocks ()
 Number of blocks which could not be corrected.
 
virtual void flush () override
 
 operator bool ()
 
size_t readBytes (uint8_t *data, size_t len) override
 
void setWriteBufferSize (int size)
 
size_t write (const uint8_t *data, size_t len) override
 
virtual size_t write (uint8_t ch) override
 

Protected Member Functions

bool decodeBlock ()
 
void refillReadBuffer ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read()
 
bool writeBlock ()
 

Protected Attributes

int _timeout = 10
 
uint8_t decoded [bytecount]
 
int decoded_len = 0
 
int decoded_pos = 0
 
size_t failed_blocks = 0
 
const int max_write_retries = 1000
 
Print * p_print = nullptr
 
Stream * p_stream = nullptr
 
uint8_t raw [bytecount]
 
int raw_len = 0
 
RS::ReedSolomon< bytecount, additional_bytes > rs
 
uint8_t rx_encoded [bytecount+additional_bytes]
 
int rx_len = 0
 
RingBuffer< uint8_t > tmp_in {0}
 
RingBuffer< uint8_t > tmp_out {0}
 
uint8_t tx_encoded [bytecount+additional_bytes]
 
int write_buffer_size = MAX_SINGLE_CHARS
 

Detailed Description

template<int bytecount, int additional_bytes>
class audio_tools::ReedSolomonFEC< bytecount, additional_bytes >

Forward error correction using Reed-Solomon: write is encoding and readBytes does the decoding.

The written data is split into blocks of bytecount bytes and each block is written with additional_bytes parity bytes. Data is only sent in complete blocks: the bytes of a trailing incomplete block (less than bytecount bytes) are never written. The reader collects the encoded blocks from the stream and corrects up to additional_bytes / 2 wrong bytes per block. If a block can not be corrected, the uncorrected data bytes are provided and failedBlocks() is incremented. There are no sync markers: if bytes get lost on the link, the block boundaries are wrong until begin() is called on both sides to restart at a block boundary.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ ReedSolomonFEC() [1/2]

template<int bytecount, int additional_bytes>
ReedSolomonFEC ( Stream &  stream)
inline

◆ ReedSolomonFEC() [2/2]

template<int bytecount, int additional_bytes>
ReedSolomonFEC ( Print &  print)
inline

Member Function Documentation

◆ available()

template<int bytecount, int additional_bytes>
int available ( )
inlineoverridevirtual

Number of decoded bytes which can be read without blocking.

Reimplemented from BaseStream.

◆ availableForWrite()

template<int bytecount, int additional_bytes>
int availableForWrite ( )
inlineoverridevirtual

Number of bytes which can be written until the next block is encoded.

Reimplemented from BaseStream.

◆ begin()

template<int bytecount, int additional_bytes>
bool begin ( )
inlineoverridevirtual

Resets the encoding and decoding state: can be used to resynchronize the block boundaries (e.g. after lost bytes)

Reimplemented from BaseStream.

◆ decodeBlock()

template<int bytecount, int additional_bytes>
bool decodeBlock ( )
inlineprotected

Decodes the received block if it is complete: returns false if more data is needed

◆ end()

virtual void end ( )
inlinevirtualinherited

◆ failedBlocks()

template<int bytecount, int additional_bytes>
size_t failedBlocks ( )
inline

Number of blocks which could not be corrected.

◆ flush()

virtual void flush ( )
inlineoverridevirtualinherited

◆ operator bool()

operator bool ( )
inlineinherited

◆ readBytes()

template<int bytecount, int additional_bytes>
size_t readBytes ( uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

Implements BaseStream.

◆ refillReadBuffer()

void refillReadBuffer ( )
inlineprotectedinherited

Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read()

◆ setWriteBufferSize()

void setWriteBufferSize ( int  size)
inlineinherited

◆ write() [1/2]

template<int bytecount, int additional_bytes>
size_t write ( const uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

Implements BaseStream.

◆ write() [2/2]

virtual size_t write ( uint8_t  ch)
inlineoverridevirtualinherited

◆ writeBlock()

template<int bytecount, int additional_bytes>
bool writeBlock ( )
inlineprotected

Writes the complete encoded block: a partial block would break the block boundaries of the receiver

Member Data Documentation

◆ _timeout

int _timeout = 10
protectedinherited

◆ decoded

template<int bytecount, int additional_bytes>
uint8_t decoded[bytecount]
protected

◆ decoded_len

template<int bytecount, int additional_bytes>
int decoded_len = 0
protected

◆ decoded_pos

template<int bytecount, int additional_bytes>
int decoded_pos = 0
protected

◆ failed_blocks

template<int bytecount, int additional_bytes>
size_t failed_blocks = 0
protected

◆ max_write_retries

template<int bytecount, int additional_bytes>
const int max_write_retries = 1000
protected

◆ p_print

template<int bytecount, int additional_bytes>
Print* p_print = nullptr
protected

◆ p_stream

template<int bytecount, int additional_bytes>
Stream* p_stream = nullptr
protected

◆ raw

template<int bytecount, int additional_bytes>
uint8_t raw[bytecount]
protected

◆ raw_len

template<int bytecount, int additional_bytes>
int raw_len = 0
protected

◆ rs

template<int bytecount, int additional_bytes>
RS::ReedSolomon<bytecount, additional_bytes> rs
protected

◆ rx_encoded

template<int bytecount, int additional_bytes>
uint8_t rx_encoded[bytecount+additional_bytes]
protected

◆ rx_len

template<int bytecount, int additional_bytes>
int rx_len = 0
protected

◆ tmp_in

RingBuffer<uint8_t> tmp_in {0}
protectedinherited

◆ tmp_out

RingBuffer<uint8_t> tmp_out {0}
protectedinherited

◆ tx_encoded

template<int bytecount, int additional_bytes>
uint8_t tx_encoded[bytecount+additional_bytes]
protected

◆ write_buffer_size

int write_buffer_size = MAX_SINGLE_CHARS
protectedinherited

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