Skip to content

Use WAV file sample rate unless user explicitly set samprate#448

Merged
dhdaines merged 1 commit intomainfrom
wav-samprate-fix
Dec 1, 2025
Merged

Use WAV file sample rate unless user explicitly set samprate#448
dhdaines merged 1 commit intomainfrom
wav-samprate-fix

Conversation

@lenzo-ka
Copy link
Contributor

@lenzo-ka lenzo-ka commented Nov 21, 2025

Problem

WAV files with non-default sample rates (e.g., 8kHz, 24kHz, 32kHz, 48kHz) were being silently ignored. The code checked if samprate == 0 before applying the WAV file's sample rate, but samprate defaults to 16000, causing the check to always fail.

Solution

Added a helper function arg_was_set() that checks if -samprate was actually passed on the command line by inspecting the stored argv. The WAV file's sample rate is now used unless the user explicitly provided -samprate.

Behavior

Before:

  • WAV file at 48kHz processed as 16kHz (incorrect)
  • User had to manually specify -samprate 48000 for correct processing

After:

  • WAV file at 48kHz automatically processed at 48kHz (correct)
  • User can still override with -samprate if desired

Changes

  • Modified src/util/soundfiles.c (1 file, +19/-2 lines)
  • Added arg_was_set() helper function to check command line arguments
  • Updated ps_config_wavfile() to properly detect user intent

Testing

Tested with WAV files at various sample rates. Confirmed that:

  • Files without -samprate flag use WAV file rate
  • Files with -samprate flag respect user's choice
  • Warning is shown when user's rate differs from WAV file

Fixes issue where WAV file sample rates were ignored because the check
for 'samprate == 0' always failed (samprate defaults to 16000).

Now checks if -samprate was actually passed on the command line. If not,
uses the WAV file's sample rate. If user explicitly set it, respects
their choice.

This allows WAV files with any sample rate (8kHz, 24kHz, 32kHz, 48kHz,
etc.) to be processed correctly without requiring users to manually
specify -samprate.
@lenzo-ka lenzo-ka requested a review from dhdaines November 21, 2025 23:06
@dhdaines
Copy link
Contributor

dhdaines commented Dec 1, 2025

Oh! That is pretty silly, I'm not sure why I thought the default value for -samprate was zero...

@dhdaines dhdaines merged commit 677597e into main Dec 1, 2025
21 checks passed
@dhdaines dhdaines deleted the wav-samprate-fix branch December 1, 2025 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants