0
我需要做一些混音工作。我发现的例子在Adobe的帮助:我需要更多关于sound.extract()的信息
var sourceSnd:Sound = new Sound();
var outputSnd:Sound = new Sound();
var urlReq:URLRequest = new URLRequest("test.mp3");
sourceSnd.load(urlReq);
sourceSnd.addEventListener(Event.COMPLETE, loaded);
function loaded(event:Event):void
{
outputSnd.addEventListener(SampleDataEvent.SAMPLE_DATA, processSound);
outputSnd.play();
}
function processSound(event:SampleDataEvent):void
{
var bytes:ByteArray = new ByteArray();
sourceSnd.extract(bytes, 4096);
event.data.writeBytes(upOctave(bytes));
}
function upOctave(bytes:ByteArray):ByteArray
{
var returnBytes:ByteArray = new ByteArray();
bytes.position = 0;
while(bytes.bytesAvailable > 0)
{
returnBytes.writeFloat(bytes.readFloat());
returnBytes.writeFloat(bytes.readFloat());
if (bytes.bytesAvailable > 0)
{
bytes.position += 8;
}
}
return returnBytes;
}
它说:
target:ByteArray — A ByteArray object in which the extracted sound samples are placed.
length:Number — The number of sound samples to extract. A sample contains both the left and right channels — that is, two 32-bit floating-point values.
我建议
必须编写leftchannel值和rightchannel价值。
bytes.position += 8
减少样本,使声音播放更快。我试图将该值修改为4.速度减慢到2,并且我只有噪音,为什么?其他值,如16或更高,没有声音输出。为什么?如何通过一个浮点值来制作各种音效?
我需要更多信息来了解我的工作,请帮助。
更新:我稍微改变upOctave()函数,速度现在可以调整。
function upOctave(bytes:ByteArray):ByteArray
{
var returnBytes:ByteArray = new ByteArray();
bytes.position = 0;
var position:int = 0;
var speed:Number = 0.75;
while(bytes.bytesAvailable > 0)
{
if (bytes.bytesAvailable > 0)
{
bytes.position = int(speed*position)*8;
}
position++;
if(bytes.bytesAvailable>0){
returnBytes.writeFloat(bytes.readFloat());
returnBytes.writeFloat(bytes.readFloat());
}
}
return returnBytes;
}
感谢,因为我理解的结构,现在我可以改变速度,请参见上面的^^的代码,你可以告诉名词更多信息你提到关于波形? – user2003548 2013-02-09 08:39:31