NES Noise
Plays basically the same kind of noise as the Nintendo Entertainment System.
See:
http://en.wikipedia.org/wiki/Linear_feedback_shift_register
http://nesdev.parodius.com/NESSOUND.txt
/**
* Copyright shaktool ( http://wonderfl.net/user/shaktool )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/mccJ
*/
package {
import flash.display.Sprite;
import flash.events.SampleDataEvent;
import flash.media.Sound;
[SWF(width='320',height='240',frameRate='255',backgroundColor='0xFFFFFF')]
public class FlashTest extends Sprite {
public function FlashTest() {
var buffer: int = 1;
var timeUntilReset: int = 0;
var rate: int = 1;
function onSampleDataEvent(event: SampleDataEvent): void {
for (var i: int = 0 ; i < 2048; i++) {
if (timeUntilReset == 0) {
timeUntilReset = 44100;
rate *= 2;
if (rate > 200) rate = 1;
}
timeUntilReset--;
if (i%rate == 0) {
var newBuffer: int = buffer >> 1;
if ((buffer + newBuffer) & 1 == 1) {
newBuffer += 1 << 14;
}
buffer = newBuffer;
}
var sample: Number = buffer & 1 ? 0.1 : -0.1;
event.data.writeFloat(sample);
event.data.writeFloat(sample);
}
}
var sound: Sound = new Sound();
sound.addEventListener(SampleDataEvent.SAMPLE_DATA, onSampleDataEvent);
sound.play();
}
}
}