24-bit samples are written as 4-byte integers instead of packed 3-byte little-endian
The finding
For fmt.bits == 24 the dtype falls through to "<i4", so each sample takes 4 bytes. Standard 24-bit PCM (WAV block align = channels*3, raw s24le) expects 3 bytes per sample. Anything that trusts fmt.bits to compute frame size or duration will misread the stream: playback is garbled, the stream is 4/3 longer than expected, and channels interleave incorrectly. The sample values are scaled to 24-bit range but left in a 32-bit container, so they are not valid s24le or s32le audio.
1| """Speech audio for the voice channels: decode what the synthesiser gave, convert it to what a sink wants.
2|
3| A :class:`~argus_scout.channels.base.SpeechAudio` arrives as one of:
4|
5| - ``wav``: a RIFF/WAVE file. PCM integer samples of 8, 16, 24 or 32 bits, or IEEE float (32 or 64 bit),
6| including ``WAVE_FORMAT_EXTENSIBLE``. The header's rate and channel count win over the dataclass's.
7| - ``pcm_s16le``: raw little-endian 16-bit samples, interleaved, described by ``sample_rate`` and ``channels``.
8| - ``pcm_f32le``: the same, 32-bit float.
9|
10| Anything else (``mp3``, ``ogg``) is refused with :class:`AudioFormatError`: scout has no decoder for it, and
11| argus-echo can produce WAV or raw PCM.
12|
13| Conversion (channel count, sample rate, sample width) needs **numpy**, which is not a core dependency: it comes
14| with the ``snapcast`` and ``mask`` extras. :func:`require_numpy` gives the error to show when it is missing.
15| Resampling is linear interpolation: plenty for speech, and no extra dependency.
16| """
17|
18| from __future__ import annotations
19| The work pack
Recommendation. For 24-bit, convert to <i4 and drop the high byte of each sample, e.g. a = np.round(clipped*scale).astype('<i4'); return a.view(np.uint8).reshape(-1, 4)[:, :3].tobytes(). Alternatively, explicitly declare a 32-bit container in the format metadata.
Acceptance criteria
- Address: 24-bit samples are written as 4-byte integers instead of packed 3-byte little-endian
- Keep the change scoped to the cited file/symbols unless impact requires otherwise
- For 24-bit, convert to
<i4and drop the high byte of each sample, e.g.a = np.round(clipped*scale).astype('<i4'); return a.view(np.uint8).reshape(-1, 4)[:, :3].tobytes(). Alternatively, explicitly declare a 32-bit container in the forma - Re-check
src/argus_scout/channels/audio.pyafter the fix
Status
- claimed
- wontfix
How it was judged
The agent checked the finding against the code and found it wrong. No fix, no test run: the pack was closed with this note, which a person can read and overturn.
Deliberate: encode() writes the format Snapcast's sampleformat means. Snapcast stores 24-bit samples in 4-byte containers (its SampleFormat sets sampleSize 4 for 24 bits), and SampleFormat.sample_bytes already declares the 32-bit container (4 for both 24 and 32 bits; docstring and CLAUDE.md say so). Packing to 3 bytes would garble Snapcast playback.