41 cfg.sample_rate = info.sample_rate;
42 cfg.channels = info.channels;
43 cfg.bits_per_sample = info.bits_per_sample;
49 using audio_tools::AudioEncoder::begin;
59 if (!
cfg.isValid())
return false;
60 if (
cfg.bits_per_sample != 16) {
61 LOGE(
"OFDMEncoder: bits_per_sample must be 16, not %d",
62 (
int)
cfg.bits_per_sample);
65 if (
cfg.channels < 1) {
66 LOGE(
"OFDMEncoder: invalid number of channels: %d", (
int)
cfg.channels);
90 size_t write(
const uint8_t* data,
size_t len)
override {
92 for (
size_t j = 0; j < len; j++) {
106 for (
size_t j = 0; j < n; j++)
samples.write(0.0f);
136 int n =
cfg.carriers;
157 void sendBits(
const uint8_t* data,
int len,
int& bit_count) {
158 int n =
cfg.carriers;
159 for (
int j = 0; j < len; j++) {
160 for (
int b = 6; b >= 0; b -= 2) {
161 int dibit = (data[j] >> b) & 3;
162 int carrier = bit_count / 2;
165 if (bit_count == 2 * n) {
177 for (
int s = 0; s < symbols; s++) {
178 for (
int i = 0; i <
cfg.carriers; i++) {
179 int bit = (header >> (31 - (s *
cfg.carriers + i) % 32)) & 1;
188 static const int phase[4] = {0, 1, 3, 2};
194 int n =
cfg.carriers;
197 int time = t < 0 ? t +
fft_size : t;
199 for (
int i = 0; i < n; i++) {
201 if (sync && (bin & 1))
continue;
202 int idx = (int)(((int64_t)bin * time) %
fft_size);
206 value +=
table.cosine(idx);
209 value -=
table.sine(idx);
212 value -=
table.cosine(idx);
215 value +=
table.sine(idx);
Common API of the modulators (FSKEncoder, MFSKEncoder): the written data is converted to 16 bit PCM a...
Definition ModemBase.h:286
void setOutput(Print &out) override
Definition ModemBase.h:288
ToneOutput tones
Definition ModemBase.h:334
bool begin() override
Definition OFDMEncoder.h:57
audio_tools::AudioInfo audioInfo() override
Definition OFDMEncoder.h:47
int frame_len
Definition OFDMEncoder.h:133
bool is_active
Definition OFDMEncoder.h:126
SampleOutput samples
Definition OFDMEncoder.h:124
float amplitude
Definition OFDMEncoder.h:130
void sendHeader(uint32_t header)
Definition OFDMEncoder.h:175
void sendBits(const uint8_t *data, int len, int &bit_count)
Definition OFDMEncoder.h:157
void setAudioInfo(audio_tools::AudioInfo info) override
Defines the sample rate and number of channels of the generated audio.
Definition OFDMEncoder.h:40
bool endTransmission(size_t silence_samples=0) override
Definition OFDMEncoder.h:101
OFDMEncoder(Print &out)
Definition OFDMEncoder.h:25
void end() override
Definition OFDMEncoder.h:84
float symbolRate() override
OFDM symbols per second.
Definition OFDMEncoder.h:115
audio_tools::Vector< uint8_t > phases
Definition OFDMEncoder.h:131
int first_bin
Definition OFDMEncoder.h:129
size_t write(const uint8_t *data, size_t len) override
Collects the bytes and sends full frames.
Definition OFDMEncoder.h:90
bool begin(OFDMConfig config)
Starts the processing with the indicated configuration.
Definition OFDMEncoder.h:52
void sendSymbol(bool sync)
Writes the cyclic prefix and the symbol.
Definition OFDMEncoder.h:193
void sendFrame()
Definition OFDMEncoder.h:135
audio_tools::Vector< uint8_t > frame
Definition OFDMEncoder.h:132
bool isTransmitting() override
true if there is data which was not sent yet
Definition OFDMEncoder.h:112
int fft_size
Definition OFDMEncoder.h:127
OFDMConfig cfg
Definition OFDMEncoder.h:123
static int grayToPhase(int dibit)
00 -> 0, 01 -> 90, 11 -> 180, 10 -> 270 degrees
Definition OFDMEncoder.h:187
OFDMConfig & config()
The configuration which was provided in begin().
Definition OFDMEncoder.h:118
OFDMConfig defaultConfig()
Provides a default configuration: ofdm32.
Definition OFDMEncoder.h:28
void setOutput(Print &out) override
Definition OFDMEncoder.h:34
int prefix_size
Definition OFDMEncoder.h:128
OFDMTable table
Definition OFDMEncoder.h:125
Sine and cosine of 2 * PI * i / size.
Definition OFDM.h:140
Writes float samples (-1.0 to 1.0) as 16 bit PCM with the requested number of channels and volume to ...
Definition ModemBase.h:118
TinyModem: software audio modems and packets with error correction.
Definition AX25.h:11
Configuration of the OFDM modem (OFDMEncoder, OFDMDecoder): the data is transmitted in parallel on ca...
Definition OFDM.h:23
static int knownPhase(int symbol, int carrier)
Definition OFDM.h:120
static int headerSymbols(int carriers)
Number of symbols of the header (32 bits, one bit per carrier).
Definition OFDM.h:116
bool setMode(const char *mode)
Selects "ofdm16", "ofdm32" or "ofdm64": returns false if invalid.
Definition OFDM.h:52