Skip to content

Decode mu-law and A-law WAV files before resampling - #30

Merged
calebtt merged 1 commit into
masterfrom
fix/play-mulaw-wav
Sep 26, 2026
Merged

calebtt merged 1 commit into
masterfrom
fix/play-mulaw-wav

Conversation

@calebtt

@calebtt calebtt commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #29.

sipbot serve's play rejected 8 kHz μ-law WAV files ("not a readable WAV … decode produced no PCM"), although AGENTS.md and --help say μ-law is accepted. AudioAlgos passed the WaveFileReader to NAudio's ToSampleProvider(), which only takes PCM and IEEE float and throws "Unsupported source encoding" on G.711 data.

Changes

  • AudioAlgos.WavSampleProvider (private): decodes μ-law and A-law WAV data to 16-bit PCM with NAudio's managed MuLawDecoder / ALawDecoder, then builds the sample provider. Other encodings go to ToSampleProvider() as before.
  • Used by all three WAV readers: ConvertWavToPcm (sipbot play), ReadWelcomeWavBytesAsPcmu, and ReadWelcomeWavBytesAsPcm16kHz.
  • No public API change.

Tests

WavDecodeTests (8 tests):

  • μ-law and A-law decode at the same rate (each sample within one step of the reference decoder).
  • Both resample to 16 kHz.
  • 16-bit PCM WAVs still read the same.
  • ReadWelcomeWavBytesAsPcmu reads a μ-law file and ReadWelcomeWavBytesAsPcm16kHz reads an A-law file.
  • AgentAudioEndPoint.PlayWav accepts a μ-law file, which is the reported symptom.

Without the fix, 7 of the 8 fail; the PCM check passes either way. The full suite passes: 114/114.

Live check against a VitalPBX (Asterisk 20.14) lab PBX, extension to extension. A sipbot serve built from this branch played an 8 kHz μ-law WAV written by ffmpeg into an answered call. v0.1.5 had returned the error above for the same file. The far end's recording matched the clip: correlation 0.997, and 1.000 in every 1 s window.

🤖 Generated with Claude Code

sipbot serve's play command rejected 8 kHz mu-law WAV files with "not a
readable WAV ... decode produced no PCM", although AGENTS.md and --help say
mu-law is accepted. AudioAlgos passed the WaveFileReader to NAudio's
ToSampleProvider(), which only takes PCM and IEEE float and throws
"Unsupported source encoding" for G.711 data.

WAV readers now go through WavSampleProvider, which decodes mu-law and
A-law data to 16-bit PCM with NAudio's managed decoders first. This covers
ConvertWavToPcm (sipbot play) and both ReadWelcomeWav* helpers.

Closes #29

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SGcDAANyU5QKVK2Vtur1xc
@calebtt
calebtt merged commit 09ea3d7 into master Sep 26, 2026
2 checks passed
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.

sipbot play rejects mu-law WAV files

1 participant