Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions audio_filters/butterworth_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@
) -> IIRFilter:
"""
Creates a low-pass filter

>>> filter = make_lowpass(1000, 48000)
>>> filter.a_coeffs + filter.b_coeffs # doctest: +NORMALIZE_WHITESPACE
[1.0922959556412573, -1.9828897227476208, 0.9077040443587427, 0.004277569313094809,
0.008555138626189618, 0.004277569313094809]
... (docstring content)
"""
# --- Input Validation Start ---
if samplerate <= 0:
raise ValueError("Samplerate must be a positive value.")
if frequency <= 0:
raise ValueError("Frequency must be a positive value.")
if frequency >= samplerate / 2:
# Nyquist frequency limit check
raise ValueError(
f"Frequency ({frequency} Hz) must be less than the Nyquist frequency ({samplerate / 2} Hz)."

Check failure on line 30 in audio_filters/butterworth_filter.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

audio_filters/butterworth_filter.py:30:89: E501 Line too long (104 > 88)

Check failure on line 30 in audio_filters/butterworth_filter.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (EM102)

audio_filters/butterworth_filter.py:30:13: EM102 Exception must not use an f-string literal, assign to variable first

Check failure on line 30 in audio_filters/butterworth_filter.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

audio_filters/butterworth_filter.py:30:89: E501 Line too long (104 > 88)

Check failure on line 30 in audio_filters/butterworth_filter.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (EM102)

audio_filters/butterworth_filter.py:30:13: EM102 Exception must not use an f-string literal, assign to variable first
)
# --- Input Validation End ---

w0 = tau * frequency / samplerate
_sin = sin(w0)
_cos = cos(w0)
Expand Down
2 changes: 1 addition & 1 deletion audio_filters/equal_loudness_filter.py.broken.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class EqualLoudnessFilter:
self.butterworth_filter = make_highpass(150, samplerate)

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

# Convert to angular frequency
Expand Down
Loading