Repository navigation
Memory
Most of the memory is allocated once, in the decoder's begin(). It grows in proportion to the sample rate, and it's dominated by the receive buffers. Sending needs almost no memory, except with OFDM.
| Where | What | When |
|---|---|---|
| Inside the object (fixed size) | Output buffer of 128 × int16_t, Goertzel state, Packets buffers, FSK expect_* strings |
When the object is created |
Heap (audio_tools::Vector) |
Decoder sample buffers, OFDM sine/cosine tables, OFDM frame | Once, in begin(), which reallocates when the configuration changes |
| Heap (growing) |
ByteQueue (received bytes in the ...Stream classes) |
Grows up to about rx_buffer_size (default 256), then keeps its capacity |
| Stack | OFDM decoding: about 1.5 KB of local arrays. Packet decoding: a few hundred bytes | Per call. The receive task of the ...StreamRTOS classes has a default stack of 8 KB (see setTaskConfig()) |
PacketStream uses no heap at all. Its size is fixed by the template parameters (888 bytes with PacketStream<64, 16>).
The heap allocated by begin(), measured on the desktop. The buffers hold floats, so they are the same size on the ESP32 and RP2040.
| Modem type | Mode | Receiving, 8 kHz | Receiving, 48 kHz | Sending, 48 kHz |
|---|---|---|---|---|
| FSK |
1200, 300
|
2.6 KB | 16 KB | – |
| FSK |
rtty (45.45 baud) |
12.7 KB | 76 KB | – |
| MFSK |
mfsk4 / mfsk16 / mfsk64
|
0.9 / 4.2 / 15 KB | 3.5 / 15 / 57 KB | – |
| PSK |
psk31 / psk500
|
3 / 0.2 KB | 18 / 1.2 KB | – |
| OFDM |
ofdm16 / ofdm32 / ofdm64
|
3.6 / 7.2 / 14 KB | 20 / 40 / 81 KB | 3.7 / 6.7 / 13 KB |
| AX.25 | aprs |
0.1 KB | 0.6 KB | – |
A dash means less than 100 bytes.
The objects themselves are small: 0.5 to 1.4 KB for an encoder or decoder. A complete stream with an encoder, a decoder and a 256-byte copy buffer takes 1.4 to 3 KB. These sizes were measured on a 64-bit desktop, so they are a bit smaller on a 32-bit microcontroller.
Why some modes need more memory than others:
- Slow FSK modes keep about 2 characters' worth of samples. At 45 baud this is about 0.4 s of audio.
-
MFSK keeps the samples which are needed to find the preamble. This grows with the symbol length, and
mfsk64has long symbols. - OFDM keeps about 4 symbols plus 2 FFT windows. The FFT size is the sample rate divided by the carrier spacing.
Use a lower sample rate to save memory, because all buffers scale linearly with it. 8 to 22.05 kHz is enough for all modes, because the highest tone is about 3 kHz.
TinyModem allocates its buffers with audio_tools::Vector, so arduino-audio-tools decides where they go:
-
ESP32:
VectorusesDefaultAllocator, which triesps_malloc()first and falls back tomalloc(). If PSRAM is enabled in the board settings, the decoder buffers, the OFDM tables and the receive queue are placed in PSRAM automatically. Without PSRAM they are placed in internal RAM. -
RP2040 and RP2350:
Vectorusesnew[], so the buffers always stay in internal RAM, even on an RP2350 with PSRAM. The RP2040's 264 KB are enough for all modes, evenofdm64at 48 kHz. - The objects themselves are placed wherever you declare them, normally as globals in internal RAM.
- PSRAM is slower than internal RAM. The decoders read their buffers in tight loops (Goertzel filters, the OFDM DFT, the MFSK clock search), and with PSRAM these accesses go through the cache. If OFDM or MFSK cannot keep up in real time on an ESP32 with PSRAM, use a lower sample rate or disable PSRAM.
-
ESP32 without PSRAM: a single allocation of 76 to 81 KB (
rttyorofdm64at 48 kHz) can fail when the heap is fragmented. Use 22.05 kHz or less. -
Call
begin()early, for example insetup(), while the heap is still unfragmented. A laterbegin()with a different configuration allocates the buffers again.