Repository navigation
Fix JT4 encoding to match the WSJT-X reference - #42
Merged
Merged
Conversation
The JT4 encoder produced frames that did not match WSJT-X. Four separate problems: - JT4_SYMBOL_COUNT was 207, but a JT4 frame is 206 symbols. - The encoder filled a 206-bit buffer and then shifted it right by one symbol (memmove + a hardcoded s[0] = 0), which corrupted the frame and read one element past the end of the buffer. - The sync vector table had only 126 entries (a truncated transcription) and stopped matching the reference from the first entry. - The sync/data merge put sync in the MSB and data in the LSB. Rewrite the merge step against WSJT-X gen4.f90: use the full 207-entry npr table (with its inert leading element, indexing npr(2:) for the 206 symbols) and map each symbol as tone = 2*data + sync, i.e. data MSB, sync LSB. Add the negative-report case from gen4: when a '-' sits in the report field (1-indexed position >= 9) and is followed by a digit 0-3, the sync vector is inverted. Verified bit-exact against a Python reimplementation of the gen4/encode4 pipeline (same 72-bit packing as the library's other modes) for report, non-report, and negative-report messages. Harness grows to 20 checks with JT4 frame-length, bit-exact, and inverted-sync coverage. Library still builds on AVR, SAMD, ESP32, ESP8266 and Renesas.
Member
Author
Upstream verification (added after Test Lab's PASS)In addition to Test Lab's independent check, I verified the implementation against the actual upstream WSJT-X source (
The one remaining difference is the message-packing stage: the library keeps its simplified |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
The JT4 encoder produced frames that do not match WSJT-X. Four separate defects in
jt4_encode/jt4_merge_sync_vector:JT4_SYMBOL_COUNTwas 207; a JT4 frame is 206 symbols.memmove(s + 1, s, JT4_BIT_COUNT)+ a hardcodeds[0] = 0). That corrupted the frame and read one element past the end of the buffer.What changed
JT4_SYMBOL_COUNT207 → 206; buffer for the convolution is nowuint8_t s[JT4_BIT_COUNT](was[JT4_SYMBOL_COUNT]).memmove+s[0] = 0shift entirely.jt4_merge_sync_vectornow takes the prepped message so it can detect negative reports.gen4.f90(npr, whose first element is inert), read asnpr[i + 1]fori = 0..205. Regenerated programmatically from the Fortran data statement after the hand-typed paste proved corrupted; verifiedlen == 207and element-wise equal to the reference.tone = 2 * data + sync(data MSB, sync LSB) — the correct 4-FSK mapping, replacingsync + 2 * gwith sync in the MSB.gen4.f90: if the message contains a-in the report field (0-indexed position ≥ 8, with a guard that a following character exists) followed by a digit0–3, the sync bits are complemented.jt4_encode(saidJT9_SYMBOL_COUNT) and the example comment (said 207 symbols).Verification
Bit-exact against a Python reimplementation of the WSJT-X
gen4/encode4pipeline (packing → K=32 convolutional encode →jt9_interleave→ sync merge with the referencenprtable), which itself was checked against the Fortran data statement:NT7SG0ABC M0SUPG0ABC M0SUP -05CQ DXAAAAAAA -05(inverted sync triggers)AAAAAAA 05All 206 tones in
{0,1,2,3}in every case.Harness: 20/20 PASS, 0/20 checks detected a bug. Three new checks:
jt4_frame_length— 206 tones, all in{0..3}(would have caught the uninitialized read).jt4_bit_exact— bit-exact 206-symbol frame forNT7S.jt4_inverted_sync— bit-exact frame forAAAAAAA -05.Example builds on all five CI targets: AVR Uno (28,438 B / 88%), SAMD MKR1000 (31,364 B / 11%), ESP32 (300,516 B / 22%), ESP8266 NodeMCU (253,492 B / 24% flash), Renesas Uno R4 WiFi (72,192 B / 27%).
Version bumped 1.4.2 → 1.4.3 (patch), README changelog and
jt4_encodedocs updated.Note on scope
JT4 keeps the library's existing simplified 72-bit
jt9_bit_packingrather than implementing WSJT-X's fullpackmsgtype detection — consistent with how JT9 and JT65 are handled in this library. The frame structure, sync vector, tone mapping and inverted-sync behaviour now match the reference exactly.