※現在、「wonderfl build flash online」求人コンテンツ制作に関してのアンケートを実施中です!みなさまのお力添えを頂いて、続々とアンケート結果が集まっていますが、まだまだ募集しております。ご協力のほど、どうぞよろしくお願いいたします!

wonderfl運営事務局
→アンケートページ(※ログインしてからお答えいただけるようになっています。)

 notice: Flash editor updated! Join the development! Thanks to MiniBuilder


FORKED
  1. // forked from keim_at_Si's ●
  2. package {
  3.     import flash.display.*;
  4.     import flash.events.*;
  5.     import flash.filters.*;
  6.     import flash.media.*;
  7.     import flash.text.*;
  8.     
  9.     [SWF(width="465", height="465", backgroundColor="#ffffff", frameRate=30)]
  10.     public class main extends Sprite {
  11.         private var module:TinySiOPM=new TinySiOPM(2048), sound:Sound=new Sound(), channel:SoundChannel;
  12.         private var bshc:Array = ["6060003305300031","0000620000006001","3110011121110010","0000000000000000"];
  13.         private var tone:Array = [[640,3,11,24,-48], [960,4,3,20,0],    [1280,2,3,32,0],   [1024,4,3,8,0]];
  14.         private var pong:Array = [60,62,64,67,69];
  15.         private var pointer:int, frame:int, frameCounter:int, mouseDown:int, bouns:int;
  16.         public function main() {
  17.             stage.addEventListener(Event.ENTER_FRAME,     _onEnterFrame);
  18.             stage.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown);
  19.             sound.addEventListener('sampleData', _onStream);
  20.             var tf:TextField = new TextField();
  21.             tf.text = "クリックではねる";
  22.             tf.textColor = 0x808080;
  23.             tf.x = 180;
  24.             tf.y = 16;
  25.             addChild(tf);
  26.             channel = sound.play();
  27.             pointer = 0;
  28.             frame = 3;
  29.             frameCounter = 0;
  30.             mouseDown = 0;
  31.             bouns = 0;
  32.         }
  33.         private function _onEnterFrame(event:Event) : void {
  34.             if (mouseDown > 1) {
  35.                 addChild(new ball(mouseX, mouseY, mouseDown-2function(p:int, v:Number) : void { bouns = (p<<5) | int(v*32); }));
  36.                 mouseDown = 0;
  37.             }
  38.         }
  39.         private function _onMouseDown(event:MouseEvent) : void {
  40.             mouseDown = 1;
  41.         }
  42.         private function _onStream(e:SampleDataEvent) : void {
  43.             if (++frameCounter == frame) {
  44.                 for (var i:int=0; i<4; i++) {
  45.                     var v:int = int(bshc[i].charAt(pointer));
  46.                     if (v) { module.noteOn(tone[i][0], v<<tone[i][1], tone[i][2], tone[i][3], tone[i][4]); }
  47.                 }
  48.                 if (mouseDown == 1) {
  49.                     var p:int = int(Math.random()*5);
  50.                     module.noteOn(pong[p]<<46428);
  51.                     mouseDown = p+2;
  52.                 }
  53.                 if (bouns > 0) {
  54.                     module.noteOn(pong[bouns>>5]<<4, bouns&3128);
  55.                     bouns = 0;
  56.                 }
  57.                 pointer = (pointer + 1) & 15;
  58.                 frameCounter = 0;
  59.             }
  60.             module.buffer(e.data);
  61.         }
  62.     }
  63. }
  64. import flash.events.*;
  65. import flash.display.*;
  66. import flash.geom.*;
  67. class ball extends Shape {
  68.     private var v:Point=new Point(), pitch:int, bound:Function, spring:Boolean;
  69.     function ball(x:int, y:int, p:int, f:Function) {
  70.         graphics.clear();
  71.         graphics.beginFill([0xf08080,0xe0e040,0x80f080,0x40e0e0,0x8080f0][p]);
  72.         graphics.drawCircle(0010);
  73.         graphics.endFill();
  74.         addEventListener("enterFrame", _ef);
  75.         this.x = x;
  76.         this.y = y;
  77.         v.x = Math.random() * 10-5;
  78.         v.y = Math.random() * -5-5;
  79.         alpha = 1;
  80.         pitch = p;
  81.         bound = f;
  82.         spring = true;
  83.     }
  84.     private function _ef(e:Event) : void {
  85.         x+=v.x; y+=v.y; v.y+=1; alpha-=0.0078125;
  86.         if (y>360 && v.y>0 && spring) { bound(pitch, alpha); spring=false; }
  87.         if (y>450) { y=900-y; v.y=-v.y*0.7; spring=true; }
  88.         if (x<0 || x>495 || alpha<0.01) { removeEventListener("enterFrame", _ef); parent.removeChild(this); }
  89.     }
  90. }
  91. import flash.utils.ByteArray;
  92. class TinySiOPM {
  93.     private var term:Note, pipe:Vector.<Number>, bufferSize:int;
  94.     private var pitchTable:Vector.<int> = new Vector.<int>(2048true);      // 128:note * 16:detune
  95.     private var logTable:Vector.<Number> = new Vector.<Number>(6144true);  // 24:cause * 128:fine *2:p/n
  96.     function TinySiOPM(bufferSize:int=2048) {
  97.         var i:int, j:int, p:Number, v:Number, t:Vector.<int>;
  98.         for (i=0, p=0; i<192; i++, p+=0.00520833333)
  99.             for (v=Math.pow(2, p)*12441.464342886, j=i; j<2048; v*=2, j+=192)
  100.                 pitchTable[j] = int(v);
  101.         for (i=0, p=0.0078125; i<256; i+=2, p+=0.0078125
  102.             for (v=Math.pow(213-p)*0.0001220703125, j=i; j<3328; v*=0.5, j+=256)
  103.                 logTable[j+1] = -(logTable[j] = v);
  104.         for (i=3328; i<6144; i++) { logTable[i] = 0; }
  105.         var famtri:Array = [0,1,2,3,4,5,6,7,6,5,4,3,2,1,0,0,-1,-2,-3,-4,-5,-6,-7,-8,-7,-6,-5,-4,-3,-2,-1,0];
  106.         for (t=Note.createTable(10), i=0, p=0; i<1024; i++, p+=0.00613592315) { t[i] = _logIndex(Math.sin(p)); } // sin=0
  107.         for (t=Note.createTable(10), i=0, p=0.75; i<1024; i++, p-=0.00146484375) { t[i] = _logIndex(p); }        // saw=1
  108.         for (t=Note.createTable(5), i=0; i<32; i++) { t[i] = _logIndex(famtri[i]*0.0625); }                      // famtri=2
  109.         for (t=Note.createTable(15), i=0; i<32768; i++) { t[i] = _logIndex(Math.random()-0.5); }                 // wnoize=3
  110.         for (i=0; i<8; i++) for (t=Note.createTable(4), j=0; j<16; j++) { t[j] = (j<=i) ? 192 : 193; }           // pulse=4-11
  111.         term = new Note();
  112.         pipe = new Vector.<Number>(bufferSize, true);
  113.         for (i=0; i<bufferSize; i++) pipe[i] = 0;
  114.         this.bufferSize = bufferSize;
  115.     }
  116.     private function _logIndex(n:Number) : int {
  117.         return (n<0) ? ((n<-0.00390625) ? (((int(Math.log(-n) * -184.66496523 + 0.5) + 1) << 1) + 1) : 2047)
  118.                      : ((n> 0.00390625) ? (( int(Math.log( n) * -184.66496523 + 0.5) + 1) << 1)      : 2046);
  119.     }
  120.     public function buffer(data:ByteArray) : void {
  121.         var n:Note, rep:int, i:int, imax:int, dph:int, lout:int, v:int;
  122.         for (imax=1024; imax<=bufferSize; imax+=1024) {
  123.             for (n=term.next; n!=term; n=n.next) {
  124.                 for (dph=pitchTable[n.pitch], i=imax-1024; i<imax; n.ph=(n.ph+dph)&0x3ffffff, i++) {
  125.                     lout=n.table[n.ph>>n.shift]+n.gain; pipe[i]+=logTable[lout];
  126.                 }
  127.                 if (!n.inc()) n = n.remove();
  128.             }
  129.         }
  130.         for (i=0; i<bufferSize; i++) { data.writeFloat(pipe[i]); data.writeFloat(pipe[i]); pipe[i]=0; }
  131.     }
  132.     public function noteOn(pitch:int, velocity:int=64, tone:int=0, decay:int=4, sweep:int=0) : void {
  133.         Note.alloc().reset(tone, pitch, _logIndex(velocity*0.0078125), sweep, (decay<<2)).into(term);
  134.     }
  135. }
  136. class Note {
  137.     public var prev:Note, next:Note, ph:int, pitch:int, gain:int, sweep:int, decay:int, table:Vector.<int>, shift:int
  138.     function Note() { prev = next = this; }
  139.     public function remove() : Note { var r:Note=prev; prev.next=next; next.prev=prev; into(free); return r; }
  140.     public function into(n:Note) : Note { prev=n.prev; next=n; prev.next=this; next.prev=thisreturn this; }
  141.     public function inc() : Boolean { gain+=decay; pitch+=sweep; pitch&=2047return (gain<4000); }
  142.     public function reset(t:int, p:int, g:int, s:int, d:int) : Note { 
  143.         ph=0; pitch=p; gain=g; sweep=s; decay=d<<1; table=waveTable[t]; shift=shiftTable[t]; return this;
  144.     }
  145.     static public var waveTable:Array=[], shiftTable:Array=[];
  146.     static public function createTable(bit:int) : Vector.<int> { 
  147.         var t:Vector.<int>=new Vector.<int>(1<<bit, true); waveTable.push(t); shiftTable.push(26-bit); return t;
  148.     }
  149.     static public var free:Note = new Note();
  150.     static public function alloc() : Note {
  151.         if (free.prev==free) return new Note();
  152.         var r:Note=free.prev; free.prev=r.prev; free.prev.next=free; return r;
  153.     }
  154. }
noswf
  1. // forked from keim_at_Si's ●
  2. package {
  3.     import flash.display.*;
  4.     import flash.events.*;
  5.     import flash.filters.*;
  6.     import flash.media.*;
  7.     import flash.text.*;
  8.     
  9.     [SWF(width="465", height="465", backgroundColor="#cccccc", frameRate=30)]
  10.     public class main extends Sprite {
  11.         private var module:TinySiOPM=new TinySiOPM(2048), sound:Sound=new Sound(), channel:SoundChannel;
  12.         private var bshc:Array = ["0010100000900091","0000090000000001","3110011121110010","0000000000000000"];
  13.         private var tone:Array = [[640,3,11,24,-48], [960,4,3,20,0],    [1280,2,3,32,0],   [1024,4,3,8,0]];
  14.         private var pong:Array = [10,12,10,67,69];
  15.         private var pointer:int, frame:int, frameCounter:int, mouseDown:int, bouns:int;
  16.         public function main() {
  17.             stage.addEventListener(Event.ENTER_FRAME,     _onEnterFrame);
  18.             stage.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown);
  19.             sound.addEventListener('sampleData', _onStream);
  20.             var tf:TextField = new TextField();
  21.             tf.text = "";
  22.             tf.textColor = 0x808080;
  23.             tf.x = 180;
  24.             tf.y = 16;
  25.             addChild(tf);
  26.             channel = sound.play();
  27.             pointer = 0;
  28.             frame = 3;
  29.             frameCounter = 0;
  30.             mouseDown = 0;
  31.             bouns = 0;
  32.         }
  33.         private function _onEnterFrame(event:Event) : void {
  34.             if (mouseDown > 1) {
  35.                 addChild(new ball(mouseX, mouseY, mouseDown-2function(p:int, v:Number) : void { bouns = (p<<5) | int(v*32); }));
  36.                 mouseDown = 0;
  37.             }
  38.         }
  39.         private function _onMouseDown(event:MouseEvent) : void {
  40.             mouseDown = 1;
  41.         }
  42.         private function _onStream(e:SampleDataEvent) : void {
  43.             if (++frameCounter == frame) {
  44.                 for (var i:int=0; i<4; i++) {
  45.                     var v:int = int(bshc[i].charAt(pointer));
  46.                     if (v) { module.noteOn(tone[i][0], v<<tone[i][1], tone[i][2], tone[i][3], tone[i][4]); }
  47.                 }
  48.                 if (mouseDown == 1) {
  49.                     var p:int = int(Math.random()*5);
  50.                     module.noteOn(pong[p]<<46428);
  51.                     mouseDown = p+2;
  52.                 }
  53.                 if (bouns > 0) {
  54.                     module.noteOn(pong[bouns>>5]<<4, bouns&3128);
  55.                     bouns = 0;
  56.                 }
  57.                 pointer = (pointer + 1) & 15;
  58.                 frameCounter = 0;
  59.             }
  60.             module.buffer(e.data);
  61.         }
  62.     }
  63. }
  64. import flash.events.*;
  65. import flash.display.*;
  66. import flash.geom.*;
  67. class ball extends Shape {
  68.     private var v:Point=new Point(), pitch:int, bound:Function, spring:Boolean;
  69.     function ball(x:int, y:int, p:int, f:Function) {
  70.         graphics.clear();
  71.         graphics.beginFill([0xff0000,0xffffff,0x0000ff,0xff00ff,0x00ff00][p]);
  72.         graphics.drawRect(0050,50);
  73.         graphics.endFill();
  74.         addEventListener("enterFrame", _ef);
  75.         this.x = x;
  76.         this.y = y;
  77.         v.x = Math.random() * 10-5;
  78.         v.y = Math.random() * -5-5;
  79.         alpha = 1;
  80.         pitch = p;
  81.         bound = f;
  82.         spring = true;
  83.     }
  84.     private function _ef(e:Event) : void {
  85.         x+=v.x; y+=v.y; v.y+=1; alpha-=0.0078125;
  86.         if (y>360 && v.y>0 && spring) { bound(pitch, alpha); spring=false; }
  87.         if (y>450) { y=900-y; v.y=-v.y*0.7; spring=true; }
  88.         if (x<0 || x>495 || alpha<0.01) { removeEventListener("enterFrame", _ef); parent.removeChild(this); }
  89.     }
  90. }
  91. import flash.utils.ByteArray;
  92. class TinySiOPM {
  93.     private var term:Note, pipe:Vector.<Number>, bufferSize:int;
  94.     private var pitchTable:Vector.<int> = new Vector.<int>(2048true);      // 128:note * 16:detune
  95.     private var logTable:Vector.<Number> = new Vector.<Number>(6144true);  // 24:cause * 128:fine *2:p/n
  96.     function TinySiOPM(bufferSize:int=2048) {
  97.         var i:int, j:int, p:Number, v:Number, t:Vector.<int>;
  98.         for (i=0, p=0; i<192; i++, p+=0.00520833333)
  99.             for (v=Math.pow(2, p)*12441.464342886, j=i; j<2048; v*=2, j+=192)
  100.                 pitchTable[j] = int(v);
  101.         for (i=0, p=0.0078125; i<256; i+=2, p+=0.0078125
  102.             for (v=Math.pow(213-p)*0.0001220703125, j=i; j<3328; v*=0.5, j+=256)
  103.                 logTable[j+1] = -(logTable[j] = v);
  104.         for (i=3328; i<6144; i++) { logTable[i] = 0; }
  105.         var famtri:Array = [0,1,2,3,4,5,6,7,6,5,4,3,2,1,0,0,-1,-2,-3,-4,-5,-6,-7,-8,-7,-6,-5,-4,-3,-2,-1,0];
  106.         for (t=Note.createTable(10), i=0, p=0; i<1024; i++, p+=0.00613592315) { t[i] = _logIndex(Math.sin(p)); } // sin=0
  107.         for (t=Note.createTable(10), i=0, p=0.75; i<1024; i++, p-=0.00146484375) { t[i] = _logIndex(p); }        // saw=1
  108.         for (t=Note.createTable(5), i=0; i<32; i++) { t[i] = _logIndex(famtri[i]*0.0625); }                      // famtri=2
  109.         for (t=Note.createTable(15), i=0; i<32768; i++) { t[i] = _logIndex(Math.random()-0.5); }                 // wnoize=3
  110.         for (i=0; i<8; i++) for (t=Note.createTable(4), j=0; j<16; j++) { t[j] = (j<=i) ? 192 : 193; }           // pulse=4-11
  111.         term = new Note();
  112.         pipe = new Vector.<Number>(bufferSize, true);
  113.         for (i=0; i<bufferSize; i++) pipe[i] = 0;
  114.         this.bufferSize = bufferSize;
  115.     }
  116.     private function _logIndex(n:Number) : int {
  117.         return (n<0) ? ((n<-0.00390625) ? (((int(Math.log(-n) * -184.66496523 + 0.5) + 1) << 1) + 1) : 2047)
  118.                      : ((n> 0.00390625) ? (( int(Math.log( n) * -184.66496523 + 0.5) + 1) << 1)      : 2046);
  119.     }
  120.     public function buffer(data:ByteArray) : void {
  121.         var n:Note, rep:int, i:int, imax:int, dph:int, lout:int, v:int;
  122.         for (imax=1024; imax<=bufferSize; imax+=1024) {
  123.             for (n=term.next; n!=term; n=n.next) {
  124.                 for (dph=pitchTable[n.pitch], i=imax-1024; i<imax; n.ph=(n.ph+dph)&0x3ffffff, i++) {
  125.                     lout=n.table[n.ph>>n.shift]+n.gain; pipe[i]+=logTable[lout];
  126.                 }
  127.                 if (!n.inc()) n = n.remove();
  128.             }
  129.         }
  130.         for (i=0; i<bufferSize; i++) { data.writeFloat(pipe[i]); data.writeFloat(pipe[i]); pipe[i]=0; }
  131.     }
  132.     public function noteOn(pitch:int, velocity:int=64, tone:int=0, decay:int=4, sweep:int=0) : void {
  133.         Note.alloc().reset(tone, pitch, _logIndex(velocity*0.0078125), sweep, (decay<<2)).into(term);
  134.     }
  135. }
  136. class Note {
  137.     public var prev:Note, next:Note, ph:int, pitch:int, gain:int, sweep:int, decay:int, table:Vector.<int>, shift:int
  138.     function Note() { prev = next = this; }
  139.     public function remove() : Note { var r:Note=prev; prev.next=next; next.prev=prev; into(free); return r; }
  140.     public function into(n:Note) : Note { prev=n.prev; next=n; prev.next=this; next.prev=thisreturn this; }
  141.     public function inc() : Boolean { gain+=decay; pitch+=sweep; pitch&=2047return (gain<4000); }
  142.     public function reset(t:int, p:int, g:int, s:int, d:int) : Note { 
  143.         ph=0; pitch=p; gain=g; sweep=s; decay=d<<1; table=waveTable[t]; shift=shiftTable[t]; return this;
  144.     }
  145.     static public var waveTable:Array=[], shiftTable:Array=[];
  146.     static public function createTable(bit:int) : Vector.<int> { 
  147.         var t:Vector.<int>=new Vector.<int>(1<<bit, true); waveTable.push(t); shiftTable.push(26-bit); return t;
  148.     }
  149.     static public var free:Note = new Note();
  150.     static public function alloc() : Note {
  151.         if (free.prev==free) return new Note();
  152.         var r:Note=free.prev; free.prev=r.prev; free.prev.next=free; return r;
  153.     }
  154. }
noswf
  1. // forked from keim_at_Si's ●
  2. package {
  3.     import flash.display.*;
  4.     import flash.events.*;
  5.     import flash.filters.*;
  6.     import flash.media.*;
  7.     import flash.text.*;
  8.     
  9.     [SWF(width="465", height="465", backgroundColor="#ffffff", frameRate=30)]
  10.     public class main extends Sprite {
  11.         private var module:TinySiOPM=new TinySiOPM(2048), sound:Sound=new Sound(), channel:SoundChannel;
  12.         private var bshc:Array = ["6060003305300031","0000620000006001","3110011121110010","0000000000000000"];
  13.         private var tone:Array = [[640,3,11,24,-48], [960,4,3,20,0],    [1280,2,3,32,0],   [1024,4,3,8,0]];
  14.         private var pong:Array = [60,62,64,67,69];
  15.         private var pointer:int, frame:int, frameCounter:int, mouseDown:int, bouns:int;
  16.         public function main() {
  17.             stage.addEventListener(Event.ENTER_FRAME,     _onEnterFrame);
  18.             stage.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown);
  19.             sound.addEventListener('sampleData', _onStream);
  20.             var tf:TextField = new TextField();
  21.             tf.text = "クリックではねる";
  22.             tf.textColor = 0x808080;
  23.             tf.x = 180;
  24.             tf.y = 16;
  25.             addChild(tf);
  26.             channel = sound.play();
  27.             pointer = 0;
  28.             frame = 3;
  29.             frameCounter = 0;
  30.             mouseDown = 0;
  31.             bouns = 0;
  32.         }
  33.         private function _onEnterFrame(event:Event) : void {
  34.             if (mouseDown > 1) {
  35.                 addChild(new ball(mouseX, mouseY, mouseDown-2function(p:int, v:Number) : void { bouns = (p<<5) | int(v*32); }));
  36.                 mouseDown = 0;
  37.             }
  38.         }
  39.         private function _onMouseDown(event:MouseEvent) : void {
  40.             mouseDown = 1;
  41.         }
  42.         private function _onStream(e:SampleDataEvent) : void {
  43.             if (++frameCounter == frame) {
  44.                 for (var i:int=0; i<4; i++) {
  45.                     var v:int = int(bshc[i].charAt(pointer));
  46.                     if (v) { module.noteOn(tone[i][0], v<<tone[i][1], tone[i][2], tone[i][3], tone[i][4]); }
  47.                 }
  48.                 if (mouseDown == 1) {
  49.                     var p:int = int(Math.random()*5);
  50.                     module.noteOn(pong[p]<<46428);
  51.                     mouseDown = p+2;
  52.                 }
  53.                 if (bouns > 0) {
  54.                     module.noteOn(pong[bouns>>5]<<4, bouns&3128);
  55.                     bouns = 0;
  56.                 }
  57.                 pointer = (pointer + 1) & 15;
  58.                 frameCounter = 0;
  59.             }
  60.             module.buffer(e.data);
  61.         }
  62.     }
  63. }
  64. import flash.events.*;
  65. import flash.display.*;
  66. import flash.geom.*;
  67. class ball extends Shape {
  68.     private var v:Point=new Point(), pitch:int, bound:Function, spring:Boolean;
  69.     function ball(x:int, y:int, p:int, f:Function) {
  70.         graphics.clear();
  71.         graphics.beginFill([0xf08080,0xe0e040,0x80f080,0x40e0e0,0x8080f0][p]);
  72.         graphics.drawCircle(0010);
  73.         graphics.endFill();
  74.         addEventListener("enterFrame", _ef);
  75.         this.x = x;
  76.         this.y = y;
  77.         v.x = Math.random() * 10-5;
  78.         v.y = Math.random() * -5-5;
  79.         alpha = 1;
  80.         pitch = p;
  81.         bound = f;
  82.         spring = true;
  83.     }
  84.     private function _ef(e:Event) : void {
  85.         x+=v.x; y+=v.y; v.y+=1; alpha-=0.0078125;
  86.         if (y>360 && v.y>0 && spring) { bound(pitch, alpha); spring=false; }
  87.         if (y>450) { y=900-y; v.y=-v.y*0.7; spring=true; }
  88.         if (x<0 || x>495 || alpha<0.01) { removeEventListener("enterFrame", _ef); parent.removeChild(this); }
  89.     }
  90. }
  91. import flash.utils.ByteArray;
  92. class TinySiOPM {
  93.     private var term:Note, pipe:Vector.<Number>, bufferSize:int;
  94.     private var pitchTable:Vector.<int> = new Vector.<int>(2048true);      // 128:note * 16:detune
  95.     private var logTable:Vector.<Number> = new Vector.<Number>(6144true);  // 24:cause * 128:fine *2:p/n
  96.     function TinySiOPM(bufferSize:int=2048) {
  97.         var i:int, j:int, p:Number, v:Number, t:Vector.<int>;
  98.         for (i=0, p=0; i<192; i++, p+=0.00520833333)
  99.             for (v=Math.pow(2, p)*12441.464342886, j=i; j<2048; v*=2, j+=192)
  100.                 pitchTable[j] = int(v);
  101.         for (i=0, p=0.0078125; i<256; i+=2, p+=0.0078125
  102.             for (v=Math.pow(213-p)*0.0001220703125, j=i; j<3328; v*=0.5, j+=256)
  103.                 logTable[j+1] = -(logTable[j] = v);
  104.         for (i=3328; i<6144; i++) { logTable[i] = 0; }
  105.         var famtri:Array = [0,1,2,3,4,5,6,7,6,5,4,3,2,1,0,0,-1,-2,-3,-4,-5,-6,-7,-8,-7,-6,-5,-4,-3,-2,-1,0];
  106.         for (t=Note.createTable(10), i=0, p=0; i<1024; i++, p+=0.00613592315) { t[i] = _logIndex(Math.sin(p)); } // sin=0
  107.         for (t=Note.createTable(10), i=0, p=0.75; i<1024; i++, p-=0.00146484375) { t[i] = _logIndex(p); }        // saw=1
  108.         for (t=Note.createTable(5), i=0; i<32; i++) { t[i] = _logIndex(famtri[i]*0.0625); }                      // famtri=2
  109.         for (t=Note.createTable(15), i=0; i<32768; i++) { t[i] = _logIndex(Math.random()-0.5); }                 // wnoize=3
  110.         for (i=0; i<8; i++) for (t=Note.createTable(4), j=0; j<16; j++) { t[j] = (j<=i) ? 192 : 193; }           // pulse=4-11
  111.         term = new Note();
  112.         pipe = new Vector.<Number>(bufferSize, true);
  113.         for (i=0; i<bufferSize; i++) pipe[i] = 0;
  114.         this.bufferSize = bufferSize;
  115.     }
  116.     private function _logIndex(n:Number) : int {
  117.         return (n<0) ? ((n<-0.00390625) ? (((int(Math.log(-n) * -184.66496523 + 0.5) + 1) << 1) + 1) : 2047)
  118.                      : ((n> 0.00390625) ? (( int(Math.log( n) * -184.66496523 + 0.5) + 1) << 1)      : 2046);
  119.     }
  120.     public function buffer(data:ByteArray) : void {
  121.         var n:Note, rep:int, i:int, imax:int, dph:int, lout:int, v:int;
  122.         for (imax=1024; imax<=bufferSize; imax+=1024) {
  123.             for (n=term.next; n!=term; n=n.next) {
  124.                 for (dph=pitchTable[n.pitch], i=imax-1024; i<imax; n.ph=(n.ph+dph)&0x3ffffff, i++) {
  125.                     lout=n.table[n.ph>>n.shift]+n.gain; pipe[i]+=logTable[lout];
  126.                 }
  127.                 if (!n.inc()) n = n.remove();
  128.             }
  129.         }
  130.         for (i=0; i<bufferSize; i++) { data.writeFloat(pipe[i]); data.writeFloat(pipe[i]); pipe[i]=0; }
  131.     }
  132.     public function noteOn(pitch:int, velocity:int=64, tone:int=0, decay:int=4, sweep:int=0) : void {
  133.         Note.alloc().reset(tone, pitch, _logIndex(velocity*0.0078125), sweep, (decay<<2)).into(term);
  134.     }
  135. }
  136. class Note {
  137.     public var prev:Note, next:Note, ph:int, pitch:int, gain:int, sweep:int, decay:int, table:Vector.<int>, shift:int
  138.     function Note() { prev = next = this; }
  139.     public function remove() : Note { var r:Note=prev; prev.next=next; next.prev=prev; into(free); return r; }
  140.     public function into(n:Note) : Note { prev=n.prev; next=n; prev.next=this; next.prev=thisreturn this; }
  141.     public function inc() : Boolean { gain+=decay; pitch+=sweep; pitch&=2047return (gain<4000); }
  142.     public function reset(t:int, p:int, g:int, s:int, d:int) : Note { 
  143.         ph=0; pitch=p; gain=g; sweep=s; decay=d<<1; table=waveTable[t]; shift=shiftTable[t]; return this;
  144.     }
  145.     static public var waveTable:Array=[], shiftTable:Array=[];
  146.     static public function createTable(bit:int) : Vector.<int> { 
  147.         var t:Vector.<int>=new Vector.<int>(1<<bit, true); waveTable.push(t); shiftTable.push(26-bit); return t;
  148.     }
  149.     static public var free:Note = new Note();
  150.     static public function alloc() : Note {
  151.         if (free.prev==free) return new Note();
  152.         var r:Note=free.prev; free.prev=r.prev; free.prev.next=free; return r;
  153.     }
  154. }
noswf
  1. // forked from keim_at_Si's ●
  2. package {
  3.     import flash.display.*;
  4.     import flash.events.*;
  5.     import flash.filters.*;
  6.     import flash.media.*;
  7.     import flash.text.*;
  8.     
  9.     [SWF(width="465", height="465", backgroundColor="#ffffff", frameRate=30)]
  10.     public class main extends Sprite {
  11.         private var module:TinySiOPM=new TinySiOPM(2048), sound:Sound=new Sound(), channel:SoundChannel;
  12.         private var bshc:Array = ["6060003305300031","0000620000006001","3110011121110010","0000000000000000"];
  13.         private var tone:Array = [[640,3,11,24,-48], [960,4,3,20,0],    [1280,2,3,32,0],   [1024,4,3,8,0]];
  14.         private var pong:Array = [60,62,64,67,69];
  15.         private var pointer:int, frame:int, frameCounter:int, mouseDown:int, bouns:int;
  16.         public function main() {
  17.             stage.addEventListener(Event.ENTER_FRAME,     _onEnterFrame);
  18.             stage.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown);
  19.             sound.addEventListener('sampleData', _onStream);
  20.             var tf:TextField = new TextField();
  21.             tf.text = "クリックではねる";
  22.             tf.textColor = 0x808080;
  23.             tf.x = 180;
  24.             tf.y = 16;
  25.             addChild(tf);
  26.             channel = sound.play();
  27.             pointer = 0;
  28.             frame = 3;
  29.             frameCounter = 0;
  30.             mouseDown = 0;
  31.             bouns = 0;
  32.         }
  33.         private function _onEnterFrame(event:Event) : void {
  34.             if (mouseDown > 1) {
  35.                 addChild(new ball(mouseX, mouseY, mouseDown-2function(p:int, v:Number) : void { bouns = (p<<5) | int(v*32); }));
  36.                 mouseDown = 0;
  37.             }
  38.         }
  39.         private function _onMouseDown(event:MouseEvent) : void {
  40.             mouseDown = 1;
  41.         }
  42.         private function _onStream(e:SampleDataEvent) : void {
  43.             if (++frameCounter == frame) {
  44.                 for (var i:int=0; i<4; i++) {
  45.                     var v:int = int(bshc[i].charAt(pointer));
  46.                     if (v) { module.noteOn(tone[i][0], v<<tone[i][1], tone[i][2], tone[i][3], tone[i][4]); }
  47.                 }
  48.                 if (mouseDown == 1) {
  49.                     var p:int = int(Math.random()*5);
  50.                     module.noteOn(pong[p]<<46428);
  51.                     mouseDown = p+2;
  52.                 }
  53.                 if (bouns > 0) {
  54.                     module.noteOn(pong[bouns>>5]<<4, bouns&3128);
  55.                     bouns = 0;
  56.                 }
  57.                 pointer = (pointer + 1) & 15;
  58.                 frameCounter = 0;
  59.             }
  60.             module.buffer(e.data);
  61.         }
  62.     }
  63. }
  64. import flash.events.*;
  65. import flash.display.*;
  66. import flash.geom.*;
  67. class ball extends Shape {
  68.     private var v:Point=new Point(), pitch:int, bound:Function, spring:Boolean;
  69.     function ball(x:int, y:int, p:int, f:Function) {
  70.         graphics.clear();
  71.         graphics.beginFill([0xf08080,0xe0e040,0x80f080,0x40e0e0,0x8080f0][p]);
  72.         graphics.drawCircle(0010);
  73.         graphics.endFill();
  74.         addEventListener("enterFrame", _ef);
  75.         this.x = x;
  76.         this.y = y;
  77.         v.x = Math.random() * 10-5;
  78.         v.y = Math.random() * -5-5;
  79.         alpha = 1;
  80.         pitch = p;
  81.         bound = f;
  82.         spring = true;
  83.     }
  84.     private function _ef(e:Event) : void {
  85.         x+=v.x; y+=v.y; v.y+=1; alpha-=0.0078125;
  86.         if (y>360 && v.y>0 && spring) { bound(pitch, alpha); spring=false; }
  87.         if (y>450) { y=900-y; v.y=-v.y*0.7; spring=true; }
  88.         if (x<0 || x>495 || alpha<0.01) { removeEventListener("enterFrame", _ef); parent.removeChild(this); }
  89.     }
  90. }
  91. import flash.utils.ByteArray;
  92. class TinySiOPM {
  93.     private var term:Note, pipe:Vector.<Number>, bufferSize:int;
  94.     private var pitchTable:Vector.<int> = new Vector.<int>(2048true);      // 128:note * 16:detune
  95.     private var logTable:Vector.<Number> = new Vector.<Number>(6144true);  // 24:cause * 128:fine *2:p/n
  96.     function TinySiOPM(bufferSize:int=2048) {
  97.         var i:int, j:int, p:Number, v:Number, t:Vector.<int>;
  98.         for (i=0, p=0; i<192; i++, p+=0.00520833333)
  99.             for (v=Math.pow(2, p)*12441.464342886, j=i; j<2048; v*=2, j+=192)
  100.                 pitchTable[j] = int(v);
  101.         for (i=0, p=0.0078125; i<256; i+=2, p+=0.0078125
  102.             for (v=Math.pow(213-p)*0.0001220703125, j=i; j<3328; v*=0.5, j+=256)
  103.                 logTable[j+1] = -(logTable[j] = v);
  104.         for (i=3328; i<6144; i++) { logTable[i] = 0; }
  105.         var famtri:Array = [0,1,2,3,4,5,6,7,6,5,4,3,2,1,0,0,-1,-2,-3,-4,-5,-6,-7,-8,-7,-6,-5,-4,-3,-2,-1,0];
  106.         for (t=Note.createTable(10), i=0, p=0; i<1024; i++, p+=0.00613592315) { t[i] = _logIndex(Math.sin(p)); } // sin=0
  107.         for (t=Note.createTable(10), i=0, p=0.75; i<1024; i++, p-=0.00146484375) { t[i] = _logIndex(p); }        // saw=1
  108.         for (t=Note.createTable(5), i=0; i<32; i++) { t[i] = _logIndex(famtri[i]*0.0625); }                      // famtri=2
  109.         for (t=Note.createTable(15), i=0; i<32768; i++) { t[i] = _logIndex(Math.random()-0.5); }                 // wnoize=3
  110.         for (i=0; i<8; i++) for (t=Note.createTable(4), j=0; j<16; j++) { t[j] = (j<=i) ? 192 : 193; }           // pulse=4-11
  111.         term = new Note();
  112.         pipe = new Vector.<Number>(bufferSize, true);
  113.         for (i=0; i<bufferSize; i++) pipe[i] = 0;
  114.         this.bufferSize = bufferSize;
  115.     }
  116.     private function _logIndex(n:Number) : int {
  117.         return (n<0) ? ((n<-0.00390625) ? (((int(Math.log(-n) * -184.66496523 + 0.5) + 1) << 1) + 1) : 2047)
  118.                      : ((n> 0.00390625) ? (( int(Math.log( n) * -184.66496523 + 0.5) + 1) << 1)      : 2046);
  119.     }
  120.     public function buffer(data:ByteArray) : void {
  121.         var n:Note, rep:int, i:int, imax:int, dph:int, lout:int, v:int;
  122.         for (imax=1024; imax<=bufferSize; imax+=1024) {
  123.             for (n=term.next; n!=term; n=n.next) {
  124.                 for (dph=pitchTable[n.pitch], i=imax-1024; i<imax; n.ph=(n.ph+dph)&0x3ffffff, i++) {
  125.                     lout=n.table[n.ph>>n.shift]+n.gain; pipe[i]+=logTable[lout];
  126.                 }
  127.                 if (!n.inc()) n = n.remove();
  128.             }
  129.         }
  130.         for (i=0; i<bufferSize; i++) { data.writeFloat(pipe[i]); data.writeFloat(pipe[i]); pipe[i]=0; }
  131.     }
  132.     public function noteOn(pitch:int, velocity:int=64, tone:int=0, decay:int=4, sweep:int=0) : void {
  133.         Note.alloc().reset(tone, pitch, _logIndex(velocity*0.0078125), sweep, (decay<<2)).into(term);
  134.     }
  135. }
  136. class Note {
  137.     public var prev:Note, next:Note, ph:int, pitch:int, gain:int, sweep:int, decay:int, table:Vector.<int>, shift:int
  138.     function Note() { prev = next = this; }
  139.     public function remove() : Note { var r:Note=prev; prev.next=next; next.prev=prev; into(free); return r; }
  140.     public function into(n:Note) : Note { prev=n.prev; next=n; prev.next=this; next.prev=thisreturn this; }
  141.     public function inc() : Boolean { gain+=decay; pitch+=sweep; pitch&=2047return (gain<4000); }
  142.     public function reset(t:int, p:int, g:int, s:int, d:int) : Note { 
  143.         ph=0; pitch=p; gain=g; sweep=s; decay=d<<1; table=waveTable[t]; shift=shiftTable[t]; return this;
  144.     }
  145.     static public var waveTable:Array=[], shiftTable:Array=[];
  146.     static public function createTable(bit:int) : Vector.<int> { 
  147.         var t:Vector.<int>=new Vector.<int>(1<<bit, true); waveTable.push(t); shiftTable.push(26-bit); return t;
  148.     }
  149.     static public var free:Note = new Note();
  150.     static public function alloc() : Note {
  151.         if (free.prev==free) return new Note();
  152.         var r:Note=free.prev; free.prev=r.prev; free.prev.next=free; return r;
  153.     }
  154. }
noswf
  1. // forked from keim_at_Si's ●
  2. package {
  3.     import flash.display.*;
  4.     import flash.events.*;
  5.     import flash.filters.*;
  6.     import flash.media.*;
  7.     import flash.text.*;
  8.     
  9.     [SWF(width="465", height="465", backgroundColor="#ffffff", frameRate=30)]
  10.     public class main extends Sprite {
  11.         private var module:TinySiOPM=new TinySiOPM(2048), sound:Sound=new Sound(), channel:SoundChannel;
  12.         private var bshc:Array = ["6060003305300031","0000620000006001","3110011121110010","0000000000000000"];
  13.         private var tone:Array = [[640,3,11,24,-48], [960,4,3,20,0],    [1280,2,3,32,0],   [1024,4,3,8,0]];
  14.         private var pong:Array = [60,62,64,67,69];
  15.         private var pointer:int, frame:int, frameCounter:int, mouseDown:int, bouns:int;
  16.         public function main() {
  17.             stage.addEventListener(Event.ENTER_FRAME,     _onEnterFrame);
  18.             stage.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown);
  19.             sound.addEventListener('sampleData', _onStream);
  20.             var tf:TextField = new TextField();
  21.             tf.text = "クリックではねる";
  22.             tf.textColor = 0x808080;
  23.             tf.x = 180;
  24.             tf.y = 16;
  25.             addChild(tf);
  26.             channel = sound.play();
  27.             pointer = 0;
  28.             frame = 3;
  29.             frameCounter = 0;
  30.             mouseDown = 0;
  31.             bouns = 0;
  32.         }
  33.         private function _onEnterFrame(event:Event) : void {
  34.             if (mouseDown > 1) {
  35.                 addChild(new ball(mouseX, mouseY, mouseDown-2function(p:int, v:Number) : void { bouns = (p<<5) | int(v*32); }));
  36.                 mouseDown = 0;
  37.             }
  38.         }
  39.         private function _onMouseDown(event:MouseEvent) : void {
  40.             mouseDown = 1;
  41.         }
  42.         private function _onStream(e:SampleDataEvent) : void {
  43.             if (++frameCounter == frame) {
  44.                 for (var i:int=0; i<4; i++) {
  45.                     var v:int = int(bshc[i].charAt(pointer));
  46.                     if (v) { module.noteOn(tone[i][0], v<<tone[i][1], tone[i][2], tone[i][3], tone[i][4]); }
  47.                 }
  48.                 if (mouseDown == 1) {
  49.                     var p:int = int(Math.random()*5);
  50.                     module.noteOn(pong[p]<<46428);
  51.                     mouseDown = p+2;
  52.                 }
  53.                 if (bouns > 0) {
  54.                     module.noteOn(pong[bouns>>5]<<4, bouns&3128);
  55.                     bouns = 0;
  56.                 }
  57.                 pointer = (pointer + 1) & 15;
  58.                 frameCounter = 0;
  59.             }
  60.             module.buffer(e.data);
  61.         }
  62.     }
  63. }
  64. import flash.events.*;
  65. import flash.display.*;
  66. import flash.geom.*;
  67. class ball extends Shape {
  68.     private var v:Point=new Point(), pitch:int, bound:Function, spring:Boolean;
  69.     function ball(x:int, y:int, p:int, f:Function) {
  70.         graphics.clear();
  71.         graphics.beginFill([0xf08080,0xe0e040,0x80f080,0x40e0e0,0x8080f0][p]);
  72.         graphics.drawCircle(0010);
  73.         graphics.endFill();
  74.         addEventListener("enterFrame", _ef);
  75.         this.x = x;
  76.         this.y = y;
  77.         v.x = Math.random() * 10-5;
  78.         v.y = Math.random() * -5-5;
  79.         alpha = 1;
  80.         pitch = p;
  81.         bound = f;
  82.         spring = true;
  83.     }
  84.     private function _ef(e:Event) : void {
  85.         x+=v.x; y+=v.y; v.y+=1; alpha-=0.0078125;
  86.         if (y>360 && v.y>0 && spring) { bound(pitch, alpha); spring=false; }
  87.         if (y>450) { y=900-y; v.y=-v.y*0.7; spring=true; }
  88.         if (x<0 || x>495 || alpha<0.01) { removeEventListener("enterFrame", _ef); parent.removeChild(this); }
  89.     }
  90. }
  91. import flash.utils.ByteArray;
  92. class TinySiOPM {
  93.     private var term:Note, pipe:Vector.<Number>, bufferSize:int;
  94.     private var pitchTable:Vector.<int> = new Vector.<int>(2048true);      // 128:note * 16:detune
  95.     private var logTable:Vector.<Number> = new Vector.<Number>(6144true);  // 24:cause * 128:fine *2:p/n
  96.     function TinySiOPM(bufferSize:int=2048) {
  97.         var i:int, j:int, p:Number, v:Number, t:Vector.<int>;
  98.         for (i=0, p=0; i<192; i++, p+=0.00520833333)
  99.             for (v=Math.pow(2, p)*12441.464342886, j=i; j<2048; v*=2, j+=192)
  100.                 pitchTable[j] = int(v);
  101.         for (i=0, p=0.0078125; i<256; i+=2, p+=0.0078125
  102.             for (v=Math.pow(213-p)*0.0001220703125, j=i; j<3328; v*=0.5, j+=256)
  103.                 logTable[j+1] = -(logTable[j] = v);
  104.         for (i=3328; i<6144; i++) { logTable[i] = 0; }
  105.         var famtri:Array = [0,1,2,3,4,5,6,7,6,5,4,3,2,1,0,0,-1,-2,-3,-4,-5,-6,-7,-8,-7,-6,-5,-4,-3,-2,-1,0];
  106.         for (t=Note.createTable(10), i=0, p=0; i<1024; i++, p+=0.00613592315) { t[i] = _logIndex(Math.sin(p)); } // sin=0
  107.         for (t=Note.createTable(10), i=0, p=0.75; i<1024; i++, p-=0.00146484375) { t[i] = _logIndex(p); }        // saw=1
  108.         for (t=Note.createTable(5), i=0; i<32; i++) { t[i] = _logIndex(famtri[i]*0.0625); }                      // famtri=2
  109.         for (t=Note.createTable(15), i=0; i<32768; i++) { t[i] = _logIndex(Math.random()-0.5); }                 // wnoize=3
  110.         for (i=0; i<8; i++) for (t=Note.createTable(4), j=0; j<16; j++) { t[j] = (j<=i) ? 192 : 193; }           // pulse=4-11
  111.         term = new Note();
  112.         pipe = new Vector.<Number>(bufferSize, true);
  113.         for (i=0; i<bufferSize; i++) pipe[i] = 0;
  114.         this.bufferSize = bufferSize;
  115.     }
  116.     private function _logIndex(n:Number) : int {
  117.         return (n<0) ? ((n<-0.00390625) ? (((int(Math.log(-n) * -184.66496523 + 0.5) + 1) << 1) + 1) : 2047)
  118.                      : ((n> 0.00390625) ? (( int(Math.log( n) * -184.66496523 + 0.5) + 1) << 1)      : 2046);
  119.     }
  120.     public function buffer(data:ByteArray) : void {
  121.         var n:Note, rep:int, i:int, imax:int, dph:int, lout:int, v:int;
  122.         for (imax=1024; imax<=bufferSize; imax+=1024) {
  123.             for (n=term.next; n!=term; n=n.next) {
  124.                 for (dph=pitchTable[n.pitch], i=imax-1024; i<imax; n.ph=(n.ph+dph)&0x3ffffff, i++) {
  125.                     lout=n.table[n.ph>>n.shift]+n.gain; pipe[i]+=logTable[lout];
  126.                 }
  127.                 if (!n.inc()) n = n.remove();
  128.             }
  129.         }
  130.         for (i=0; i<bufferSize; i++) { data.writeFloat(pipe[i]); data.writeFloat(pipe[i]); pipe[i]=0; }
  131.     }
  132.     public function noteOn(pitch:int, velocity:int=64, tone:int=0, decay:int=4, sweep:int=0) : void {
  133.         Note.alloc().reset(tone, pitch, _logIndex(velocity*0.0078125), sweep, (decay<<2)).into(term);
  134.     }
  135. }
  136. class Note {
  137.     public var prev:Note, next:Note, ph:int, pitch:int, gain:int, sweep:int, decay:int, table:Vector.<int>, shift:int
  138.     function Note() { prev = next = this; }
  139.     public function remove() : Note { var r:Note=prev; prev.next=next; next.prev=prev; into(free); return r; }
  140.     public function into(n:Note) : Note { prev=n.prev; next=n; prev.next=this; next.prev=thisreturn this; }
  141.     public function inc() : Boolean { gain+=decay; pitch+=sweep; pitch&=2047return (gain<4000); }
  142.     public function reset(t:int, p:int, g:int, s:int, d:int) : Note { 
  143.         ph=0; pitch=p; gain=g; sweep=s; decay=d<<1; table=waveTable[t]; shift=shiftTable[t]; return this;
  144.     }
  145.     static public var waveTable:Array=[], shiftTable:Array=[];
  146.     static public function createTable(bit:int) : Vector.<int> { 
  147.         var t:Vector.<int>=new Vector.<int>(1<<bit, true); waveTable.push(t); shiftTable.push(26-bit); return t;
  148.     }
  149.     static public var free:Note = new Note();
  150.     static public function alloc() : Note {
  151.         if (free.prev==free) return new Note();
  152.         var r:Note=free.prev; free.prev=r.prev; free.prev.next=free; return r;
  153.     }
  154. }
noswf
Get Adobe Flash Player