53 if (info.sample_rate ==
cfg.sample_rate && info.channels ==
cfg.channels &&
54 info.bits_per_sample ==
cfg.bits_per_sample)
56 cfg.sample_rate = info.sample_rate;
57 cfg.channels = info.channels;
58 cfg.bits_per_sample = info.bits_per_sample;
64 using audio_tools::AudioDecoder::begin;
74 if (!
cfg.isValid())
return false;
86 if (!
cfg.rx_any_speed && p.
id != selected.
id)
continue;
102 for (
int j = 0; j < (int)
candidates.size(); j++)
105 float thr =
cfg.marker_threshold;
135 size_t write(
const uint8_t* data,
size_t len)
override {
137 input.write(data, len, [
this](
float sample) {
addSample(sample,
true); });
157 static constexpr int RING = 24;
188 audio_tools::Vector<float>
acc;
229 for (
int b = 0; b <
nbins; b++) {
242 for (
int j = 0; j < (int)
candidates.size(); j++)
250 return ((
noise_seed >> 8) & 0xFFFF) / 65535.0f - 0.5f;
255 if (add_noise &&
cfg.rx_noise != 0.0f)
260 for (
int b = 0; b <
nbins; b++) {
265 if (idx >= n) idx -= n;
284 for (
int b = 0; b <
nbins; b++) {
292 if (t + 1 >= (uint32_t)
WINDOW) {
293 for (
int b = 0; b <
nbins; b++) {
294 float sum_re = 0, sum_im = 0;
295 for (
int k = 0; k <
WINDOW; k++) {
296 sum_re +=
ringRe(t - k)[b];
297 sum_im +=
ringIm(t - k)[b];
299 power[b] = sum_re * sum_re + sum_im * sum_im;
303 for (
int b = 0; b <
nbins; b++) power[b] = 0;
317 for (
int b = 0; b < n; b++)
318 if (power[b] > max_power) max_power = power[b];
319 float floor = max_power * 1e-4f;
320 if (floor <= 0)
return 0;
323 float on = power[2 * i + i % 2];
324 float off = power[2 * i + 1 - i % 2];
325 float sum = on + off;
326 if (sum > floor) score += (on - off) / sum;
356 uint32_t best_pos = from;
357 for (uint32_t pos = from + 1; pos <= to; pos++) {
375 for (
int k = 0; k <
NOFFSETS; k++) {
377 uint32_t start = data_start + k -
NOFFSETS / 2;
378 c.
alive = start >= oldest;
380 LOGW(
"ggwave: start of the data is not in the history");
395 status(
"### CARRIER ggwave %.0f-%.0f Hz ###\n",
409 while (c.
alive && (int32_t)(c.
next - t) <= 0) {
419 uint32_t rel = t - c.
start;
421 int within = rel % symbol_blocks;
424 if (within >=
WINDOW && within < symbol_blocks - 1) {
426 for (
int b = 0; b <
data_bins; b++) c.
acc[b] += power[b];
428 if (within == symbol_blocks - 1)
endSymbol(c);
432 uint32_t end_start = (uint32_t)c.
nsymbols * symbol_blocks;
433 uint32_t first = end_start + 2 *
BLOCKS;
436 if (rel == last - 1) {
447 for (
int i = 0; i < 2 * bpt; i++) {
449 float max_power = -1;
450 for (
int k = 0; k < 16; k++) {
452 if (c.
acc[b] > max_power) {
453 max_power = c.
acc[b];
469 memcpy(tmp, c.
bytes,
sizeof(tmp));
477 c.
nsymbols = (total + bpt - 1) / bpt;
496 status(
"### NOCARRIER ndata=0 (no valid message) ###\n");
501 for (
int i = 0; i < c.
length; i++) {
503 if (p_print !=
nullptr) p_print->write(value);
audio_tools::Vector< float > block_re
Definition GGWaveDecoder.h:209
GGWaveDecoder(Print &out)
Definition GGWaveDecoder.h:42
float markerScore(const float *power, int n)
Definition GGWaveDecoder.h:315
GGWaveConfig cfg
Definition GGWaveDecoder.h:192
static constexpr int MARKER_WINDOWS
number of windows which are completely inside a marker
Definition GGWaveDecoder.h:171
static constexpr int RING
number of blocks of the history of the window power
Definition GGWaveDecoder.h:157
float noise()
uniform random value in the range -0.5 to 0.5
Definition GGWaveDecoder.h:248
static constexpr int SCORE_RING
number of blocks of the history of the marker score
Definition GGWaveDecoder.h:159
void clearCandidates()
Definition GGWaveDecoder.h:241
static constexpr int MAX_ENCODED
Definition GGWaveDecoder.h:173
GGWaveConfig defaultConfig()
Provides a default configuration: ggwave-fast.
Definition GGWaveDecoder.h:45
void addSample(float x, bool add_noise)
Definition GGWaveDecoder.h:253
void resetState()
Definition GGWaveDecoder.h:228
bool isFinished() override
true if the decoding was stopped (rx_one)
Definition GGWaveDecoder.h:145
static constexpr int MIN_DETECTIONS
a marker must be detected in this number of blocks (of 64)
Definition GGWaveDecoder.h:169
audio_tools::Vector< float > ring_im
Definition GGWaveDecoder.h:212
bool run_active
Definition GGWaveDecoder.h:220
bool begin(GGWaveConfig config)
Starts the processing with the indicated configuration.
Definition GGWaveDecoder.h:67
bool is_active
Definition GGWaveDecoder.h:193
static constexpr int BLOCKS
blocks per frame
Definition GGWaveDecoder.h:163
void accept(Candidate &c)
Definition GGWaveDecoder.h:499
PcmInput input
Definition GGWaveDecoder.h:195
void trackStartMarker(bool detected)
Definition GGWaveDecoder.h:331
uint32_t noise_seed
Definition GGWaveDecoder.h:197
float scores[SCORE_RING]
Definition GGWaveDecoder.h:215
audio_tools::Vector< float > ring_power
Definition GGWaveDecoder.h:214
int sample_pos
Definition GGWaveDecoder.h:210
int run_detections
Definition GGWaveDecoder.h:222
void kill(Candidate &c)
Definition GGWaveDecoder.h:489
float detect_score
Definition GGWaveDecoder.h:216
void processCandidates(uint32_t t)
Provides the blocks up to t to all candidates.
Definition GGWaveDecoder.h:406
void startCandidates(uint32_t data_start)
Definition GGWaveDecoder.h:369
int block_size
Definition GGWaveDecoder.h:200
static constexpr int MAX_MISSES
the marker is lost after this number of blocks without detection
Definition GGWaveDecoder.h:167
float * ringRe(uint32_t block)
Definition GGWaveDecoder.h:274
void setAudioInfo(audio_tools::AudioInfo info) override
Defines the format of the input audio data.
Definition GGWaveDecoder.h:52
GGWaveProtocol rx_protocols[3]
Definition GGWaveDecoder.h:204
GGWaveConfig & config()
The configuration which was provided in begin().
Definition GGWaveDecoder.h:151
bool is_finished
Definition GGWaveDecoder.h:194
void processBlock(Candidate &c, uint32_t t)
Definition GGWaveDecoder.h:417
audio_tools::Vector< Candidate > candidates
Definition GGWaveDecoder.h:225
uint32_t run_first
Definition GGWaveDecoder.h:221
audio_tools::AudioInfo audioInfo() override
Definition GGWaveDecoder.h:62
uint32_t block_no
Definition GGWaveDecoder.h:217
int nbins
Definition GGWaveDecoder.h:203
bool isCarrier() override
true while a message is received
Definition GGWaveDecoder.h:142
size_t write(const uint8_t *data, size_t len) override
Provide PCM data to the decoder.
Definition GGWaveDecoder.h:135
float * ringIm(uint32_t block)
Definition GGWaveDecoder.h:275
OFDMTable table
Definition GGWaveDecoder.h:196
int frame_size
Definition GGWaveDecoder.h:199
int nprotocols
Definition GGWaveDecoder.h:205
audio_tools::Vector< float > ring_re
Definition GGWaveDecoder.h:212
void endSymbol(Candidate &c)
Definition GGWaveDecoder.h:445
audio_tools::Vector< int > table_idx
Definition GGWaveDecoder.h:208
void endBlock()
Definition GGWaveDecoder.h:280
int nalive
Definition GGWaveDecoder.h:226
static constexpr int WINDOW
number of blocks of the marker detection window (one frame)
Definition GGWaveDecoder.h:161
int freq_start
Definition GGWaveDecoder.h:201
float * ringPower(uint32_t block)
Definition GGWaveDecoder.h:276
size_t messages
Definition GGWaveDecoder.h:198
int data_bins
Definition GGWaveDecoder.h:202
void failed()
Definition GGWaveDecoder.h:494
audio_tools::Vector< float > block_im
Definition GGWaveDecoder.h:209
void clearAccumulator(Candidate &c)
Definition GGWaveDecoder.h:401
size_t messageCount()
Number of received messages.
Definition GGWaveDecoder.h:148
static constexpr int NOFFSETS
timing offsets of the candidates: -1, 0, +1 block
Definition GGWaveDecoder.h:165
int run_misses
Definition GGWaveDecoder.h:223
void end() override
Processes the remaining samples.
Definition GGWaveDecoder.h:113
void flush() override
Processes the remaining samples (e.g. at the end of the input).
Definition GGWaveDecoder.h:120
bool begin() override
Definition GGWaveDecoder.h:72
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
Sine and cosine of 2 * PI * i / size.
Definition OFDM.h:140
static bool decode(uint8_t *data, int len, int ecc, int fcr=0)
Definition ReedSolomon.h:51
TinyModem: software audio modems and packets with error correction.
Definition AX25.h:11
Configuration of the ggwave compatible modem (GGWaveEncoder, GGWaveDecoder). Each message (up to 140 ...
Definition GGWave.h:74
static uint8_t dssMagic(int i)
Value of the ggwave DSS sequence for the indicated payload byte.
Definition GGWave.h:220
static constexpr int MARKER_TONES
number of tones of a marker
Definition GGWave.h:89
static constexpr int MARKER_FRAMES
number of frames of the start and end marker
Definition GGWave.h:87
static int encodedBytes(int len)
Total number of encoded bytes of a message (length, payload, parity).
Definition GGWave.h:169
static constexpr int LENGTH_BYTES
bytes of the Reed-Solomon coded length at the start of a message
Definition GGWave.h:91
static const GGWaveProtocol * protocols()
Provides the supported protocols.
Definition GGWave.h:132
static int eccBytes(int len)
Number of Reed-Solomon parity bytes for a payload of len bytes.
Definition GGWave.h:164
bool setMode(const char *mode)
Selects the protocol by mode name: returns false if invalid.
Definition GGWave.h:112
static int protocolCount()
Number of supported protocols.
Definition GGWave.h:129
static constexpr int MAX_PAYLOAD
max payload of a message (variable length format)
Definition GGWave.h:85
decoder for one protocol and timing offset
Definition GGWaveDecoder.h:178
int symbol
Definition GGWaveDecoder.h:183
audio_tools::Vector< float > acc
Definition GGWaveDecoder.h:188
bool data_done
Definition GGWaveDecoder.h:186
bool alive
Definition GGWaveDecoder.h:179
GGWaveProtocol protocol
Definition GGWaveDecoder.h:180
int length
Definition GGWaveDecoder.h:185
float end_score
Definition GGWaveDecoder.h:187
uint32_t next
Definition GGWaveDecoder.h:182
uint32_t start
Definition GGWaveDecoder.h:181
uint8_t bytes[MAX_ENCODED]
Definition GGWaveDecoder.h:189
int nsymbols
Definition GGWaveDecoder.h:184
Transmission protocol of ggwave (https://github.com/ggerganov/ggwave): the ids and parameters are ide...
Definition GGWave.h:36
const char * mode
TinyModem mode name.
Definition GGWave.h:40
int tones() const
number of simultaneous tones in a data symbol
Definition GGWave.h:49
GGWaveProtocolId id
ggwave protocol id
Definition GGWave.h:38
int frames_per_tx
number of frames per transmitted chunk (symbol)
Definition GGWave.h:44
int freq_start
FFT bin of the lowest tone.
Definition GGWave.h:42
int bytes_per_tx
number of bytes per chunk: 2 tones per byte
Definition GGWave.h:46