Thanks to the very useful Google Chrome team, I figured this out. Here's what they said:
Hi, Brad, it looks like the sample data is outside of the actual range. For this API, full-scale floating-point PCM audio data should be between -1.0 โ +1.0
Perhaps your data values โโare 16 bits (-32768 โ +32767).
Therefore, when I create my byte array, I need to make sure that everything is represented as decimal. So instead:
byte[] buffer = new byte[]{ 56, -27, 88, -29, 88, ............ };
I really needed something like:
byte[] buffer = new byte[]{ 0.023, -0.1, 0.125, -0.045, ............ };
So, in my code, I just added some logic to convert 16-bit scaled values โโto the appropriate range, for example:
for(var i=0;i<buffer.length;i++) { var b = buffer[i]; b = (b>0)?b/32767:b/-32768; buffer[i] = b; }
The sound is now represented as decimal and no longer sounds like a distorted heavy metal song.
Brad rydzewski
source share