wavio icon indicating copy to clipboard operation
wavio copied to clipboard

normalize option added for scale parameter in `write`

Open nj-vs-vh opened this issue 2 years ago • 2 comments

My quick attempt to solve issues #12 and #13. Usage:

wavio.write("smth.wav", data, 44100, scale="normalize")

In this case the behavior mimics standard normalize feature found in any DAW: make audio as loud as possible while keeping zeroes at zero, i.e. avoiding DC offset. This may even be the default setting as it is the most fitting for dealing with recorded audio which is almost never symmetric.

Tests for the behavior are included.

nj-vs-vh avatar Sep 21 '21 11:09 nj-vs-vh

Would you be able to add a test for 24bit as well? Its not an uncommon bit rate in music.

I have just added one, though it really is similar to 32 and 16 bit as they both map analog zero to digital zero. One thing I just noticed is that writing 32-bit Numpy array to 24-bit .wav file results in hard clipping, not scaling down, but this seems to be preferred method for the library and I think I should not change that.

nj-vs-vh avatar Sep 21 '21 16:09 nj-vs-vh

Thanks for adding the test and for mentioning the 32 bit to 24 bit hard clipping.

Exitare avatar Sep 21 '21 16:09 Exitare

@nj-vs-vh, a very belated "thanks" for the contribution! Back when you submitted this, I was considering more radical changes to the API, based on feedback in other issues. After a long delay, I've finally implemented a new API. I just pushed the changes today. Those changes make this pull request obsolete, so I'm closing it. But I think you were right about "keeping zeros at zero"--that is what the new (and simplified) API does.

Note that the new changes are not backwards compatible, so if you are still using wavio, you'll probably have to make some changes to handle the new API.

WarrenWeckesser avatar Oct 15 '22 22:10 WarrenWeckesser