Utils: cplay: Fix WAV header parsing for multi-channel (5.1/7.1) formats#32
Open
singalsu wants to merge 1 commit intoalsa-project:masterfrom
Open
Utils: cplay: Fix WAV header parsing for multi-channel (5.1/7.1) formats#32singalsu wants to merge 1 commit intoalsa-project:masterfrom
singalsu wants to merge 1 commit intoalsa-project:masterfrom
Conversation
Multi-channel WAV files (>2 channels) use WAVE_FORMAT_EXTENSIBLE (type 0xFFFE) with a larger fmt chunk that includes a channel mask and subformat GUID. The existing parser only handled basic PCM (type 0x0001), causing several issues with 5.1 (6ch) and 7.1 (8ch) content: - The fixed-size fread of struct wave_header (44 bytes) misaligned the data chunk read when the fmt chunk was larger than 16 bytes, resulting in audio data being read from the wrong file offset. - No chunk scanning was performed, so intermediate chunks (fact, LIST, PEAK) between fmt and data caused parse failures. - The WAV channel mask (speaker positions FL, FR, FC, LFE, BL, BR, SL, SR) was never extracted, so firmware received ch_mode=0 and could not determine the correct channel-to-speaker routing. Add parse_wave_file() that properly scans chunks, handles both basic PCM and WAVE_FORMAT_EXTENSIBLE formats, extracts the channel mask, and positions the file pointer at the start of audio data. For basic PCM files with >2 channels, a standard default channel mask is generated per the Microsoft WAV specification. The channel mask is passed to firmware via snd_codec.ch_mode so it can correctly map channels to speaker positions. Also add 24-bit sample format support (SNDRV_PCM_FORMAT_S24_LE). Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
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.
Multi-channel WAV files (>2 channels) use WAVE_FORMAT_EXTENSIBLE (type 0xFFFE) with a larger fmt chunk that includes a channel mask and subformat GUID. The existing parser only handled basic PCM (type 0x0001), causing several issues with 5.1 (6ch) and 7.1 (8ch) content:
The fixed-size fread of struct wave_header (44 bytes) misaligned the data chunk read when the fmt chunk was larger than 16 bytes, resulting in audio data being read from the wrong file offset.
No chunk scanning was performed, so intermediate chunks (fact, LIST, PEAK) between fmt and data caused parse failures.
The WAV channel mask (speaker positions FL, FR, FC, LFE, BL, BR, SL, SR) was never extracted, so firmware received ch_mode=0 and could not determine the correct channel-to-speaker routing.
Add parse_wave_file() that properly scans chunks, handles both basic PCM and WAVE_FORMAT_EXTENSIBLE formats, extracts the channel mask, and positions the file pointer at the start of audio data. For basic PCM files with >2 channels, a standard default channel mask is generated per the Microsoft WAV specification.
The channel mask is passed to firmware via snd_codec.ch_mode so it can correctly map channels to speaker positions. Also add 24-bit sample format support (SNDRV_PCM_FORMAT_S24_LE).