Skip to content

Add peaking equalizer filter #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 1, 2019
Merged

Conversation

xinyang0
Copy link
Contributor

Add peaking equalizer filter in functional.py and test it in test_functional_filter.py.

@vincentqb
Copy link
Contributor

Thanks for working on this! For convenience, let's also add a reference in the pull request to the other one: #260.

@vincentqb vincentqb self-requested a review October 25, 2019 21:25
Copy link
Contributor

@vincentqb vincentqb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

@@ -683,6 +684,36 @@ def lowpass_biquad(waveform, sample_rate, cutoff_freq, Q=0.707):
return biquad(waveform, b0, b1, b2, a0, a1, a2)


def equalizer_biquad(waveform, sample_rate, center_freq, Q, gain):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we give the same default value to Q as other filters?

Good you are using the same notation as other transforms :) If I could go back in time, I'd rename Q to q_factor to be more transparent, and to avoid using a single capital letter as a parameter name. If we decide to go ahead, this would be in a separate PR afterward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sox sets default value of Q=0.707 in high pass and low pass filters which gives a Butterworth response. There is no such special case in peaking equalizer, so sox doesn't give default values to Q. See http://sox.sourceforge.net/sox.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth setting default values for some of these arguments, even if we define them ourselves. Having a sane default always makes it easier to use a function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a default value for Q=0.707

mult = _dB2Linear(max(gain, 0))

if A == 1:
return waveform
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens when gain is zero. Why is this a special case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. Sox has this special case, but removing it doesn't affect our result.

"""

CENTER_FREQ = 1000
Q = 0.707
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a chance that these values are special and miss something important?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! The specgram of the white noise signal is actually in the range of [0, 578], so 1000 is a bit large for this signal. Decrease it to 300.

sample_rate (int): sampling rate of the waveform, e.g. 44100 (Hz)
center_freq (float): filter’s central frequency
Q (float): https://en.wikipedia.org/wiki/Q_factor
gain (float): desired gain at the boost (or cut)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The units for gain are dB, right?

What do you think of "attenuation" instead of "cut"?

Q = 0.707
GAIN = 1

noise_filepath = os.path.join(self.test_dirpath, "assets", "whitenoise.mp3")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vincentqb instead of calling into sox while testing, should we write out reference files instead? especially since the asset is fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree with you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this could be done in a separate PR for all the other tests too.

@@ -683,6 +684,36 @@ def lowpass_biquad(waveform, sample_rate, cutoff_freq, Q=0.707):
return biquad(waveform, b0, b1, b2, a0, a1, a2)


def equalizer_biquad(waveform, sample_rate, center_freq, Q, gain):
# type: (Tensor, int, float, float, float) -> Tensor
r"""Designs biquad peaking equalizer filter and performs filtering. Similar to SoX implementation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure its necessary to mention that this is similar to Sox. Its a well-defined operation that stands by itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. It's mentioned in the other transforms, so we'll have to remove it elsewhere too.

@cpuhrsch
Copy link
Contributor

This PR also raises questions around general jit support, since many of the referenced and surrounding functions don't seem to be decorated as such.

However, overall, it's in tune with the current setup and seems correct. I'm happy to merge this!

…req from 1000 to 300 in test_functional_filtering.py
Copy link
Contributor

@vincentqb vincentqb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for working on this! We'll create a new PR for jit support.

@vincentqb vincentqb merged commit 6d5f0b4 into pytorch:master Nov 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants