是否可以在Flash中应用声音滤镜?

时间:2013-01-15 11:40:05

标签: audio actionscript filter actionscript-2 flash-cs6

所以基本上我有一个用Flash CS5制作的音板,是否可以使用Flash替换库的音频文件的声音?就像让剪辑听起来更深或更快一样,这就是重点。但如果它不是pissbile

1 个答案:

答案 0 :(得分:0)

你不能在AS2中这样做。但是,您可以在AS3中更改声音的音高和播放速度。事实上,你可以做更多的事情(搜索Audiotool),但这表明它是如何完成的: http://plasticsturgeon.com/2012/05/changing-the-pitch-of-a-looped-sound-at-runtime-with-actionscript/

如果我的博客发生故障或其他事情,这里是改变声音音调的相关课程。:

    package sound
{
    import flash.events.Event;
    import flash.events.SampleDataEvent;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundTransform;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;

/**
 * @author Andre Michelle (andr...@gmail.com)
     * Modified by Zach Foley aka The Plastic Sturgeon
 */
public class MP3Pitch
{
    private const BLOCK_SIZE: int = 3072;

    private var _mp3: Sound;
    private var _sound: Sound;

    private var _target: ByteArray;

    private var _position: Number;
    private var _rate: Number;
    private var repeat:SoundChannel;
    private var _volume:Number = 1;
    private var byteArray:ByteArray;

            // Pass in your looped Sound
    public function MP3Pitch( pitchedSound: Sound)
    {
        _target = new ByteArray();
        _mp3 =  pitchedSound;

        _position = 0.0;
        _rate = 0.0;

        _sound = new Sound();
        _sound.addEventListener( SampleDataEvent.SAMPLE_DATA, sampleData );
        repeat = _sound.play();
    }

    public function get rate(): Number
    {
        return _rate;
    }

            // Also added a handy volume setter
    public function set volume( value: Number ): void
    {
        _volume = value;
        repeat.soundTransform = new SoundTransform(_volume);
    }

            // use this to set the pitch of your sound
    public function set rate( value: Number ): void
    {
        if( value < 0.0 )
            value = 0;

        _rate =  value;
    }

    private function sampleData( event: SampleDataEvent ): void
    {
        //-- REUSE INSTEAD OF RECREATION
        _target.position = 0;

        //-- SHORTCUT
        var data: ByteArray = event.data;

        var scaledBlockSize: Number = BLOCK_SIZE * _rate;
        var positionInt: int = _position;
        var alpha: Number = _position - positionInt;

        var positionTargetNum: Number = alpha;
        var positionTargetInt: int = -1;

        //-- COMPUTE NUMBER OF SAMPLES NEED TO PROCESS BLOCK (+2 FOR INTERPOLATION)
        var need: int = Math.ceil( scaledBlockSize ) + 2;

        //-- EXTRACT SAMPLES
        var read: int = _mp3.extract( _target, need, positionInt );

        var n: int = read == need ? BLOCK_SIZE : read / _rate;

        var l0: Number;
        var r0: Number;
        var l1: Number;
        var r1: Number;

        for( var i: int = 0 ; i < n ; ++i )
        {
            //-- AVOID READING EQUAL SAMPLES, IF RATE < 1.0
            if( int( positionTargetNum ) != positionTargetInt )
            {
                positionTargetInt = positionTargetNum;

                //-- SET TARGET READ POSITION
                _target.position = positionTargetInt << 3;                      //-- READ TWO STEREO SAMPLES FOR LINEAR INTERPOLATION                   l0 = _target.readFloat();                   r0 = _target.readFloat();                   l1 = _target.readFloat();                   r1 = _target.readFloat();               }                               //-- WRITE INTERPOLATED AMPLITUDES INTO STREAM              data.writeFloat( l0 + alpha * ( l1 - l0 ) );                data.writeFloat( r0 + alpha * ( r1 - r0 ) );                                //-- INCREASE TARGET POSITION               positionTargetNum += _rate;                                 //-- INCREASE FRACTION AND CLAMP BETWEEN 0 AND 1                alpha += _rate;                 while( alpha &gt;= 1.0 ) --alpha;
        }

        //-- FILL REST OF STREAM WITH ZEROs
        if( i < BLOCK_SIZE )
        {
            while( i < BLOCK_SIZE )                 {                   data.writeFloat( 0.0 );                     data.writeFloat( 0.0 );                                         ++i;                }           }           //-- INCREASE SOUND POSITION            _position += scaledBlockSize;                        // My little addition here:            if (_position &gt; _mp3.length * 44.1) {
            _position = 0;
            _target.position = 0;
        }
    }
}
}