-
Notifications
You must be signed in to change notification settings - Fork 14
PCM16 distortion #10
Comments
I don't understand the fix. This doesn't solve the problem. Example: Why not just use: |
I had a look at how Google Chrome and Firefox decode WAV files with AudioContext.decodeAudioData():
Chrome uses an asymmetric scheme, like you currently do, and can encode the float value 1. Why not map the integer range -32768 .. +32767 to the float range -1.0000305185 .. +1? This would be symmetric and encoding of the float value 1 would be possible. |
It seems to me that is decoder problem. |
I agree, The problem occurs when the encoder and decoder do not use the same mapping between float (-1 to 1) and int (-32768 to 32767). Your encoder and decoder use the same mapping as the decoder of Google Chrome, but Firefox is different. |
This issue move to mohayonao/wav-decoder#14. |
The same "symmetric" option would also make sense for the encoder. |
How do encoder map values with symmetric options with int16?
|
|
Thanks. I can't accept "symmetric V1". The code of "symmetric V2" is below? I agree that is not bad as optional variation. function encode_pcm16(value) {
value = Math.max(-1, Math.min(value, +1));
return Math.min(Math.round(value * 32768), 32767);
}
|
or shorter: function encode_pcm16(value) {
return Math.max(-32768, Math.min(32767, Math.round(value * 32768)));
} |
Okay. I've implemented and merged it to v1.3.0. Thanks. |
Thanks for your work. |
For the PCM16 format, negative sample values are multiplied by 32768, but positive sample values are multiplied by 32767. This leads to a small distortion.
Consider the following symmetrical float signal without a DC value: 0, 0.5, 0, -0.5, 0
The values written to the WAV file are: 0, 16383, 0, -16384, 0
(0.5 * 32767)|0 ==> 16383
(-0.5 * 32768)|0 ==> -16384
The text was updated successfully, but these errors were encountered: