44 if (info.sample_rate ==
cfg.sample_rate && info.channels ==
cfg.channels &&
45 info.bits_per_sample ==
cfg.bits_per_sample)
47 cfg.sample_rate = info.sample_rate;
48 cfg.channels = info.channels;
49 cfg.bits_per_sample = info.bits_per_sample;
55 using audio_tools::AudioDecoder::begin;
65 if (!
cfg.isValid())
return false;
85 "### AX25 frames=%u fcs_errors=%u fx25=%u il2p=%u corrected=%u ###\n",
98 size_t write(
const uint8_t* data,
size_t len)
override {
100 input.write(data, len, [
this](
float sample) {
addSample(sample); });
136 void begin(
float freq,
float sample_rate) {
137 double w = 2.0 * M_PI * freq / sample_rate;
144 float r =
re *
c -
im *
s;
149 float mag = sqrtf(
re *
re +
im *
im);
211 for (
int j = 0; j < 4; j++)
sums[j] = 0;
228 return ((
noise_seed >> 8) & 0xFFFF) / 65535.0f - 0.5f;
232 if (
cfg.rx_noise != 0.0f) x +=
noise() *
cfg.rx_noise * 2.0f;
236 for (
int j = 0; j < 4; j++) {
237 sums[j] += values[j] - old[j];
247 bool tone = mark_energy > space_energy;
269 for (
int j = 0; j < 4; j++)
sums[j] = 0;
270 for (
int k = 0; k <
window; k++)
271 for (
int j = 0; j < 4; j++)
sums[j] +=
products[k * 4 + j];
317 uint16_t fcs =
frame[len] | (
frame[len + 1] << 8);
342 if (tag == 0)
return;
358 int len = corrected < 0 ? 0
360 result,
sizeof(result));
409 if (len <= 0)
return;
417 for (; v; v &= v - 1) n++;
424 if (p_print ==
nullptr)
return;
431 p_print->write((
const uint8_t*)
text, n);
uint8_t il_payload[IL2P_MAX_ENCODED]
Definition AX25Decoder.h:206
Phasor mark
Definition AX25Decoder.h:170
void deliver(const uint8_t *frame, int len)
Writes a received frame (without FCS) to the output.
Definition AX25Decoder.h:422
size_t frameCount()
Number of received frames with a correct frame check sequence.
Definition AX25Decoder.h:113
size_t corrected_bytes
Definition AX25Decoder.h:163
int fx_tag
Definition AX25Decoder.h:193
uint8_t frame[AX25Frame::MAX_FRAME+2]
Definition AX25Decoder.h:183
float pll
Definition AX25Decoder.h:175
uint8_t fx_block[FX25::BLOCK_SIZE]
Definition AX25Decoder.h:195
uint32_t sample_count
Definition AX25Decoder.h:171
char text[AX25Frame::MAX_FRAME *2]
Definition AX25Decoder.h:187
void setAudioInfo(audio_tools::AudioInfo info) override
Defines the format of the input audio data.
Definition AX25Decoder.h:43
void fx25(int bit)
FX.25: correlation tag and Reed-Solomon block.
Definition AX25Decoder.h:338
int current_bits
Definition AX25Decoder.h:186
uint32_t il_accum
Definition AX25Decoder.h:201
int il_bits
Definition AX25Decoder.h:203
size_t write(const uint8_t *data, size_t len) override
Provide PCM data to the decoder.
Definition AX25Decoder.h:98
size_t il2pCount()
Number of received IL2P frames.
Definition AX25Decoder.h:122
size_t errorCount()
Number of frames with a wrong frame check sequence.
Definition AX25Decoder.h:116
void deliverPending()
Definition AX25Decoder.h:332
void flush() override
Provides a frame which is held back during an FX.25 block.
Definition AX25Decoder.h:92
void hdlc(int bit)
Definition AX25Decoder.h:276
int pending_len
Definition AX25Decoder.h:190
size_t errors
Definition AX25Decoder.h:160
bool begin(AX25Config config)
Starts the processing with the indicated configuration.
Definition AX25Decoder.h:58
float noise()
uniform random value in the range -0.5 to 0.5
Definition AX25Decoder.h:226
size_t il2p_frames
Definition AX25Decoder.h:162
size_t frames
Definition AX25Decoder.h:159
int il_state
Definition AX25Decoder.h:200
void il2p(int raw)
IL2P: sync word, header and payload.
Definition AX25Decoder.h:372
size_t fx25_frames
Definition AX25Decoder.h:161
Phasor space
Definition AX25Decoder.h:170
AX25Decoder(Print &out)
Definition AX25Decoder.h:33
static constexpr float PLL_GAIN
Definition AX25Decoder.h:436
int il_need
Definition AX25Decoder.h:203
size_t correctedCount()
Number of bytes which were corrected by FX.25 and IL2P.
Definition AX25Decoder.h:125
audio_tools::AudioInfo audioInfo() override
Definition AX25Decoder.h:53
uint32_t noise_seed
Definition AX25Decoder.h:158
int fx_total
Definition AX25Decoder.h:196
int pos
Definition AX25Decoder.h:168
int ones
Definition AX25Decoder.h:181
void resetState()
Definition AX25Decoder.h:209
AX25Config & config()
The configuration which was provided in begin().
Definition AX25Decoder.h:128
void processFrame()
Definition AX25Decoder.h:314
AX25Config cfg
Definition AX25Decoder.h:155
bool is_active
Definition AX25Decoder.h:156
static constexpr int IL2P_MAX_ENCODED
Definition AX25Decoder.h:199
int fx_bits
Definition AX25Decoder.h:196
PcmInput input
Definition AX25Decoder.h:157
bool last_tone
Definition AX25Decoder.h:176
bool isFinished() override
The decoder never stops.
Definition AX25Decoder.h:110
void recalculate()
Avoids the accumulation of rounding errors.
Definition AX25Decoder.h:268
int il_len
Definition AX25Decoder.h:203
bool il_inverted
Definition AX25Decoder.h:202
uint8_t current
Definition AX25Decoder.h:185
uint8_t il_header[IL2P::HEADER_SIZE]
Definition AX25Decoder.h:205
int frame_len
Definition AX25Decoder.h:184
uint64_t fx_accum
Definition AX25Decoder.h:194
void addSample(float x)
Definition AX25Decoder.h:231
float sums[4]
Definition AX25Decoder.h:169
uint8_t history
Definition AX25Decoder.h:180
uint8_t pending[AX25Frame::MAX_FRAME]
Definition AX25Decoder.h:189
int fx_len
Definition AX25Decoder.h:196
bool in_frame
Definition AX25Decoder.h:182
int il_corrected
Definition AX25Decoder.h:207
bool bit_tone
Definition AX25Decoder.h:177
audio_tools::Vector< float > products
Definition AX25Decoder.h:167
bool isCarrier() override
true while a frame is received
Definition AX25Decoder.h:105
size_t fx25Count()
Number of received FX.25 frames.
Definition AX25Decoder.h:119
float pll_step
Definition AX25Decoder.h:174
int window
Definition AX25Decoder.h:166
AX25Config defaultConfig()
Provides a default configuration: APRS (1200 baud AFSK).
Definition AX25Decoder.h:36
static int popcount(uint32_t v)
Definition AX25Decoder.h:415
void end() override
Reports the statistics.
Definition AX25Decoder.h:81
uint8_t il_raw_header[IL2P::HEADER_SIZE+IL2P::HEADER_PARITY]
Definition AX25Decoder.h:204
bool begin() override
Definition AX25Decoder.h:63
static size_t writeKiss(Print &out, const uint8_t *frame, size_t len)
Writes the frame as KISS data frame for port 0.
Definition AX25.h:242
static int toText(const uint8_t *frame, size_t len, char *text, size_t text_size)
Definition AX25.h:198
static uint16_t fcs(const uint8_t *data, size_t len)
AX.25 frame check sequence: CRC-16-CCITT with reflected bits.
Definition AX25.h:151
static constexpr int MAX_FRAME
Definition AX25.h:143
static constexpr int MIN_FRAME
Definition AX25.h:144
static int correct(int t, uint8_t *received)
Definition AX25FEC.h:101
static int extract(const uint8_t *data, int len, uint8_t *frame, int frame_size)
Definition AX25FEC.h:117
static const Tag & tag(int index)
The tag 1 - 11.
Definition AX25FEC.h:39
static constexpr int BLOCK_SIZE
Definition AX25FEC.h:31
static int findTag(uint64_t bits)
Finds the tag which matches the received 64 bits: returns 0 if none.
Definition AX25FEC.h:58
static int decodeHeader(const uint8_t *received, uint8_t *hdr, int *corrected=nullptr)
Definition AX25FEC.h:252
static int decodeFrame(const uint8_t *hdr, const uint8_t *encoded, uint8_t *frame, int frame_size, int *corrected=nullptr)
Definition AX25FEC.h:267
static constexpr int HEADER_PARITY
Definition AX25FEC.h:219
static constexpr uint32_t SYNC_WORD
Definition AX25FEC.h:217
static constexpr int HEADER_SIZE
Definition AX25FEC.h:218
Common API of the demodulators (FSKDecoder, MFSKDecoder): PCM audio data is written to the decoder an...
Definition ModemBase.h:344
void status(const char *fmt,...)
Definition ModemBase.h:367
TinyModem: software audio modems and packets with error correction.
Definition AX25.h:11
@ KISS
Definition AX25.h:20
Configuration of the AX.25 packet radio modem (AX25Encoder, AX25Decoder): Bell 202 AFSK with 1200 bau...
Definition AX25.h:44
bool setMode(const char *mode)
Definition AX25.h:78
Rotating phasor of a tone: avoids sin() and cos() per sample.
Definition AX25Decoder.h:134
float s
Definition AX25Decoder.h:135
float im
Definition AX25Decoder.h:135
float c
Definition AX25Decoder.h:135
void next()
Definition AX25Decoder.h:143
float re
Definition AX25Decoder.h:135
void begin(float freq, float sample_rate)
Definition AX25Decoder.h:136
void normalize()
Definition AX25Decoder.h:148
int check
check bytes
Definition AX25FEC.h:28
int data
transmitted data bytes
Definition AX25FEC.h:26