Repository navigation
fix: byte-swap PortAudio PCM on big-endian hosts - #119
Merged
Merged
Conversation
The player carries little-endian PCM, but PortAudio's paInt16, paInt24 and paInt32 are native-endian. On a big-endian host the sink handed PortAudio byte-reversed samples and played noise, and --input portaudio sent byte-reversed capture upstream. pcm_le_native_swap() converts in place in either direction and compiles to nothing on little-endian hosts. The sink swaps after the volume ramp, which works on little-endian data; the source swaps as it reads from its ring. The standalone check that CI cross-compiles for big-endian MIPS now covers the swap too, against memcpy into native integers. Fixes #78
chrisuthe
added a commit
that referenced
this pull request
Nov 12, 2026
Brings the re-pin to sendspin-cpp 78b13d5e and main through #119. The endpoint now reads the token through client_pairing_token(), which replaces the deprecated pairing_token().
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.
Fixes #78
Why
The player carries little-endian PCM, and every other backend opens an explicitly little-endian format. PortAudio has no little-endian format to ask for:
paInt16,paInt24andpaInt32are native-endian. On a big-endian host,-o portaudiotherefore played every 16-, 24- and 32-bit sample byte-reversed, which is noise at any volume.--input portaudio, added after #78 was filed, had the mirror-image bug: it sent native-endian capture upstream as if it were little-endian.What
src/pcm_endian.hwithpcm_le_native_swap(), which swaps each sample in place between little-endian and native order. The swap undoes itself, so it serves both directions. Thanks toif constexpr (std::endian::native == std::endian::little), it compiles to nothing on little-endian hosts, so x86 and ARM builds do no extra work.apply_volume_ramp(), which expects little-endian data.read()swaps as it takes frames out of the ring, on the capture thread rather than in PortAudio's callback. It keeps abytes_per_sample_for this.pa_format_for(), which claimed PortAudio takes little-endian PCM, is corrected.Testing
tests/pcm_volume_le_check.cpp, which thebig-endian (mips)CI job already cross-compiles and runs under qemu, now checks the swap too. It compares 16- and 32-bit results againstmemcpyinto nativeint16_t/int32_trather than repeating the swap logic, and checks that a second swap restores the original bytes.ci.ymlis unchanged.qemu-mips-static: all checks pass. A mutant with the swap disabled fails it (5 wrong samples at each of 16, 24 and 32 bits), so the check catches the bug.-Werror, PortAudio built in): 540/540 passed, so both changed PortAudio files compile cleanly.-Werror, no PortAudio): 549/549 passed.