42 if (info.sample_rate ==
cfg.sample_rate && info.channels ==
cfg.channels &&
43 info.bits_per_sample ==
cfg.bits_per_sample)
45 cfg.sample_rate = info.sample_rate;
46 cfg.channels = info.channels;
47 cfg.bits_per_sample = info.bits_per_sample;
53 using audio_tools::AudioDecoder::begin;
63 if (!
cfg.isValid())
return false;
72 double w = 2.0 * M_PI *
cfg.frequency /
cfg.sample_rate;
91 size_t n = (size_t)(
cfg.rx_timeout_units + 2) *
cfg.unitTime() *
102 size_t write(
const uint8_t* data,
size_t len)
override {
185 return ((
noise_seed >> 8) & 0xFFFF) / 65535.0f - 0.5f;
190 if (add_noise &&
cfg.rx_noise != 0.0f) x +=
noise() *
cfg.rx_noise * 2.0f;
192 float vi = x *
re, vq = -x *
im;
194 sum_i += vi - old[0];
195 sum_q += vq - old[1];
212 for (
int k = 0; k <
window; k++) {
216 float mag = sqrtf(
re *
re +
im *
im);
223 float block_sec = (float)
block /
cfg.sample_rate;
232 bool raw =
tone_on ? level > threshold - hysteresis
233 : level > threshold + hysteresis &&
234 level >=
cfg.min_amplitude &&
256 float changed =
pending * block_sec;
277 float length = raw_length +
bias;
278 float units = length /
unit;
281 if (units < (t.
dot + t.
dash) / 2) {
296 if (
cfg.adaptive_speed && (element ==
'.' || element ==
'-'))
297 unit += 0.2f * (length / expected -
unit);
308 float length = raw_length -
bias;
309 float units = length /
unit;
315 float max_bias = 0.3f *
unit;
316 if (
bias > max_bias)
bias = max_bias;
317 if (
bias < -max_bias)
bias = -max_bias;
333 float units = (raw_length -
bias) /
unit;
347 output(ch == 0 ?
'?' : ch);
352 if (p_print !=
nullptr) p_print->write((uint8_t)ch);
360 status(
"### CARRIER morse %s %.1f wpm @ %.1f Hz ###\n",
363 (
double)
cfg.wpm, (
double)
cfg.frequency);
370 status(
"\n### NOCARRIER ndata=%u wpm=%.1f ###\n",
ndata, (
double)
wpm());
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
static const Timing & timing(MorseAlphabet alphabet)
Definition Morse.h:153
static char decode(MorseAlphabet alphabet, const char *code)
Character of a code: returns 0 if the code is unknown.
Definition Morse.h:169
void endOfSpace(float raw_length)
Definition MorseDecoder.h:302
float last_mark
Definition MorseDecoder.h:153
void flush() override
Processes the remaining samples (e.g. at the end of the input).
Definition MorseDecoder.h:88
void endOfMark(float raw_length)
Definition MorseDecoder.h:274
MorseConfig defaultConfig()
Provides a default configuration: International Morse code, 20 wpm.
Definition MorseDecoder.h:38
void processBlock(float level)
On/off decision of one block with the level of the tone.
Definition MorseDecoder.h:222
uint32_t sample_count
Definition MorseDecoder.h:143
char last_element
Definition MorseDecoder.h:154
float step_re
Definition MorseDecoder.h:142
bool isCarrier() override
true while a transmission is received
Definition MorseDecoder.h:109
float noise_level
Definition MorseDecoder.h:144
void endOfCarrier()
Definition MorseDecoder.h:366
float noise_mean
Definition MorseDecoder.h:145
int window
Definition MorseDecoder.h:138
bool is_active
Definition MorseDecoder.h:133
int pos
Definition MorseDecoder.h:140
void end() override
Processes the remaining samples and reports the end of the carrier.
Definition MorseDecoder.h:81
void finishCharacter()
Definition MorseDecoder.h:343
MorseDecoder(Print &out)
Definition MorseDecoder.h:35
float step_im
Definition MorseDecoder.h:142
float re
Definition MorseDecoder.h:142
bool isFinished() override
true if the decoding was stopped (rx_one)
Definition MorseDecoder.h:112
MorseConfig & config()
The configuration which was provided in begin().
Definition MorseDecoder.h:118
char code[MAX_CODE+1]
Definition MorseDecoder.h:157
float im
Definition MorseDecoder.h:142
float sum_i
Definition MorseDecoder.h:141
float signal_level
Definition MorseDecoder.h:144
static constexpr float DEBOUNCE_UNITS
changes which are shorter than this (in units) are ignored
Definition MorseDecoder.h:127
MorseConfig cfg
Definition MorseDecoder.h:132
void setAudioInfo(audio_tools::AudioInfo info) override
Defines the format of the input audio data.
Definition MorseDecoder.h:41
audio_tools::Vector< float > history
Definition MorseDecoder.h:139
float duration
Definition MorseDecoder.h:150
static constexpr float WINDOW_UNITS
length of the measurement window in units
Definition MorseDecoder.h:125
static constexpr float BLOCK_SEC
Definition MorseDecoder.h:123
PcmInput input
Definition MorseDecoder.h:135
float noise()
uniform random value in the range -0.5 to 0.5
Definition MorseDecoder.h:183
uint32_t noise_seed
Definition MorseDecoder.h:136
bool first_block
Definition MorseDecoder.h:146
void recalculate()
Avoids the accumulation of rounding errors.
Definition MorseDecoder.h:210
static constexpr float MIN_SNR
min ratio of the tone level to the average noise level
Definition MorseDecoder.h:130
unsigned ndata
Definition MorseDecoder.h:159
bool is_finished
Definition MorseDecoder.h:134
size_t write(const uint8_t *data, size_t len) override
Provide PCM data to the decoder.
Definition MorseDecoder.h:102
int pending
Definition MorseDecoder.h:149
bool carrier
Definition MorseDecoder.h:155
int code_len
Definition MorseDecoder.h:158
static constexpr int MAX_CODE
Definition MorseDecoder.h:128
int count
Definition MorseDecoder.h:138
float unit
Definition MorseDecoder.h:151
float wpm()
Current speed of the sender in words per minute.
Definition MorseDecoder.h:115
bool word_pending
Definition MorseDecoder.h:156
int block
Definition MorseDecoder.h:138
void resetState()
Definition MorseDecoder.h:161
void addSample(float x, bool add_noise)
Definition MorseDecoder.h:188
bool begin() override
Definition MorseDecoder.h:61
bool tone_on
Definition MorseDecoder.h:148
void checkSpace(float raw_length)
Ends the character, the word or the transmission during a space.
Definition MorseDecoder.h:331
float bias
Definition MorseDecoder.h:152
float sum_q
Definition MorseDecoder.h:141
bool begin(MorseConfig config)
Starts the processing with the indicated configuration.
Definition MorseDecoder.h:56
void output(char ch)
Definition MorseDecoder.h:350
void startOfCarrier()
Definition MorseDecoder.h:355
audio_tools::AudioInfo audioInfo() override
Definition MorseDecoder.h:51
TinyModem: software audio modems and packets with error correction.
Definition AX25.h:11
@ AMERICAN
Definition Morse.h:18
@ INTERNATIONAL
International Morse code (ITU-R M.1677): dots and dashes of 3 units.
Definition Morse.h:15
Lengths in units.
Definition Morse.h:146
float extra_long_dash
Definition Morse.h:147
float dot
Definition Morse.h:147
float letter_gap
Definition Morse.h:148
float element_gap
Definition Morse.h:148
float dash
Definition Morse.h:147
float inner_gap
Definition Morse.h:148
float long_dash
Definition Morse.h:147
float word_gap
Definition Morse.h:148
Configuration of the Morse code modem (MorseEncoder, MorseDecoder): a tone which is switched on and o...
Definition Morse.h:31