Improved handling of EQ when fs=44.1k a bit, including suggestion to use 48k

This commit is contained in:
Casper Jansen 2023-01-05 17:06:32 +01:00
parent 24b9a24b04
commit eedd6d83b4

View File

@ -85,8 +85,8 @@ class FilterBankDesigner:
if self.nominal_txt(x) == nom_txt: if self.nominal_txt(x) == nom_txt:
return x return x
raise ValueError( raise ValueError(
f'Could not find a nominal frequency corresponding to {nom_txt}. Hint: use \'5k\' instead of \'5000\'.' f'Could not find a nominal frequency corresponding to {nom_txt}. '
) 'Hint: use \'5k\' instead of \'5000\'.')
def sanitize_input(self, input_): def sanitize_input(self, input_):
if isinstance(input_, int): if isinstance(input_, int):
@ -254,8 +254,8 @@ class FilterBankDesigner:
for i, x in enumerate(range(xl, xu + 1)): for i, x in enumerate(range(xl, xu + 1)):
fl = self.fl(x) fl = self.fl(x)
fu = self.fu(x) fu = self.fu(x)
# Find the indices in the frequency array which correspond to the # Find the indices in the frequency array which correspond to
# frequency band x # the frequency band x
if x != xu: if x != xu:
indices_cur = np.where((freq >= fl) & (freq < fu)) indices_cur = np.where((freq >= fl) & (freq < fu))
else: else:
@ -337,13 +337,13 @@ class OctaveBankDesigner(FilterBankDesigner):
Args: Args:
x: Filter offset power from the reference frequency of 1000 Hz. x: Filter offset power from the reference frequency of 1000 Hz.
filter_class: Either 0 or 1, defines the tolerances on the frequency filter_class: Either 0 or 1, defines the tolerances on the
response frequency response
Returns: Returns:
freq, llim, ulim: Tuple of Numpy arrays containing the frequencies of freq, llim, ulim: Tuple of Numpy arrays containing the frequencies
the corner points of the filter frequency response limits, lower limits of the corner points of the filter frequency response limits, lower
in *deciBell*, upper limits in *deciBell*, respectively. limits in *deciBell*, upper limits in *deciBell*, respectively.
""" """
b = 1 b = 1
@ -450,8 +450,8 @@ class OctaveBankDesigner(FilterBankDesigner):
if int(self.fs) in [44100, 48000, 96000]: if int(self.fs) in [44100, 48000, 96000]:
return 1.0 return 1.0
else: else:
raise ValueError('Unimplemented sampling frequency for SOS' raise ValueError('Unimplemented sampling frequency \'{} Hz\' for '
'filter design') 'SOS filter design. Try 48 kHz.'.format(self.fs))
def sosFac_u(self, x): def sosFac_u(self, x):
"""Right side percentage of change in cut-on frequency for designing """Right side percentage of change in cut-on frequency for designing
@ -463,8 +463,8 @@ class OctaveBankDesigner(FilterBankDesigner):
if int(self.fs) in [44100, 48000, 96000]: if int(self.fs) in [44100, 48000, 96000]:
return 1.0 return 1.0
else: else:
raise ValueError('Unimplemented sampling frequency for SOS' raise ValueError('Unimplemented sampling frequency \'{} Hz\' for '
'filter design') 'SOS filter design. Try 48 kHz.'.format(self.fs))
class ThirdOctaveBankDesigner(FilterBankDesigner): class ThirdOctaveBankDesigner(FilterBankDesigner):
@ -511,13 +511,13 @@ class ThirdOctaveBankDesigner(FilterBankDesigner):
Args: Args:
x: Filter offset power from the reference frequency of 1000 Hz. x: Filter offset power from the reference frequency of 1000 Hz.
filter_class: Either 0 or 1, defines the tolerances on the frequency filter_class: Either 0 or 1, defines the tolerances on the
response frequency response
Returns: Returns:
freq, llim, ulim: Tuple of Numpy arrays containing the frequencies of freq, llim, ulim: Tuple of Numpy arrays containing the frequencies
the corner points of the filter frequency response limits, lower limits of the corner points of the filter frequency response limits, lower
in *deciBell*, upper limits in *deciBell*, respectively. limits in *deciBell*, upper limits in *deciBell*, respectively.
""" """
fm = self.G**(x / self.b) * self.fr fm = self.G**(x / self.b) * self.fr
@ -605,16 +605,16 @@ class ThirdOctaveBankDesigner(FilterBankDesigner):
# Idea: correct for frequency warping: # Idea: correct for frequency warping:
if np.isclose(self.fs, 48000): if np.isclose(self.fs, 48000):
return 1.00 return 1.00
elif np.isclose(self.fs, 41000): elif np.isclose(self.fs, 44100):
warnings.warn( warnings.warn(f'Sampling frequency {self.fs} Hz might result in '
f'Frequency {self.fs} might not result in correct filters') 'incorrect filters')
return 1.00 return 1.00
elif np.isclose(self.fs, 32768): elif np.isclose(self.fs, 32768):
return 1.00 return 1.00
else: else:
raise ValueError('Unimplemented sampling frequency for SOS' raise ValueError('Unimplemented sampling frequency \'{} Hz\' for '
'filter design') 'SOS filter design. Try 48 kHz.'.format(self.fs))
def sosFac_u(self, x): def sosFac_u(self, x):
"""Right side percentage of change in cut-on frequency for designing """Right side percentage of change in cut-on frequency for designing
the filter.""" the filter."""
@ -623,5 +623,5 @@ class ThirdOctaveBankDesigner(FilterBankDesigner):
elif np.isclose(self.fs, 32768): elif np.isclose(self.fs, 32768):
return 1.00 return 1.00
else: else:
raise ValueError('Unimplemented sampling frequency for SOS' raise ValueError('Unimplemented sampling frequency \'{} Hz\' for '
'filter design') 'SOS filter design. Try 48 kHz.'.format(self.fs))