Raw sound byteArray for float Array

I am trying to convert a byteArray of an audio object to a floating point array. The sound object plays normally and full length, but the float array that I get from it is clipped (but it sounds right), so I have to do something wrong in the conversion:

var s:Sound = mySound;
s.play(); // plays fine

var bytes:ByteArray = new ByteArray();
bytes.endian = Endian.LITTLE_ENDIAN;
s.extract(bytes, s.bytesTotal, 0);

var leftChannel:Array = new Array();
var rightChannel:Array = new Array();

bytes.position = 0;

while (bytes.bytesAvailable)
{
    leftChannel.push(bytes.readFloat());
    rightChannel.push(bytes.readFloat());
}

and here is what I get:

alt text

The top two channels are the original sound object. The bottom two are floating-point array data. I aligned them so that you can see that the beginning is trimmed and obviously the length is wrong.

Thanks for any answers ...

+3
source share
1 answer

ok there are two problems:

  • mp3 , , - , .
  • i, , ,

var numTotalSamples: Number = int (s.length * 44.1);// 44,1

s.extract(bytes, numTotalSamples, 0);

+1

Source: https://habr.com/ru/post/1735445/


All Articles