Skip to content
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

Centroid frequency limits #2061

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

jacobjwebber
Copy link

It was mentioned in #1059 that it might be good to support a narrow range of frequencies to find the spectral centroid. This is an attempt at that.

Apologies if this is not correct, it is my first attempt at a PR for pytorch/audio!

@facebook-github-bot
Copy link
Contributor

Hi @jacobjwebber!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Copy link
Collaborator

@mthrok mthrok left a comment

Choose a reason for hiding this comment

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

Hi @jacobjwebber

Thanks for the contribution. I think I understand the gist of the new logic, but can you add a test code that explains the desired behavior?

torchaudio/functional/functional.py Outdated Show resolved Hide resolved
max_freq_index = int(round((max_freq * fft_bins) / nyquist)) if max_freq is not None else fft_bins

if min_freq is not None or max_freq is not None:
assert min_freq_index < max_freq_index
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of checking the value here, the check on the given arguments should happen at the beginning of the argument.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I don't fully understand this. Would you mind explaining?

specgram = spectrogram(waveform, pad=pad, window=window, n_fft=n_fft, hop_length=hop_length,
win_length=win_length, power=1., normalized=False)
freqs = torch.linspace(0, sample_rate // 2, steps=1 + n_fft // 2,
device=specgram.device).reshape((-1, 1))

min_freq_index = int(round((min_freq * fft_bins) / nyquist)) if min_freq is not None else 0
max_freq_index = int(round((max_freq * fft_bins) / nyquist)) if max_freq is not None else fft_bins
Copy link
Collaborator

Choose a reason for hiding this comment

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

IIRC TorchScript does not handle ternary operator. Can you run pytest test/torchaudio_unittest/transforms/torchscript_consistency_cpu_test.py -k Centroid and see if it works?

Copy link
Author

Choose a reason for hiding this comment

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

Hi, this test seems to pass on my system. Should I still swap out the ternary?

@mthrok
Copy link
Collaborator

mthrok commented Dec 3, 2021

CircleCI is not getting triggered. Let me close and reopen the PR to see if it helps.

@mthrok mthrok closed this Dec 3, 2021
@mthrok mthrok reopened this Dec 3, 2021
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@jacobjwebber
Copy link
Author

Hi @mthrok, sorry for taking a little while to get back to you.

I added a test in batch_consistency_test.py for the new behaviour -- I am not sure if this is the right place.

The basic idea of why you would want this is that you might want the centroid of a specific range of frequencies. I used this recently because I only wanted the centroid of voiced frequencies.

A downside of accepting this is that it adds features that aren't present in librosa. I think this transform was initially intended to clone a function from that library

@jacobjwebber jacobjwebber changed the title Centroid_wip Centroid frequency limits Dec 9, 2021
mthrok pushed a commit to mthrok/audio that referenced this pull request Dec 13, 2022
All it needed is adding missing `deep_phonemizer` package to `requirements.txt`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants