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

mu-law companding #1022

Merged
merged 2 commits into from
Dec 10, 2019
Merged

mu-law companding #1022

merged 2 commits into from
Dec 10, 2019

Conversation

bmcfee
Copy link
Member

@bmcfee bmcfee commented Nov 26, 2019

Reference Issue

Related to #1007 , but different.
[EDIT by @lostanlen: closes #1034]

What does this implement/fix? Explain your changes.

This PR implements mu-law compression and expansion, with and without quantization.

Any other comments?

A couple of things to consider here:

  • Should we also add A-law companding? Does anyone even use it?
  • Would it make sense to separate the quantization parameter from the compression parameter? Right now, it quantizes to lg(1+mu) bits, which derives from the common setting of mu=255 and 8-bit quantization. But there's technically no reason that these things have to be tied together.
  • Should we worry about dtype inference based on the number of quantization levels? Numpy doesn't make it totally trivial to infer the minimum dtype for a given value range, but it's something we could do with a bit of work. It just seems wasteful to use int64 to hold 8-bit quantized values.

@bmcfee bmcfee added the functionality Does this add new functionality? label Nov 26, 2019
@bmcfee bmcfee added this to the 0.8.0 milestone Nov 26, 2019
@lostanlen
Copy link
Contributor

Thanks for doing this. It looks great but i'm curious as to the practical purpose. Given that all of this operates on IEEE 754 arithmetic, i doubt it reflects the effect of mu law in practice (e.g. audio sensing with limited resources)

Suppose that i have a WAV file in PCM (~fixed-point) format, encoded with a bit depth of 16 (or 24, or 32, etc.)
Suppose that i want to simulate how 8-bit compression affects the audio quality of that file upon listening to it.
How do i do this in librosa?

@bmcfee
Copy link
Member Author

bmcfee commented Nov 26, 2019

Suppose that i want to simulate how 8-bit compression affects the audio quality of that file upon listening to it.
How do i do this in librosa?

z = librosa.mu_compress(y, quantize=True)
y_compand = librosa.mu_expand(z, quantize=True)

I don't think we need to go as far as to add an explicit compand shortcut function, but above should do the trick,

@bmcfee
Copy link
Member Author

bmcfee commented Nov 27, 2019

One more question raised offline: should quantization be the default behavior? Or are there more compelling use cases for continuous mu compression?

@bmcfee bmcfee mentioned this pull request Nov 27, 2019
19 tasks
@lostanlen lostanlen self-requested a review December 6, 2019 13:25
@lostanlen
Copy link
Contributor

LGTM. I would prefer quantize=True by default though. The main application of mu-law is to have it quantized, be it for storage or for multinomial modeling à la WaveNet. Furthermore, the quantization is actually non-trivial, with a call to np.digitize and a -int(mu + 1)//2 offset.

@bmcfee
Copy link
Member Author

bmcfee commented Dec 6, 2019

Ok, I'm onboard with quantizing by default.

Final question: i put this in the audio submodule, because it seemed like the most logical place. But I could also see it living under effects alongside preemphasis and other time-domain transformations. What do you think about migrating it there?

@lostanlen lostanlen mentioned this pull request Dec 6, 2019
@lostanlen
Copy link
Contributor

lostanlen commented Dec 9, 2019

I would prefer audio over effects. Although it is true that back-and-forth companding and expansion does result in an audible effect, it's not the main purpose of why we have it here.

Please merge at your convenience

@bmcfee
Copy link
Member Author

bmcfee commented Dec 10, 2019

I would prefer audio over effects. Although it is true that back-and-forth companding and expansion does result in an audible effect, it's not the main purpose of why we have it here.

Please merge at your convenience

Fair enough, thanks again!

Should we bump this up to the 0.7.2 release then?

@lostanlen lostanlen modified the milestones: 0.8.0, 0.7.2 Dec 10, 2019
@lostanlen
Copy link
Contributor

Sure. I just bumped it to 0.7.2

@bmcfee bmcfee merged commit 4743fff into master Dec 10, 2019
@bmcfee bmcfee deleted the mulaw branch December 10, 2019 17:00
@bmcfee bmcfee restored the mulaw branch December 10, 2019 17:21
@bmcfee
Copy link
Member Author

bmcfee commented Dec 10, 2019

whoops, forgot to set quantize=True to default. Fixing and then will merge again.

@bmcfee bmcfee mentioned this pull request Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
functionality Does this add new functionality?
Development

Successfully merging this pull request may close these issues.

μ-law companding
2 participants