I would like to generate a sound in Adobe
Air using ByteArray
. The sound should be a silence of x seconds. I found this code that I am using to generate the bytes:
private function encode(data : ByteArray) : ByteArray
{
var channels : uint = 2;
var bits : uint = 16;
var rate : uint = 44100;
var bytes : ByteArray = new ByteArray();
bytes.endian = Endian.LITTLE_ENDIAN;
bytes.writeUTFBytes('RIFF');
bytes.writeInt(uint(data.length + 44));
bytes.writeUTFBytes('WAVE');
bytes.writeUTFBytes('fmt ');
bytes.writeInt(uint(16));
bytes.writeShort(uint(1));
bytes.writeShort(channels);
bytes.writeInt(rate);
bytes.writeInt(uint(rate * channels * (bits / 8)));
bytes.writeShort(uint(channels * (bits / 8)));
bytes.writeShort(bits);
bytes.writeUTFBytes('data');
bytes.writeInt(data.length);
bytes.writeBytes(data);
bytes.position = 0;
return bytes;
}
But when I save the file using Filereference and import it into a flash file I get an error message saying that there were problem reading the file.