performance - 如何在AS3中控制声速和音量?

标签 performance actionscript-3 flash audio volume

我需要控制声音的播放速度,以便从声音文件中提取样本数据,但是由于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/

相关文章:

java - 使用哪种语法可以获得更好的性能和资源利用率

mysql - 有效地将大约 20kb 的文本重新保存到 mysql

ASP.NET 启动缓慢(符号加载)

ios - 使用 Tapjoy Adob​​e AIR SDK

actionscript-3 - AS3 物体初始位置进入椭圆轨道

performance - SIMD/SSE 新手 : simple image filtering

actionscript-3 - 在AS3中在循环中或循环前声明变量?

asp.net - 从网页录制音频

html - cu3er背景问题

actionscript-3 - 使用计时器的问题