Skip to content

Commit

Permalink
Add test for A-weighted RMS value correct offset
Browse files Browse the repository at this point in the history
  • Loading branch information
endolith committed Oct 31, 2024
1 parent 0fe185c commit 2ec12f3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/test_wave_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,29 @@ def test_correctness(self, filename, expected_peak):
# These are all sine waves, which always have crest factor of 3 dB.
assert crest_factor_db == pytest.approx(3.01029995663, abs=0.6)

@pytest.mark.parametrize("filename, expected_level", [
("test-44100Hz-le-1ch-4bytes.wav", -3.01),
("test-8000Hz-le-2ch-1byteu.wav", -3.01),
("test-44100Hz-le-1ch-4bytes-early-eof.wav", -3.01),
])
def test_a_weighting_1khz(self, filename, expected_level):
"""Test that A-weighted RMS matches unweighted RMS for 1 kHz sine waves"""
result = run_wave_analyzer(filename)
assert result.returncode == os.EX_OK

rms_pattern = r"RMS level:.*\(([-\d.]+) dBFS\)"
a_weighted_pattern = r"RMS A-weighted:.*\(([-\d.]+) dBFS\(A\)"

rms_match = re.search(rms_pattern, result.stdout)
a_weighted_match = re.search(a_weighted_pattern, result.stdout)

rms_db = float(rms_match.group(1))
a_weighted_db = float(a_weighted_match.group(1))

# At 1 kHz, A-weighting should match unweighted, no 3 dB offset
# (Wider tolerance due to short file length)
assert a_weighted_db == pytest.approx(rms_db, abs=0.3)

@pytest.mark.parametrize("filename", [
"test-44100Hz-le-1ch-4bytes-incomplete-chunk.wav",
"test-44100Hz-le-1ch-4bytes-early-eof-no-data.wav",
Expand Down

0 comments on commit 2ec12f3

Please sign in to comment.