Performance 如何在AS3中控制音速和音量?
我需要控制声音播放速度,以便从声音文件中提取样本数据,但如何控制音量,因为SoundTransform.volume没有效果Performance 如何在AS3中控制音速和音量?,performance,actionscript-3,flash,audio,volume,Performance,Actionscript 3,Flash,Audio,Volume,我需要控制声音播放速度,以便从声音文件中提取样本数据,但如何控制音量,因为SoundTransform.volume没有效果 private function onSampleData(event:SampleDataEvent):void { var l:Number; var r:Number; var outputLength:int = 0; while (outputLength < 2048)
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;
}
}
采样数据上的私有函数(事件:SampleDataEvent):void
{
var l:数字;
var r:数字;
变量输出长度:int=0;
而(输出长度<2048)
{
_loadedMP3Samples.position=int(_phase)*8;//4字节/浮点和两个通道,因此ByteArray中的实际位置比phase大8倍
l=_loadedMP3Samples.readFloat();//读取此位置的左通道和右通道
r=_loadedMP3Samples.readFloat();//读取此位置的左通道和右通道
event.data.writeFloat(l);//将样本写入输出缓冲区
event.data.writeFloat(r);//将样本写入输出缓冲区
outputLength++;
_相位+=\u播放后退速度;
如果(_相位<0)
_相位+=_个数采样;
否则如果(\u阶段>=\u数值示例)
_相位-=_个采样;
}
}
卷:
使用sayvar volume:Number=1.0
作为字段变量。0.0表示静音,1.0表示原始音量。用其他方法改变。然而,听众会欣赏这个变量
event.data.writeFloat(卷*l)代码>
event.data.writeFloat(volume*r)代码>
速度:
必须重新采样并使用插值来定义中间值
这涉及到数学,但我相信有很多库可以为您做到这一点。但是,嘿,这里有一个教程告诉你:
编辑:哦,你用了这个教程。。。你可以说
修改播放速度。1.0是全速。2.0是双速。这只是采样代码-您能在哪里播放声音?