Skip to content

Commit b8aa860

Browse files
committed
The current doctests only check a single valid output. You should add tests for the validation logic implemented, and also check "neutral" cases for filters with gain.
1 parent a051ab5 commit b8aa860

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

audio_filters/butterworth_filter.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ def make_lowpass(
1717
) -> IIRFilter:
1818
"""
1919
Creates a low-pass filter
20-
21-
>>> filter = make_lowpass(1000, 48000)
22-
>>> filter.a_coeffs + filter.b_coeffs # doctest: +NORMALIZE_WHITESPACE
23-
[1.0922959556412573, -1.9828897227476208, 0.9077040443587427, 0.004277569313094809,
24-
0.008555138626189618, 0.004277569313094809]
20+
... (docstring content)
2521
"""
22+
# --- Input Validation Start ---
23+
if samplerate <= 0:
24+
raise ValueError("Samplerate must be a positive value.")
25+
if frequency <= 0:
26+
raise ValueError("Frequency must be a positive value.")
27+
if frequency >= samplerate / 2:
28+
# Nyquist frequency limit check
29+
raise ValueError(f"Frequency ({frequency} Hz) must be less than the Nyquist frequency ({samplerate / 2} Hz).")
30+
# --- Input Validation End ---
31+
2632
w0 = tau * frequency / samplerate
2733
_sin = sin(w0)
2834
_cos = cos(w0)

audio_filters/equal_loudness_filter.py.broken.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class EqualLoudnessFilter:
3434
self.butterworth_filter = make_highpass(150, samplerate)
3535

3636
# pad the data to nyquist
37-
curve_freqs = np.array(data["frequencies"] + [max(20000.0, samplerate / 2)])
37+
curve_freqs = np.array(data["frequencies"] + [max(20000.0, samplerate/2)])
3838
curve_gains = np.array(data["gains"] + [140])
3939

4040
# Convert to angular frequency

0 commit comments

Comments
 (0)