A compact, embedded-friendly ASCII-to-Varicode encoder and decoder for PSK31.
PSK31 is a digital mode used by amateur radio operators. This library encodes ASCII text into Varicode bit sequences and decodes them back. The implementation is designed for low-powered and embedded processors with no dynamic memory allocation.
Encoding: Convert ASCII to Varicode bit sequences. Each character becomes a variable-length sequence of 1s and 0s, terminated by at least two consecutive 0s.
unsigned char buffer[16];
encoder_start(buffer);
encoder_push('H');
encoder_push('i');
int bytes = encoder_done();
// buffer contains encoded bits, bytes indicates lengthDecoding: Reverse the process by accumulating bits until the character separator (two consecutive 0s) is detected, then emit the character.
void on_char(char c) {
printf("%c", c);
}
decoder_init(on_char);
decoder_push(encoded_byte_1);
decoder_push(encoded_byte_2);
// on_char() called for each decoded characterThe decoder maintains state: the current Varicode value being assembled and a count of consecutive zeros. When zero_count >= 2, the accumulated value is looked up in the Varicode table and emitted via callback.
encoder.c— encoder implementationdecoder.c— decoder implementationpsk31.h— public APIvaricode.h— Varicode lookup tablestest/— encoder and decoder tests
- No dynamic memory allocation
- Caller-provided buffers
- Portable C implementation
- Callback-based decoder for streaming processing