Skip to content

Fix QPSK encoder for Python 3 compatibility#1

Open
ogabrielluiz wants to merge 1 commit into
pichenettes:masterfrom
ogabrielluiz:fix-python3-encoder
Open

Fix QPSK encoder for Python 3 compatibility#1
ogabrielluiz wants to merge 1 commit into
pichenettes:masterfrom
ogabrielluiz:fix-python3-encoder

Conversation

@ogabrielluiz
Copy link
Copy Markdown

Summary

  • Fix integer division bug in qpsk/encoder.py: symbol_stream / 2 uses float division in Python 3, corrupting the QPSK modulation constellation. Values that should be ±1 become -1, 0, 1, 2 — producing ~20% sample clipping (vs ~12% with correct encoding) and making firmware WAVs unreliable or impossible to flash via the audio bootloader.
  • Fix: use // (integer division) operator.
  • Additional Python 3 compatibility fixes: shebang, bytes handling, removal of L suffixes, xrangerange, etc.

Context

Discovered while building custom Clouds firmware and failing to flash via audio bootloader. The official firmware WAVs (generated with Python 2) worked fine, but locally-generated WAVs (Python 3) consistently failed with red blinking error LEDs on the module. Root cause traced to the corrupted QPSK constellation from float division.

The 4ms fork independently worked around this with .astype(int) but never submitted upstream.

Test plan

  • Generated firmware WAV with fixed encoder — clipping now matches official levels (~11% vs ~20% before fix)
  • Successfully flashed custom Clouds firmware via audio bootloader using the fixed WAV
  • Verified module boots and operates correctly after flash

Python 2→3 migration: symbol_stream / 2 became float division,
corrupting the QPSK constellation (values -1,0,1,2 instead of ±1).
Produced ~20% sample clipping vs ~12% correct, making firmware
WAVs unreliable to flash. Fix: use // operator.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant