我需要控制声音的播放速度,以便从声音文件中提取样本数据,但是由于SoundTranform.volume没有作用,如何控制音量呢?
private function onSampleData(event:SampleDataEvent):void
{
var l:Number;
var r:Number;
var outputLength:int = 0;
while (outputLength < 2048)
{
_loadedMP3Samples.position = int(_phase) * 8; // 4 bytes per float and two channels so the actual position in the ByteArray is a factor of 8 bigger than the phase
l = _loadedMP3Samples.readFloat(); // read out the left and right channels at this position
r = _loadedMP3Samples.readFloat(); // read out the left and right channels at this position
event.data.writeFloat(l); // write the samples to our output buffer
event.data.writeFloat(r); // write the samples to our output buffer
outputLength++;
_phase += _playbackSpeed;
if (_phase < 0)
_phase += _numSamples;
else if (_phase >= _numSamples)
_phase -= _numSamples;
}
}
最佳答案
卷:
使用say var volume: Number = 1.0
作为字段变量。 0.0表示静音,1.0表示原始音量。改变其他方法。但是,侦听器将理解补间此变量。event.data.writeFloat(volume * l);
event.data.writeFloat(volume * r);
速度:
您必须重新采样并使用插值来定义中间值。
它在数学上涉及到,但是我敢肯定有大量的库可以为您做到这一点。但是,这是一个教程,可以告诉您显而易见的内容:
http://www.kelvinluck.com/2008/11/first-steps-with-flash-10-audio-programming/
编辑:哦,您使用了本教程...您可能已经说过。
修改_playbackSpeed。 1.0是全速。 2.0是双倍的速度。
关于performance - 如何在AS3中控制声速和音量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24815816/