リング変調によるボイスチェンジャ
/**
* Copyright hirossy ( http://wonderfl.net/user/hirossy )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/2aYy
*/
// forked from hirossy's forked from: マイク入力テスト(FP10.1専用) 書き換えてみた
// forked from TheCoolMuseum's マイク入力テスト(FP10.1専用)
package {
import flash.display.*;
import flash.events.SampleDataEvent;
import flash.media.Microphone;
import flash.media.Sound;
public class FlashTest extends Sprite
{
private var buffer:Array = [];
private var mic:Microphone;
private var sound:Sound;
private var depth:Number = 1; // parameter 1
private var rate:Number = 160; // parameter 2
private var count:int = 0;
public function FlashTest()
{
mic = Microphone.getMicrophone();
mic.rate = 44;
mic.setUseEchoSuppression(true);
mic.addEventListener(SampleDataEvent.SAMPLE_DATA, sampling);
sound = new Sound();
sound.addEventListener(SampleDataEvent.SAMPLE_DATA, playing);
sound.play();
}
private function sampling(event:SampleDataEvent):void
{
while (event.data.bytesAvailable)
{
buffer.push(event.data.readFloat());
}
}
private function playing(event:SampleDataEvent):void
{
for (var i:int=0; i<8192; i++)
{
var value:Number = 0;
if (buffer.length > 0)
value = buffer.shift();
var keisu:Number = depth * Math.sin(2.0 * Math.PI * rate * count / 44100);
value = value * keisu;
event.data.writeFloat(value);
event.data.writeFloat(value);
count = (count++ > 44100)? 0:count;
}
}
}
}