The IIRFilter class is used to generate and apply Infinite Impulse Response (IIR) filters to audio data. This is typically done to apply frequency weighting (like those required by loudness standards) before measuring loudness.
Parameters
When instantiating IIRFilter, provide the following arguments:
G (float): Gain of the filter in dB.Q (float): The Q factor of the filter.fc (float): Center frequency of the shelf in Hz.rate (float): Sampling rate in Hz.filter_type (str): The shape/type of the filter (see supported types below).passband_gain (float, optional): A multiplier applied to the filtered signal. Defaults to 1.0.
Supported filter_type values
Standard RBJ (Cookbook) filters:
'high_shelf''low_shelf''high_pass''low_pass''peaking''notch'
DeMan filters (for ITU specification compliance):
'high_shelf_DeMan''high_pass_DeMan'
Note: If you require full compliance with ITU specifications, use the 'DeMan' filter types.
from pyloudnorm.iirfilter import IIRFilter
# Example: Create a high-pass filter
filter = IIRFilter(G=0, Q=0.707, fc=100, rate=44100, filter_type='high_pass')
# Apply the filter to audio data
filtered_audio = filter.apply_filter(audio_data)