Repository navigation
system/nxplayer: Parse WAV headers and retain PCM fallback - #3840
Conversation
|
I've pushed the refactor in commit WAV playback now uses Validation completed:
Could you please take another look? |
665cd07 to
243b4a4
Compare
|
Hi @xiaoxiang781216 , thanks for the feedback! I've updated the implementation by moving the WAV-specific RIFF/WAVE parsing, format validation, and PCM buffer-filling logic into a dedicated The existing MP3/SBC decoder paths and raw PCM playback path have been kept separate from the WAV-specific changes. I've also rebuilt and tested the SIM ALSA configuration, including valid WAV playback with odd-sized chunks, raw PCM playback, malformed WAV rejection, and mid-playback truncation handling. Please have another look when you get a chance. Thanks! |
bb8605f to
7a2c7e3
Compare
7a2c7e3 to
ad73730
Compare
|
@imeghar2408-max I'm confuse, the nxplayer already have support to play wav files, in fact that was the first type of format supported before mp3, as you can see on this video tutorial from 8 years ago: Maybe the Copilot is making a mistake. I suggest you to get a STM32F4Discovery board and test it before applying your patch. |
Ohh, |
Ahhh ok, one limitation was the wav file had to be in an specific sampling rate otherwise it didn't work, maybe if this solution works with any format, it will be nice |
yeah, exactly! that's the limitation i was trying to address. In the rn nxplayer path, the WAV sample rate isn't extracted before playback, so it falls back to the default... (smth 48 khz ig), My change reads the sample rate from the WAV header and checks whether the audio device supports it before starting playback. |
|
@casaroli Thanks for the review! I've addressed the requested changes and pushed the updates... |
casaroli
left a comment
There was a problem hiding this comment.
Fix: squash ad649e5 into ad73730.
- The title and the body say that the PR adds WAV playback, but nxplayer plays WAV files on master. The body does not say that devices without
AUDIO_SUBFMT_PCM_S16_LEget the whole file, or that unsupported WAV files are now rejected.
Fix: describe the change against master (header parsing and the sample rate from the header on S16_LE devices, the whole file on other devices) and the tests of both paths.
|
@imeghar2408-max please update your upstream and rebase your branch with it to fix the CI issue |
Pass the player context to decoder pre-parse and fill callbacks, and allow pre-parse callbacks to select the playback subformat. Update the existing PCM, MP3, and SBC callbacks to use the common interface. Assisted-by: ChatGPT:GPT-6 Signed-off-by: Megha Rajput <i.meghar.2408@gmail.com>
ad649e5 to
b389c3b
Compare
|
Hi @casaroli, thanks for the detailed review! |
b389c3b to
b3acb50
Compare
casaroli
left a comment
There was a problem hiding this comment.
Commit b3acb50 also has style changes in code it does not change (six int errcode = errno; blocks, an indent in nxplayer_playthread(), struct sockaddr_in) and the AUDIOIOC_RELEASE fix in the error path, which applies to every format.
Fix: move these to their own commit before the WAV commit.
The run on a pcm_decode board that I asked for on 11-01 is not necessary: pcm_decode over audio_null under QEMU plays stereo and mono files with this PR.
b3acb50 to
6542ae7
Compare
6542ae7 to
6c38233
Compare
casaroli
left a comment
There was a problem hiding this comment.
Commit 6c38233 still removes the blank line after DEBUGASSERT(errcode > 0); in nxplayer_enqueuebuffer(), nxplayer_fforward() and nxplayer_rewind() of system/nxplayer/nxplayer.c; b143f1f keeps it there.
Fix: drop these three hunks from 6c38233.
The message of b143f1f has Co-authored-by: Copilot and no Assisted-by:. CONTRIBUTING 1.5 requires Assisted-by: AGENT_NAME:MODEL_VERSION above the signature on every commit that used such a tool.
Fix: add the Assisted-by: line above Signed-off-by in b143f1f.
Release the audio device on setup failures only when the reserve operation succeeded. Keep generic playback formatting changes separate from WAV support. Assisted-by: Copilot Signed-off-by: Megha Rajput <i.meghar.2408@gmail.com>
Parse RIFF/WAVE headers to obtain sample rate, channel count, and sample format for PCM S16_LE playback. Preserve whole-file PCM fallback for devices that parse WAV headers themselves, and rewind seekable input when parsing fails. Assisted-by: ChatGPT:GPT-6 Signed-off-by: Megha Rajput <i.meghar.2408@gmail.com>
6c38233 to
8bd7ef2
Compare
@casaroli Thanks for the review! |
system/nxplayer: Parse WAV headers and retain PCM fallback
Improve the existing WAV playback implementation in
system/nxplayerby parsing RIFF/WAVE headers and using the audio parameters specified in supported WAV files.The implementation supports PCM 16-bit mono and stereo WAV files through the existing audio playback path. It validates RIFF chunks, format parameters, chunk boundaries, and data lengths before playback.
It also preserves compatibility with devices that use
pcm_decodeto parse WAV headers internally, retains the existing raw PCM playback path, and reports read errors during WAV playback cleanup.Summary
Update the existing WAV playback path to handle WAV files with RIFF chunks and use the sample rate and channel information specified in their headers.
For devices reporting
AUDIO_SUBFMT_PCM_S16_LE, nxplayer parses the WAV header, extracts the audio parameters, and configures playback accordingly.For devices that do not report
AUDIO_SUBFMT_PCM_S16_LE, the existing whole-file PCM decoder path is preserved so thatpcm_decodecan parse the WAV header itself.When WAV parsing fails, nxplayer falls back to the existing PCM decoder when the original input can be safely replayed.
Changes
AUDIOIOC_CONFIGUREto report unsupported configurations.AUDIOIOC_CONFIGUREfor channel configuration errors.nxplayer_wav_rate_cap()local tonxplayer_wav.c.Commit structure
The changes are split into three commits:
system/nxplayer: Refactor decoder callback interface.system/nxplayer: Fix reserve cleanup and formattingsystem/nxplayer: Parse WAV headers and retain PCM fallbackValidation
1. SIM-ALSA build
Build command:
Relevant build output:
Result: Build, linking, and packaging completed successfully with the updated nxplayer sources.
2. Valid WAV playback
Test command:
Result: Audio playback was audible.
3. WAV playback with odd-sized RIFF chunks
Test command:
The WAV file contains an odd-sized
JUNKchunk.Result: Audio playback was audible.
4. Malformed WAV files and PCM fallback
Truncated WAV file
Result: No audible playback.
Incomplete EOF
Result: No audible playback.
Invalid RIFF length
Result: Audio playback was audible through the existing PCM fallback path.
Playback recovery after fallback
Result: Audio playback was audible, confirming that normal playback worked after the fallback test.
5. Raw PCM playback
Test command:
Result: Audio playback was audible. The existing raw PCM playback path remains functional.
6. Read error during WAV playback
During a playback test, the WAV file was truncated while playback was in progress.
Observed output:
After entering
q, the application returned to the NSH prompt.Result: The read error was reported and playback exited cleanly.
7. Configuration checks
The following combinations of
CONFIG_AUDIO_FORMAT_PCMandCONFIG_NXPLAYER_FMT_FROM_EXTpassed syntax checks:8. Checkpatch, Nxstyle, and whitespace checks
The changed files were checked using:
Both modified C files also passed
nxstyle.For the final commit series, the following checks were run:
Result: All checks passed. No whitespace errors were reported.
Review follow-up — 4 November 2026
The following review feedback has been addressed:
max_channelsrejection. Channel configuration is now determined by the result ofAUDIOIOC_CONFIGURE.nxplayer_wav_rate_cap()a file-local static function innxplayer_wav.cand removed its declaration frominclude/system/nxplayer.h.PCM decoder validation
The reviewer confirmed that
pcm_decodeoveraudio_nullunder QEMU successfully plays both mono and stereo WAV files with this PR.The reviewer also confirmed that separate physical-board validation is not necessary.
Note: This QEMU validation was confirmed by the reviewer; it was not independently reproduced as part of my local SIM-ALSA tests.
Assisted-by: OpenAI:GPT-6