开发者

raw sound byteArray to float Array

I'm trying to convert the byteArray of a Sound Object to an array with floats. The Sound Object plays back fine & at full length, but the float Array i get from it is cut off (but sounds correct), so i must be doing 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.r开发者_Go百科eadFloat());
    rightChannel.push(bytes.readFloat());
}

and this is what i get:

raw sound byteArray to float Array

The top two channels are the original Sound Object. The lower two is the float Array Data. I aligned them so you can see that the beginning is cut off and obviously the length is incorrect.

Thanks for any answers...


ok there were two problems:

  1. the mp3 file i was importing was somehow corrupt, that caused the beginning to be cut off
  2. the length i defined to extract was not correct, to find the full sound length use

var numTotalSamples:Number = int(s.length * 44.1); //assuming 44.1kHz sample rate

then:

s.extract(bytes, numTotalSamples, 0);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜