Skip to content

Conversation

@CamiWilliams
Copy link
Contributor

@CamiWilliams CamiWilliams commented Oct 28, 2019

Added functionality for SoX capabilities.

See comment in issue #260 for details.

Gain : Apply amplification or attenuation to the audio signal.

def gain(waveform, gain_db=1.0):
    # type: (Tensor, float) -> Tensor

Scale to Interval : Scales waveform to an interval.

def scale_to_interval(waveform, interval=1.0):
    # type: (Tensor, float) -> Tensor

Dither: Maximize the dynamic range of audio stored at a particular bit-depth.

def dither(waveform, probability_density_function="TPDF", noise_shaping=False, ns_filter=""):
    # type: (Tensor, str, bool, str) -> Tensor

Updated VCTK dataset code to replace SoX

E.append_effect_to_chain("gain", ["-h"])
E.append_effect_to_chain("channels", [1])
E.append_effect_to_chain("rate", [16000])
E.append_effect_to_chain("gain", ["-rh"])
E.append_effect_to_chain("dither", ["-s"])

is equivalent to

wf_vctk, sr_vctk = torchaudio.load(test_filepath_vctk)
sample = T.Resample(sr_vctk, 16000, resampling_method='sinc_interpolation')
wf_vctk = sample(wf_vctk)
wf_vctk = F.dither(wf_vctk, noise_shaping=True)

@cpuhrsch cpuhrsch changed the title Initial commit for gain [WIP] Initial commit for gain Oct 28, 2019
@vincentqb
Copy link
Contributor

See comment in #260 for VCTK.

@CamiWilliams CamiWilliams changed the title [WIP] Initial commit for gain [WIP] Add standalone SoX capabilities to functional.py Oct 31, 2019
@CamiWilliams CamiWilliams force-pushed the gain-rewrite branch 2 times, most recently from e45a9cb to 7ea82de Compare November 5, 2019 23:52
@CamiWilliams CamiWilliams force-pushed the gain-rewrite branch 2 times, most recently from 504f587 to 8f3723d Compare November 13, 2019 00:22
@cpuhrsch cpuhrsch changed the title [WIP] Add standalone SoX capabilities to functional.py [WIP] Add functionals gain, dither, scale_to_interval Nov 13, 2019

def probability_distribution(waveform, density_function="TPDF"):
# type: (Tensor, str) -> Tensor
r"""Apply a probability distribution function on a 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 should just be an internal function, and it in fact does the core of applying dither. Let's rename this to _apply_dither.

nit: "Apply dither to the waveform using the chosen density function."

Copy link
Contributor

Choose a reason for hiding this comment

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

I see this comment marked as resolved. What was the resolution of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just pushed the change, I renamed it to _apply_probability_distribution. How does that sound?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And this comment... should I still rename to "apply dither"?

@CamiWilliams CamiWilliams changed the title [WIP] Add functionals gain, dither, scale_to_interval Add functionals gain, dither, scale_to_interval Nov 27, 2019
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.

It's almost good to go. As mentioned in the comments:

  • Let's use a file different from a sine wave for testing, see other assets.
  • Let's remove scale_to_interval from this PR.
  • Let's make probability_distribution private with a different name like _apply_dither.


def probability_distribution(waveform, density_function="TPDF"):
# type: (Tensor, str) -> Tensor
r"""Apply a probability distribution function on a waveform.
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this comment marked as resolved. What was the resolution of this?

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! Good job, I'm merging!

@vincentqb vincentqb merged commit 2c7fdcc into pytorch:master Dec 2, 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