41 if (info.sample_rate ==
cfg.sample_rate && info.channels ==
cfg.channels &&
42 info.bits_per_sample ==
cfg.bits_per_sample)
44 cfg.sample_rate = info.sample_rate;
45 cfg.channels = info.channels;
46 cfg.bits_per_sample = info.bits_per_sample;
52 using audio_tools::AudioDecoder::begin;
65 LOGE(
"FSKDecoder: invalid configuration (max 64 bits per frame)");
68 if (!
input.begin(c.bits_per_sample, c.channels, c.
channel))
return false;
70 LOGE(
"FSKDecoder: frequencies not supported with sample rate %d",
145 size_t write(
const uint8_t* data,
size_t len)
override {
147 input.write(data, len, [
this](
float sample) {
addSample(sample); });
231 uic.setTrainToGround(
true);
235 uic.setTrainToGround(
false);
268 if (c.
stop_bits != 0.0f) str[j++] = stop_bit_value;
269 for (
int i = 0; i < c.
start_bits; i++) str[j++] = start_bit_value;
270 for (
int i = 0; i < c.
data_bits; i++, j++) {
271 str[j] = use_expect_bits ? ((expect_bits >> i) & 1) +
'0' :
'd';
273 if (c.
stop_bits != 0.0f) str[j++] = stop_bit_value;
281 return ((
noise_seed >> 8) & 0xFFFF) / 65535.0f - 0.5f;
294 while (
step(
false)) {
317 if (eof &&
skip > 0)
return false;
331 if (nsamples_per_scan >
plan.fftSize()) nsamples_per_scan =
plan.fftSize();
333 i += nsamples_per_scan) {
338 advance = i + nsamples_per_scan;
343 float bw =
plan.bandWidth();
349 if (b_space < 1 || b_space >= (
int)
plan.bandCount()) {
366 if (try_step_nsamples == 0) try_step_nsamples = 1;
368 float confidence, amplitude;
371 unsigned frame_start_sample = 0;
375 confidence =
plan.findFrame(
377 try_step_nsamples, try_confidence_search_limit,
379 &frame_start_sample);
381 bool do_refine_frame =
false;
383 do_refine_frame =
true;
425 do_refine_frame =
true;
428 if (do_refine_frame && confidence < INFINITY && try_step_nsamples > 1) {
431 if (try_step_nsamples == 0) try_step_nsamples = 1;
432 float confidence2, amplitude2;
434 unsigned frame_start_sample2;
435 confidence2 =
plan.findFrame(
437 try_step_nsamples, INFINITY,
439 &litude2, &frame_start_sample2);
440 if (confidence2 > confidence) {
442 amplitude = amplitude2;
443 frame_start_sample = frame_start_sample2;
459 if (c.
stop_bits != 0.0f) bits = bits >> 1;
467 if (p_print !=
nullptr) {
481 status(
"### CARRIER %u @ %.1f Hz ###\n", (
unsigned)(rate + 0.5f),
484 status(
"### CARRIER %.2f @ %.1f Hz ###\n", (
double)rate,
492 float throughput_rate =
494 status(
"\n### NOCARRIER ndata=%u confidence=%.3f ampl=%.3f bps=%.2f",
497 (
double)throughput_rate);
498 if ((
unsigned long long)(nbits_decoded * sample_rate + 0.5f) ==
500 status(
" (rate perfect) ###\n");
502 float skew = (throughput_rate - rate) / rate;
503 status(
" (%.1f%% %s) ###\n", (
double)(fabsf(skew) * 100.0f),
504 signbit(skew) ?
"slow" :
"fast");
ASCII 8-bit data (passthrough).
Definition DataCodecs.h:47
Baudot (ITA2) 5-bit data.
Definition DataCodecs.h:65
Raw N-bit binary data: prints the bits as '0' and '1' followed by newline.
Definition DataCodecs.h:55
Caller-ID (USA SDMF/MDMF) decoder. See http://melabs.com/resources/callerid.htm.
Definition DataCodecs.h:171
Converts between characters and the data bits of a frame.
Definition DataCodecs.h:32
void setupCodec()
Definition FSKDecoder.h:218
unsigned nsamples_overscan
Definition FSKDecoder.h:196
size_t carrier_nsamples
Definition FSKDecoder.h:213
AsciiCodec ascii
Definition FSKDecoder.h:182
size_t write(const uint8_t *data, size_t len) override
Provide PCM data to the decoder.
Definition FSKDecoder.h:145
unsigned expect_n_bits
Definition FSKDecoder.h:201
static constexpr float FRAME_OVERSCAN
Definition FSKDecoder.h:175
ModemConfig active_cfg
Definition FSKDecoder.h:178
CallerIDCodec callerid
Definition FSKDecoder.h:185
float amplitude_total
Definition FSKDecoder.h:211
float peak_confidence
Definition FSKDecoder.h:216
PcmInput input
Definition FSKDecoder.h:204
void end() override
Processes the remaining samples and reports the end of the carrier.
Definition FSKDecoder.h:124
ModemConfig & config()
Definition FSKDecoder.h:159
audio_tools::Vector< float > samplebuf
Definition FSKDecoder.h:190
uint32_t noise_seed
Definition FSKDecoder.h:205
int buildExpectBits(char *str, bool use_expect_bits, uint64_t expect_bits)
Definition FSKDecoder.h:263
float markFrequency()
Actual mark frequency (e.g. after the carrier auto detection).
Definition FSKDecoder.h:165
static constexpr int FSK_ANALYZE_NSTEPS
Definition FSKDecoder.h:171
int carrier_band
Definition FSKDecoder.h:209
void addSample(float sample)
Definition FSKDecoder.h:284
bool step(bool eof)
Definition FSKDecoder.h:314
float noise()
uniform random value in the range -0.5 to 0.5
Definition FSKDecoder.h:279
float nsamples_per_bit
Definition FSKDecoder.h:195
unsigned expect_nsamples
Definition FSKDecoder.h:202
bool isFinished() override
true if the decoding was stopped (rx_one)
Definition FSKDecoder.h:155
void setAudioInfo(audio_tools::AudioInfo info) override
Defines the format of the input audio data.
Definition FSKDecoder.h:40
unsigned noconfidence
Definition FSKDecoder.h:214
static constexpr unsigned FSK_MAX_NOCONFIDENCE_BITS
Definition FSKDecoder.h:173
size_t skip
Definition FSKDecoder.h:194
void reportCarrier()
Definition FSKDecoder.h:478
float track_amplitude
Definition FSKDecoder.h:215
unsigned frame_nsamples
Definition FSKDecoder.h:198
FSKDemodulator plan
Definition FSKDecoder.h:181
BaudotCodec baudot
Definition FSKDecoder.h:183
bool is_active
Definition FSKDecoder.h:179
char expect_sync_string[MAX_EXPECT]
Definition FSKDecoder.h:200
ModemConfig defaultConfig()
Provides a default configuration for a 1200 baud Bell 202 modem.
Definition FSKDecoder.h:33
DataCodec * p_codec
Definition FSKDecoder.h:187
UICCodec uic
Definition FSKDecoder.h:186
const ModemConfig & activeConfig() const
The active configuration with all derived values (e.g. frequencies).
Definition FSKDecoder.h:162
float frame_n_bits
Definition FSKDecoder.h:197
void flush() override
Processes all buffered samples (e.g. at the end of the input).
Definition FSKDecoder.h:131
static constexpr int MAX_EXPECT
Definition FSKDecoder.h:170
unsigned nframes_decoded
Definition FSKDecoder.h:212
bool carrier
Definition FSKDecoder.h:208
char expect_data_string[MAX_EXPECT]
Definition FSKDecoder.h:199
void reportNoCarrier()
Definition FSKDecoder.h:488
PrintFilter print_filter
Definition FSKDecoder.h:188
bool begin(ModemConfig config)
Starts the processing with the indicated modem configuration.
Definition FSKDecoder.h:55
FSKDecoder(Print &out)
Definition FSKDecoder.h:30
static constexpr int FSK_ANALYZE_NSTEPS_FINE
Definition FSKDecoder.h:172
bool isCarrier() override
true while a carrier is detected
Definition FSKDecoder.h:152
size_t advance
Definition FSKDecoder.h:193
void applyAdvance()
Definition FSKDecoder.h:299
bool is_finished
Definition FSKDecoder.h:180
float confidence_total
Definition FSKDecoder.h:210
size_t process_threshold
Definition FSKDecoder.h:192
size_t samples_nvalid
Definition FSKDecoder.h:191
void resetState()
Definition FSKDecoder.h:244
bool begin() override
Definition FSKDecoder.h:60
BinaryCodec binary
Definition FSKDecoder.h:184
audio_tools::AudioInfo audioInfo() override
Definition FSKDecoder.h:50
ModemConfig cfg
Definition FSKDecoder.h:177
FSK bit and frame analysis (port of minimodem's fsk.c). Instead of a full FFT we use the Goertzel alg...
Definition FSKDemodulator.h:19
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
Print which replaces non printable characters with '.'.
Definition DataCodecs.h:361
UIC-751-3 ground-train or train-ground decoder.
Definition DataCodecs.h:309
TinyModem: software audio modems and packets with error correction.
Definition AX25.h:11
uint64_t bitReverse(uint64_t value, unsigned bits)
Reverses the ordering of the bits on an integer.
Definition DataCodecs.h:13
@ UIC_GROUND
UIC-751-3 ground to train (receive only).
Definition ModemConfig.h:19
@ CALLERID
Bell 202 Caller-ID (SDMF/MDMF, receive only).
Definition ModemConfig.h:17
@ UIC_TRAIN
UIC-751-3 train to ground (receive only).
Definition ModemConfig.h:18
@ BINARY
print the raw data bits as '0'/'1' (receive only)
Definition ModemConfig.h:16
@ BAUDOT
Baudot 5 bit (RTTY, TDD).
Definition ModemConfig.h:15
uint64_t bitWindow(uint64_t value, unsigned offset, unsigned bits)
Gets "bits" bits from "value" starting "offset" bits from the start.
Definition DataCodecs.h:23
Configuration of the FSK modem. The fields correspond to the command line options of minimodem....
Definition ModemConfig.h:32
bool rx_one
receiver: stop after the first carrier was lost
Definition ModemConfig.h:80
bool auto_carrier
automatically detect the carrier frequency
Definition ModemConfig.h:70
float auto_carrier_threshold
minimum magnitude for the carrier auto detection
Definition ModemConfig.h:72
bool print_filter
receiver: replace non printable characters with '.'
Definition ModemConfig.h:88
int start_bits
number of start bits (-1 = auto)
Definition ModemConfig.h:50
float search_limit
stop searching for a better frame when this confidence was reached
Definition ModemConfig.h:68
float stop_bits
number of stop bits (-1 = auto)
Definition ModemConfig.h:52
bool rx_sync
receiver: synchronize on sync_byte
Definition ModemConfig.h:60
bool setMode(const char *mode, bool keep_options=false)
Definition ModemConfig.h:109
long long sync_byte
sync byte value (-1 = none)
Definition ModemConfig.h:64
float space_freq
space frequency in Hz (0 = auto)
Definition ModemConfig.h:44
bool invert_start_stop
invert the start and stop bits
Definition ModemConfig.h:54
uint8_t channel
receiver: input channel which is used for the decoding
Definition ModemConfig.h:94
const char * expect_bits
custom expected frame pattern ('0','1','d')
Definition ModemConfig.h:92
float confidence
minimum confidence threshold (signal-to-noise squelch)
Definition ModemConfig.h:66
int autodetect_shift
derived: shift which is used for the carrier auto detection
Definition ModemConfig.h:101
bool inverted
swap the mark and space frequencies
Definition ModemConfig.h:56
unsigned frameBits() const
number of bits of a frame: start + data + stop bits
Definition ModemConfig.h:230
int data_bits
number of data bits per frame (0 = auto)
Definition ModemConfig.h:48
float baud_rate
baud rate in bits per second (default: 1200 baud Bell 202)
Definition ModemConfig.h:40
float mark_freq
mark frequency in Hz (0 = auto)
Definition ModemConfig.h:42
bool msb_first
transmit the most significant data bit first
Definition ModemConfig.h:58
int buffer_divisor
Definition ModemConfig.h:99
bool resolve()
Definition ModemConfig.h:171
float bandwidth
receive filter bandwidth in Hz (0 = auto)
Definition ModemConfig.h:46