diff --git a/FlashSR/Util/UtilAudioLowPassFilter.py b/FlashSR/Util/UtilAudioLowPassFilter.py index 31a5ae1..657e904 100755 --- a/FlashSR/Util/UtilAudioLowPassFilter.py +++ b/FlashSR/Util/UtilAudioLowPassFilter.py @@ -37,14 +37,18 @@ def lowpass(audio:ndarray, #[time] 1d array @staticmethod def lowpass_filter(x:ndarray, #[time] 1d array - highcutoff_freq:float, #high cutoff frequency - fs:int, - order:int, #the order of filter - ftype:Literal['butter', 'cheby1', 'cheby2', 'ellip', 'bessel'], - upsample_to_original:bool = True - ) -> ndarray: #[time] 1d array + highcutoff_freq:float, #high cutoff frequency + fs:int, + order:int, #the order of filter + ftype:Literal['butter', 'cheby1', 'cheby2', 'ellip', 'bessel'], + upsample_to_original:bool = True + ) -> ndarray: #[time] 1d array nyq = 0.5 * fs + # Ensure hi is between 0 and 1 (exclusive) hi = highcutoff_freq / nyq + hi = min(hi, 0.999) # Clamp to just below 1 + hi = max(hi, 0.001) # Clamp to just above 0 + if ftype == "butter": sos = butter(order, hi, btype="low", output="sos") elif ftype == "cheby1": @@ -106,4 +110,4 @@ def subsampling(data, lowpass_ratio, fs_ori=44100, upsample_to_original:bool = T if __name__ == "__main__": util = UtilAudioLowPassFilter() - util.lowpass(np.zeros(24000),48000, filter_name="cheby", filter_order=8, cutoff_freq=8000) \ No newline at end of file + util.lowpass(np.zeros(24000),48000, filter_name="cheby", filter_order=8, cutoff_freq=8000)