Commit 338d38a2 authored by Joao Gomes's avatar Joao Gomes Committed by Facebook GitHub Bot
Browse files

Adding warnings in mu_law* for the wrong input type (#2034)

Summary:
Addresses  https://github.com/pytorch/audio/issues/1493

cc mthrok hwangjeff

Pull Request resolved: https://github.com/pytorch/audio/pull/2034

Reviewed By: hwangjeff

Differential Revision: D32807006

Pulled By: mthrok

fbshipit-source-id: badf148646c5f768328c5a4e51bd6016b0be46f3
parent 7ac525e7
......@@ -612,7 +612,7 @@ def mu_law_encoding(
r"""Encode signal based on mu-law companding. For more info see the
`Wikipedia Entry <https://en.wikipedia.org/wiki/%CE%9C-law_algorithm>`_
This algorithm assumes the signal has been scaled to between -1 and 1 and
This algorithm expects the signal has been scaled to between -1 and 1 and
returns a signal encoded with values from 0 to quantization_channels - 1.
Args:
......@@ -624,6 +624,8 @@ def mu_law_encoding(
"""
mu = quantization_channels - 1.0
if not x.is_floating_point():
warnings.warn("The input Tensor must be of floating type. \
This will be an error in the v0.12 release.")
x = x.to(torch.float)
mu = torch.tensor(mu, dtype=x.dtype)
x_mu = torch.sign(x) * torch.log1p(mu * torch.abs(x)) / torch.log1p(mu)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment