开发者

raw sound byteArray to float Array

开发者 https://www.devze.com 2022-12-21 19:17 出处:网络
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)

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

精彩评论

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