Skip to content

audiogen: reject 32-bit integer PCM WAV input - #206

Open
0z5a wants to merge 1 commit into
Arm-Examples:mainfrom
0z5a:audiogen-wav-int-pcm
Open

0z5a wants to merge 1 commit into
Arm-Examples:mainfrom
0z5a:audiogen-wav-int-pcm

Conversation

@0z5a

@0z5a 0z5a commented Nov 21, 2026

Copy link
Copy Markdown

This is the patch from #205.

Changes

read_wav() in the audiogen app now accepts only IEEE float input:

  • format tag 3, or
  • format tag 0xFFFE (WAVE_FORMAT_EXTENSIBLE) whose sub-format is 3. The sub-format is read from the first two bytes of the SubFormat GUID, after cbSize, wValidBitsPerSample and dwChannelMask. An extensible fmt chunk shorter than 40 bytes fails the check.

The rest of the fmt chunk is skipped as before, minus the 10 bytes already read. Tag 1 (integer PCM) is no longer accepted, so a 32-bit integer file gets the existing "Unsupported WAV format" message with the ffmpeg command, like a 16-bit file does today.

How I found it

I read read_wav() while looking at the audio input path and noticed that the format check allows integer PCM, while the README and the error message ask for 32-bit float.

Where this can show up in practice

This is my estimate; I have not seen a field report. Any 44.1 kHz stereo 32-bit integer WAV passed with -i hits it. Examples are ffmpeg ... -c:a pcm_s32le, afconvert -d LEI32@44100, or a "32-bit integer" export from an audio editor. Before this change, the samples are read as float, so the encoder input has values up to about ±3e38, plus inf and NaN.

Validation

macOS, Apple clang. I compiled read_wav() from before and after this change in a small harness that prints the decoded samples. Input: 1 s, 440 Hz, 0.5 amplitude sine, 44.1 kHz stereo.

Input file Before After
32-bit integer, tag 1 (afconvert -d LEI32@44100) accepted, finite peak 3.2e38, 200 inf/NaN samples rejected, exit 1
32-bit integer, tag 0xFFFE + PCM sub-format, 40-byte fmt (the layout FFmpeg writes for pcm_s32le) accepted, same values rejected
16-bit integer, tag 1 rejected rejected

Controls, decoded output identical before and after:

  • 32-bit float, tag 3 (afconvert -d LEF32@44100, also the format FFmpeg writes for pcm_f32le stereo): accepted, peak 0.5, no inf/NaN.
  • 32-bit float, tag 0xFFFE + float sub-format, 40-byte fmt: accepted, same samples. This shows the skip of the remaining fmt bytes still lands on the next chunk.

The harness build gives no warnings with -Wall, before or after.

Not run: the full app build (no LiteRT here), the encoder and models, an Android build, and real files from ffmpeg (not installed here). The two extensible files were written by my own script, following the header layout in FFmpeg's ff_put_wav_header().

read_wav() accepted format tag 1 (integer PCM) and tag 0xFFFE
(WAVE_FORMAT_EXTENSIBLE) without checking the sub-format, so a 44.1 kHz
stereo 32-bit integer file passed the check and its samples were read
as float. Accept only IEEE float: tag 3, or tag 0xFFFE with the float
sub-format.

Refs Arm-Examples#205

Signed-off-by: Dezhen Lu <dezhen.lu@student.uni-tuebingen.de>
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