0

サウンドミックスの仕事をする必要があります。私はAdobeヘルプで例を見つけました:

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.

私は提案します

    returnBytes.writeFloat(bytes.readFloat());
    returnBytes.writeFloat(bytes.readFloat());

左チャネル値と右チャネル値を書き込む必要があります。

bytes.position += 8

サンプルを減らして、サウンドの再生を速くします。値を4に変更しようとしましたが、速度が2に遅くなり、ノイズしか発生しませんでした。なぜですか。16以上などの他の値では、サウンドは出力されません。なんで?1つのフロート値だけでさまざまな効果音を作るには?

私の仕事を理解するためにもっと情報が必要です、助けてください。

更新: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;
        }
4

1 に答える 1

0

要するに、bytes.position += 8;プレイレートを意味するのではありません。

フロートあたり4バイトと2つのチャネル。下の画像のように移動します。

8byteArrayは1セットです。言い換えれば、サンプリング。

 4byte  4byte
[  L  ][  R  ] [  L  ][  R  ] [  L  ][  R  ] [  L  ][  R  ] ...

       1              2              3              4

L、R32フロート。-1と1の間の連続データ。Sin関数のように。

波形を作成し、サウンドを制御できます。直線波、のこぎり波、三角波、正弦波、ノイズ波…やがて音は波形に依存します。

プレイレートを調整したい場合は、この記事を読んでください:http ://www.kelvinluck.com/2008/11/first-steps-with-flash-10-audio-programming/

于 2013-02-09T07:40:44.530 に答える