Skip to content

parse WAV fmt chunk, downmix multi-channel to mono, widen file sizes …#864

Open
rajaamirapu wants to merge 1 commit intoSIPp:masterfrom
rajaamirapu:wavheader
Open

parse WAV fmt chunk, downmix multi-channel to mono, widen file sizes …#864
rajaamirapu wants to merge 1 commit intoSIPp:masterfrom
rajaamirapu:wavheader

Conversation

@rajaamirapu
Copy link
Copy Markdown

fix(rtpstream): parse WAV fmt chunk, downmix multi-channel to mono, widen file sizes to int64_t

Problems Fixed

Problem 1 — WAV header parser ignored the fmt chunk
get_wav_header_size() only scanned for the start of the data chunk
and never read NumChannels, BitsPerSample, or SampleRate. Stereo
(or higher) files were forwarded as raw interleaved bytes, producing
heavily distorted audio at 2× (or worse) the correct duration.

Problem 2 — File sizes capped at ~2 GB
cached_file_t::filesize, cached_pattern_t::filesize, and all
playback-tracking fields in taskentry_t
(audio/video_file_num_bytes, audio/video_file_bytes_left,
new_audio/video_file_size) were declared as int (32-bit signed),
capping supported file size at ~2 GB — reached even sooner with
multi-channel or high-rate formats.


Changes

File Change
include/rtpstream.hpp Added #include <stdint.h>; widened 6 int fields in taskentry_t to int64_t
src/rtpstream.cpp Replaced get_wav_header_size(); added parse_wav_header() and wav_downmix_to_mono(); updated rtpstream_cache_file() and rtpstream_play(); widened filesize in both cache structs to int64_t
  • parse_wav_header() — walks all RIFF chunks and extracts
    NumChannels, BitsPerSample, SampleRate, and the exact
    data-chunk byte offset from the fmt chunk.
  • wav_downmix_to_mono() — averages interleaved channels to mono
    at cache time; supports 8-bit unsigned and 16-bit signed PCM.
  • cached_file_t::wav_processed flag — WAV stripping and downmix
    now happen once in rtpstream_cache_file(); rtpstream_play() skips
    all header logic for already-processed files.
  • All processed paths produce a fresh malloc

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