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

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

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


FORKED
  1. // forked from kappaLab's ドラムンベース(っぽいもの)
  2. package  
  3. {
  4.     
  5.     import flash.display.Sprite
  6.     import flash.display.Shape
  7.     import flash.events.Event;
  8.     import flash.events.SampleDataEvent;
  9.     import flash.filters.BlurFilter;
  10.     import flash.media.Sound;
  11.     
  12.     [SWF(backgroundColor=0x000000, frameRate=60)]
  13.     public class Drumnbass_3 extends Sprite 
  14.     {
  15.         private const PI2:Number = Math.PI * 2;
  16.         private const SAMPLE_RATE:Number = 44100;    
  17.         private const LATENCY:int = 4410 //2048~8192
  18.         private var sound:Sound;
  19.         
  20.         private var voices:Vector.<Voice> = new Vector.<Voice>()
  21.         private var particles:Vector.<Shape> = new Vector.<Shape>()
  22.         private var count:int = 0
  23.         
  24.         public function Drumnbass_3() 
  25.         {
  26.             init()
  27.         }
  28.         
  29.         public function init():void 
  30.         {
  31.             voices[0] = new Voice(60,.6,100,2000,6000)
  32.             voices[1] = new Voice(120,.2,100,500,600)
  33.             voices[2] = new Voice(80, .8,100,500,600)
  34.             voices[3] = new Voice(880,.2,100,500,600)
  35.             voices[4] = new Voice(660,.5,100,1000,1200)
  36.             voices[5] = new Voice(440,.5,100,1000,1200)
  37.             
  38.             var stageWidth:Number = stage.stageWidth
  39.             var stageHeight:Number = stage.stageHeight
  40.             
  41.             
  42.             var n:int = voices.length;
  43.             for (var i:int = 0; i < n; i++) 
  44.             {
  45.                 var s:Shape = new Shape()
  46.                 var x:Number = stageHeight * Math.random() * .5 - stageHeight * .25;
  47.                 var y:Number = stageHeight * Math.random() * .5 - stageHeight * .25;
  48.                 s.graphics.beginFill(0xFFFFFF * Math.random());
  49.                 s.graphics.drawCircle(x, y, Math.random() * 20 + 20);
  50.                 s.alpha = .5
  51.                 s.x = stage.stageWidth / 2;
  52.                 s.y = stage.stageHeight / 2;
  53.                 
  54.                 particles[i] = s
  55.                 addChild(s)
  56.             }
  57.             addEventListener(Event.ENTER_FRAME,
  58.             function(e:Event):void {
  59.                 
  60.                 var n:int = particles.length
  61.                 for (var i:int = 0; i < n; i++) 
  62.                 {
  63.                     var p:Shape = particles[i]
  64.                     p.rotation += i % 2 * 2 - 1;
  65.                     p.scaleX += (1 - p.scaleX) * .4;
  66.                     p.scaleY += (1 - p.scaleY) * .4;
  67.                 }
  68.             })            
  69.             filters = [new BlurFilter(55)]
  70.             sound = new Sound()
  71.             sound.addEventListener(SampleDataEvent.SAMPLE_DATA, updateVoice)
  72.             sound.play()
  73.         }
  74.         
  75.         private function updateVoice(e:SampleDataEvent):void
  76.         {
  77.             var n:Number = LATENCY
  78.             
  79.             count++
  80.             var c8:int = count %8
  81.             var c16:int = count %16
  82.             var c32:int = count %32
  83.             var c64:int = count % 64
  84.             
  85.             if (c8 == 0 ||
  86.                 c8 == 1 ||
  87.                 c8 == 2 ||
  88.                 c8 == 3 ) {
  89.                 if (Math.random() > .3) {
  90.                     voices[2].play();
  91.                     particles[2].scaleX = particles[2].scaleY = 2
  92.                 }else {
  93.                     voices[3].play()
  94.                     particles[3].scaleX = particles[3].scaleY = 2
  95.                 }
  96.             }
  97.             if (c8 == 6 ||
  98.                 c8 == 7 ) {
  99.                 voices[1].play()
  100.                 particles[1].scaleX = particles[1].scaleY = 2.5
  101.             }
  102.             if (count % 16 == 11) {
  103.                 particles[0].scaleX = particles[0].scaleY = 3
  104.                 voices[0].play()
  105.             }
  106.             
  107.             if (count % 32 == 8) {
  108.                 particles[4].scaleX = particles[4].scaleY = 3
  109.                 voices[4].play()
  110.             }
  111.             
  112.             if (count % 32 == 10 && Math.random()>.3){
  113.                 particles[5].scaleX = particles[5].scaleY = 4
  114.                 voices[5].play()
  115.             }
  116.             for (var i:int = 0; i < n; i++) 
  117.             {
  118.                 var sample:Number = 0
  119.                 
  120.                 for each (var v:Voice in voices) 
  121.                     sample += v.pulse;
  122.                 
  123.                 e.data.writeFloat(sample)
  124.                 e.data.writeFloat(sample)
  125.             }
  126.         }
  127.  
  128.     }
  129.     
  130. }
  131. class Voice {
  132.     
  133.     private const PI2:Number = Math.PI * 2;
  134.     private const SAMPLE_RATE:Number = 44100
  135.     
  136.     private var phase:Number = 0
  137.     public var frequency:Number     
  138.     public var volume:Number;
  139.     public var attack:int;
  140.     public var decay:int;
  141.     public var sustain:int;
  142.     private var position:int     = 0
  143.     private var amplifier:Number = 0
  144.     
  145.     public function Voice(
  146.     frequency:Number = 440,
  147.     volume:Number    = .2,
  148.     attack:int       = 1000,
  149.     decay:int        = 1000,
  150.     sustain:int      = 5000 )
  151.     {
  152.         this.frequency = frequency
  153.         this.volume = volume
  154.         this.attack = attack
  155.         this.decay = decay
  156.         this.sustain = sustain
  157.     }
  158.     public function get pulse():Number
  159.     {
  160.         return Math.sin(updatePhase()) * updateAmplifier() * volume;
  161.     }
  162.     public function play():void 
  163.     {
  164.         position = 0
  165.     }
  166.     public function updatePhase():Number
  167.     {
  168.         phase += PI2 * frequency / SAMPLE_RATE
  169.         phase %= PI2;
  170.         return phase
  171.     }    
  172.     public function updateAmplifier():Number
  173.     {
  174.         var position:int = (this.position++ )
  175.         if (position >= sustain) {
  176.             amplifier = 0
  177.         }else if (position < attack) {
  178.             amplifier += 1/attack
  179.         }else if (position > (sustain-decay)) {
  180.             amplifier -= 1/decay
  181.         }
  182.         return amplifier;
  183.     }
  184. }
noswf
  1. // forked from kappaLab's ドラムンベース(っぽいもの)
  2. package  
  3. {
  4.     
  5.     import flash.display.Sprite
  6.     import flash.display.Shape
  7.     import flash.events.Event;
  8.     import flash.events.SampleDataEvent;
  9.     import flash.filters.BlurFilter;
  10.     import flash.media.Sound;
  11.     
  12.     [SWF(backgroundColor=0x000000, frameRate=60)]
  13.     public class Drumnbass_3 extends Sprite 
  14.     {
  15.         private const PI2:Number = Math.PI * 2;
  16.         private const SAMPLE_RATE:Number = 44100;    
  17.         private const LATENCY:int = 4410 //2048~8192
  18.         private var sound:Sound;
  19.         
  20.         private var voices:Vector.<Voice> = new Vector.<Voice>()
  21.         private var particles:Vector.<Shape> = new Vector.<Shape>()
  22.         private var count:int = 0
  23.         
  24.         public function Drumnbass_3() 
  25.         {
  26.             init()
  27.         }
  28.         
  29.         public function init():void 
  30.         {
  31.             voices[0] = new Voice(60,.6,100,2000,6000)
  32.             voices[1] = new Voice(120,.2,100,500,600)
  33.             voices[2] = new Voice(80, .8,100,500,600)
  34.             voices[3] = new Voice(880,.2,100,500,600)
  35.             voices[4] = new Voice(660,.5,100,1000,1200)
  36.             voices[5] = new Voice(440,.5,100,1000,1200)
  37.             
  38.             var stageWidth:Number = stage.stageWidth
  39.             var stageHeight:Number = stage.stageHeight
  40.             
  41.             
  42.             var n:int = voices.length;
  43.             for (var i:int = 0; i < n; i++) 
  44.             {
  45.                 var s:Shape = new Shape()
  46.                 var x:Number = stageHeight * Math.random() * .5 - stageHeight * .25;
  47.                 var y:Number = stageHeight * Math.random() * .5 - stageHeight * .25;
  48.                 s.graphics.beginFill(0xFFFFFF * Math.random());
  49.                 s.graphics.drawCircle(x, y, Math.random() * 20 + 20);
  50.                 s.alpha = .5
  51.                 s.x = stage.stageWidth / 2;
  52.                 s.y = stage.stageHeight / 2;
  53.                 
  54.                 particles[i] = s
  55.                 addChild(s)
  56.             }
  57.             addEventListener(Event.ENTER_FRAME,
  58.             function(e:Event):void {
  59.                 
  60.                 var n:int = particles.length
  61.                 for (var i:int = 0; i < n; i++) 
  62.                 {
  63.                     var p:Shape = particles[i]
  64.                     p.rotation += i % 2 * 2 - 1;
  65.                     p.scaleX += (1 - p.scaleX) * .4;
  66.                     p.scaleY += (1 - p.scaleY) * .4;
  67.                 }
  68.             })            
  69.             filters = [new BlurFilter(55)]
  70.             sound = new Sound()
  71.             sound.addEventListener(SampleDataEvent.SAMPLE_DATA, updateVoice)
  72.             sound.play()
  73.         }
  74.         
  75.         private function updateVoice(e:SampleDataEvent):void
  76.         {
  77.             var n:Number = LATENCY
  78.             
  79.             count++
  80.             var c8:int = count %8
  81.             var c16:int = count %16
  82.             var c32:int = count %32
  83.             var c64:int = count % 64
  84.             
  85.             if (c8 == 0 ||
  86.                 c8 == 1 ||
  87.                 c8 == 2 ||
  88.                 c8 == 3 ) {
  89.                 if (Math.random() > .3) {
  90.                     voices[2].play();
  91.                     particles[2].scaleX = particles[2].scaleY = 2
  92.                 }else {
  93.                     voices[3].play()
  94.                     particles[3].scaleX = particles[3].scaleY = 2
  95.                 }
  96.             }
  97.             if (c8 == 6 ||
  98.                 c8 == 7 ) {
  99.                 voices[1].play()
  100.                 particles[1].scaleX = particles[1].scaleY = 2.5
  101.             }
  102.             if (count % 16 == 11) {
  103.                 particles[0].scaleX = particles[0].scaleY = 3
  104.                 voices[0].play()
  105.             }
  106.             
  107.             if (count % 32 == 8) {
  108.                 particles[4].scaleX = particles[4].scaleY = 3
  109.                 voices[4].play()
  110.             }
  111.             
  112.             if (count % 32 == 10 && Math.random()>.3){
  113.                 particles[5].scaleX = particles[5].scaleY = 4
  114.                 voices[5].play()
  115.             }
  116.             for (var i:int = 0; i < n; i++) 
  117.             {
  118.                 var sample:Number = 0
  119.                 
  120.                 for each (var v:Voice in voices) 
  121.                     sample += v.pulse;
  122.                 
  123.                 e.data.writeFloat(sample)
  124.                 e.data.writeFloat(sample)
  125.             }
  126.         }
  127.  
  128.     }
  129.     
  130. }
  131. class Voice {
  132.     
  133.     private const PI2:Number = Math.PI * 2;
  134.     private const SAMPLE_RATE:Number = 44100
  135.     
  136.     private var phase:Number = 0
  137.     public var frequency:Number     
  138.     public var volume:Number;
  139.     public var attack:int;
  140.     public var decay:int;
  141.     public var sustain:int;
  142.     private var position:int     = 0
  143.     private var amplifier:Number = 0
  144.     
  145.     public function Voice(
  146.     frequency:Number = 440,
  147.     volume:Number    = .2,
  148.     attack:int       = 1000,
  149.     decay:int        = 1000,
  150.     sustain:int      = 5000 )
  151.     {
  152.         this.frequency = frequency
  153.         this.volume = volume
  154.         this.attack = attack
  155.         this.decay = decay
  156.         this.sustain = sustain
  157.     }
  158.     public function get pulse():Number
  159.     {
  160.         return Math.sin(updatePhase()) * updateAmplifier() * volume;
  161.     }
  162.     public function play():void 
  163.     {
  164.         position = 0
  165.     }
  166.     public function updatePhase():Number
  167.     {
  168.         phase += PI2 * frequency / SAMPLE_RATE
  169.         phase %= PI2;
  170.         return phase
  171.     }    
  172.     public function updateAmplifier():Number
  173.     {
  174.         var position:int = (this.position++ )
  175.         if (position >= sustain) {
  176.             amplifier = 0
  177.         }else if (position < attack) {
  178.             amplifier += 1/attack
  179.         }else if (position > (sustain-decay)) {
  180.             amplifier -= 1/decay
  181.         }
  182.         return amplifier;
  183.     }
  184. }
noswf
  1. // forked from kappaLab's ドラムンベース(っぽいもの)
  2. package  
  3. {
  4.     
  5.     import flash.display.Sprite
  6.     import flash.display.Shape
  7.     import flash.events.Event;
  8.     import flash.events.SampleDataEvent;
  9.     import flash.filters.BlurFilter;
  10.     import flash.media.Sound;
  11.     
  12.     [SWF(backgroundColor=0x000000, frameRate=60)]
  13.     public class Drumnbass_3 extends Sprite 
  14.     {
  15.         private const PI2:Number = Math.PI * 2;
  16.         private const SAMPLE_RATE:Number = 44100;    
  17.         private const LATENCY:int = 4410 //2048~8192
  18.         private var sound:Sound;
  19.         
  20.         private var voices:Vector.<Voice> = new Vector.<Voice>()
  21.         private var particles:Vector.<Shape> = new Vector.<Shape>()
  22.         private var count:int = 0
  23.         
  24.         public function Drumnbass_3() 
  25.         {
  26.             init()
  27.         }
  28.         
  29.         public function init():void 
  30.         {
  31.             voices[0] = new Voice(60,.6,100,2000,6000)
  32.             voices[1] = new Voice(120,.2,100,500,600)
  33.             voices[2] = new Voice(80, .8,100,500,600)
  34.             voices[3] = new Voice(880,.2,100,500,600)
  35.             voices[4] = new Voice(660,.5,100,1000,1200)
  36.             voices[5] = new Voice(440,.5,100,1000,1200)
  37.             
  38.             var stageWidth:Number = stage.stageWidth
  39.             var stageHeight:Number = stage.stageHeight
  40.             
  41.             
  42.             var n:int = voices.length;
  43.             for (var i:int = 0; i < n; i++) 
  44.             {
  45.                 var s:Shape = new Shape()
  46.                 var x:Number = stageHeight * Math.random() * .5 - stageHeight * .25;
  47.                 var y:Number = stageHeight * Math.random() * .5 - stageHeight * .25;
  48.                 s.graphics.beginFill(0xFFFFFF * Math.random());
  49.                 s.graphics.drawCircle(x, y, Math.random() * 20 + 20);
  50.                 s.alpha = .5
  51.                 s.x = stage.stageWidth / 2;
  52.                 s.y = stage.stageHeight / 2;
  53.                 
  54.                 particles[i] = s
  55.                 addChild(s)
  56.             }
  57.             addEventListener(Event.ENTER_FRAME,
  58.             function(e:Event):void {
  59.                 
  60.                 var n:int = particles.length
  61.                 for (var i:int = 0; i < n; i++) 
  62.                 {
  63.                     var p:Shape = particles[i]
  64.                     p.rotation += i % 2 * 2 - 1;
  65.                     p.scaleX += (1 - p.scaleX) * .4;
  66.                     p.scaleY += (1 - p.scaleY) * .4;
  67.                 }
  68.             })            
  69.             filters = [new BlurFilter(55)]
  70.             sound = new Sound()
  71.             sound.addEventListener(SampleDataEvent.SAMPLE_DATA, updateVoice)
  72.             sound.play()
  73.         }
  74.         
  75.         private function updateVoice(e:SampleDataEvent):void
  76.         {
  77.             var n:Number = LATENCY
  78.             
  79.             count++
  80.             var c8:int = count %8
  81.             var c16:int = count %16
  82.             var c32:int = count %32
  83.             var c64:int = count % 64
  84.             
  85.             if (c8 == 0 ||
  86.                 c8 == 1 ||
  87.                 c8 == 2 ||
  88.                 c8 == 3 ) {
  89.                 if (Math.random() > .3) {
  90.                     voices[2].play();
  91.                     particles[2].scaleX = particles[2].scaleY = 2
  92.                 }else {
  93.                     voices[3].play()
  94.                     particles[3].scaleX = particles[3].scaleY = 2
  95.                 }
  96.             }
  97.             if (c8 == 6 ||
  98.                 c8 == 7 ) {
  99.                 voices[1].play()
  100.                 particles[1].scaleX = particles[1].scaleY = 2.5
  101.             }
  102.             if (count % 16 == 11) {
  103.                 particles[0].scaleX = particles[0].scaleY = 3
  104.                 voices[0].play()
  105.             }
  106.             
  107.             if (count % 32 == 8) {
  108.                 particles[4].scaleX = particles[4].scaleY = 3
  109.                 voices[4].play()
  110.             }
  111.             
  112.             if (count % 32 == 10 && Math.random()>.3){
  113.                 particles[5].scaleX = particles[5].scaleY = 4
  114.                 voices[5].play()
  115.             }
  116.             for (var i:int = 0; i < n; i++) 
  117.             {
  118.                 var sample:Number = 0
  119.                 
  120.                 for each (var v:Voice in voices) 
  121.                     sample += v.pulse;
  122.                 
  123.                 e.data.writeFloat(sample)
  124.                 e.data.writeFloat(sample)
  125.             }
  126.         }
  127.  
  128.     }
  129.     
  130. }
  131. class Voice {
  132.     
  133.     private const PI2:Number = Math.PI * 2;
  134.     private const SAMPLE_RATE:Number = 44100
  135.     
  136.     private var phase:Number = 0
  137.     public var frequency:Number     
  138.     public var volume:Number;
  139.     public var attack:int;
  140.     public var decay:int;
  141.     public var sustain:int;
  142.     private var position:int     = 0
  143.     private var amplifier:Number = 0
  144.     
  145.     public function Voice(
  146.     frequency:Number = 440,
  147.     volume:Number    = .2,
  148.     attack:int       = 1000,
  149.     decay:int        = 1000,
  150.     sustain:int      = 5000 )
  151.     {
  152.         this.frequency = frequency
  153.         this.volume = volume
  154.         this.attack = attack
  155.         this.decay = decay
  156.         this.sustain = sustain
  157.     }
  158.     public function get pulse():Number
  159.     {
  160.         return Math.abs(updatePhase()) * updateAmplifier() * volume;
  161.     }
  162.     public function play():void 
  163.     {
  164.         position = 0
  165.     }
  166.     public function updatePhase():Number
  167.     {
  168.         phase += PI2 * frequency / SAMPLE_RATE
  169.         phase %= PI2;
  170.         return phase
  171.     }    
  172.     public function updateAmplifier():Number
  173.     {
  174.         var position:int = (this.position++ )
  175.         if (position >= sustain) {
  176.             amplifier = 0
  177.         }else if (position < attack) {
  178.             amplifier += 1/attack
  179.         }else if (position > (sustain-decay)) {
  180.             amplifier -= 1/decay
  181.         }
  182.         return amplifier;
  183.     }
  184. }
noswf
  1. package  
  2. {
  3.     
  4.     import flash.display.Sprite
  5.     import flash.display.Shape
  6.     import flash.events.Event;
  7.     import flash.events.SampleDataEvent;
  8.     import flash.filters.BlurFilter;
  9.     import flash.media.Sound;
  10.     
  11.     [SWF(backgroundColor=0x000000, frameRate=60)]
  12.     public class Breakbeats extends Sprite 
  13.     {
  14.         private const PI2:Number = Math.PI * 2;
  15.         private const SAMPLE_RATE:Number = 44100;    
  16.         private const LATENCY:int = 4410 //2048~8192
  17.         private var sound:Sound;
  18.         
  19.         private var voices:Vector.<Voice> = new Vector.<Voice>()
  20.         private var particles:Vector.<Shape> = new Vector.<Shape>()
  21.         private var count:int = 0
  22.         
  23.         public function Breakbeats() 
  24.         {
  25.             init()
  26.         }
  27.         
  28.         public function init():void 
  29.         {
  30.             voices[0] = new Bass()
  31.             voices[1] = new Noise(.2,100,1000,1100)
  32.             voices[2] = new Noise(.2,100,5000,5100)
  33.             voices[3] = new Noise(.2,100,8000,10000)
  34.             
  35.             var stageWidth:Number = stage.stageWidth
  36.             var stageHeight:Number = stage.stageHeight
  37.             
  38.             
  39.             var n:int = voices.length;
  40.             for (var i:int = 0; i < n; i++) 
  41.             {
  42.                 var s:Shape = new Shape()
  43.                 var x:Number = stageHeight * Math.random() * .5 - stageHeight * .25;
  44.                 var y:Number = stageHeight * Math.random() * .5 - stageHeight * .25;
  45.                 s.graphics.beginFill(0xFFFFFF * Math.random());
  46.                 s.graphics.drawCircle(x, y, Math.random() * 20 + 20);
  47.                 s.alpha = .5
  48.                 s.x = stage.stageWidth / 2;
  49.                 s.y = stage.stageHeight / 2;
  50.                 
  51.                 particles[i] = s
  52.                 addChild(s)
  53.             }
  54.             addEventListener(Event.ENTER_FRAME,
  55.             function(e:Event):void {
  56.                 
  57.                 var n:int = particles.length
  58.                 for (var i:int = 0; i < n; i++) 
  59.                 {
  60.                     var p:Shape = particles[i]
  61.                     p.rotation += i % 2 * 2 - 1;
  62.                     p.scaleX += (1 - p.scaleX) * .4;
  63.                     p.scaleY += (1 - p.scaleY) * .4;
  64.                 }
  65.             })            
  66.             filters = [new BlurFilter(55)]
  67.             sound = new Sound()
  68.             sound.addEventListener(SampleDataEvent.SAMPLE_DATA, updateVoice)
  69.             sound.play()
  70.         }
  71.         
  72.         private function updateVoice(e:SampleDataEvent):void
  73.         {
  74.             var n:Number = LATENCY
  75.             
  76.             count++
  77.             var c8:int = count %8
  78.             var c16:int = count %16
  79.             var c32:int = count %32
  80.             var c64:int = count % 64
  81.             
  82.             
  83.             if (count % 2 == 0 ) {
  84.                 var ran:Number = Math.random()
  85.                 if(ran > .6)
  86.                 voices[1].play()
  87.                 else if(ran > .3)
  88.                 voices[2].play()
  89.                 
  90.                 var ran2:Number = Math.random()
  91.                 if (ran < .25)
  92.                 voices[0].play()
  93.                 
  94.             }
  95.             if (count % 28 == 7)
  96.                 voices[3].play()
  97.             else if (count % 28 == 21)
  98.                 voices[3].play()
  99.  
  100.             for (var i:int = 0; i < n; i++) 
  101.             {
  102.                 var sample:Number = 0
  103.                 
  104.                 for each (var v:Voice in voices) 
  105.                     sample += v.pulse;
  106.                 
  107.                 e.data.writeFloat(sample)
  108.                 e.data.writeFloat(sample)
  109.             }
  110.         }
  111.  
  112.     }
  113.     
  114. }
  115. class Voice 
  116. {
  117.     
  118.     private const PI2:Number = Math.PI * 2;
  119.     private const SAMPLE_RATE:Number = 44100
  120.     
  121.     private var phase:Number = 0
  122.     public var frequency:Number     
  123.     public var volume:Number;
  124.     public var attack:int;
  125.     public var decay:int;
  126.     public var sustain:int;
  127.     private var position:int     = 0
  128.     private var amplifier:Number = 0
  129.     
  130.     public function Voice(
  131.     frequency:Number = 440,
  132.     volume:Number    = .2,
  133.     attack:int       = 1000,
  134.     decay:int        = 1000,
  135.     sustain:int      = 5000 )
  136.     {
  137.         this.frequency = frequency
  138.         this.volume = volume
  139.         this.attack = attack
  140.         this.decay = decay
  141.         this.sustain = sustain
  142.     }
  143.     public function get pulse():Number
  144.     {
  145.         return Math.sin(updatePhase()) * updateAmplifier() * volume;
  146.     }
  147.     public function play():void 
  148.     {
  149.         position = 0
  150.     }
  151.     public function updatePhase():Number
  152.     {
  153.         phase += PI2 * frequency / SAMPLE_RATE
  154.         phase %= PI2;
  155.         return phase
  156.     }    
  157.     public function updateAmplifier():Number
  158.     {
  159.         var position:int = (this.position++ )
  160.         if (position >= sustain) {
  161.             amplifier = 0
  162.         }else if (position < attack) {
  163.             amplifier += 1/attack
  164.         }else if (position > (sustain-decay)) {
  165.             amplifier -= 1/decay
  166.         }
  167.         return amplifier;
  168.     }
  169. }
  170. class Bass extends Voice 
  171. {
  172.     public function Bass()
  173.     {
  174.         super(300,1,100,1000,5000)
  175.     }
  176.     public override function play():void 
  177.     {
  178.         super.play()
  179.         frequency = 300
  180.         
  181.     }
  182.     public override function get pulse():Number
  183.     {
  184.         this.frequency += (10 - frequency) / 2000;
  185.         return Math.sin(updatePhase()) * updateAmplifier() * volume;
  186.     }    
  187. }
  188. class Sine extends Voice 
  189. {
  190.     
  191.     public function Sine(
  192.     frequency:Number = 440,
  193.     volume:Number    = .2,
  194.     attack:int       = 1000,
  195.     decay:int        = 1000,
  196.     sustain:int      = 5000 )
  197.     {
  198.         super(frequency,volume,attack,decay,sustain)
  199.     }
  200.     public override function get pulse():Number
  201.     {
  202.         return Math.sin(updatePhase()) * updateAmplifier() * volume;
  203.     }    
  204. }
  205. class Noise extends Voice 
  206. {
  207.     public function Noise(
  208.     volume:Number    = .2,
  209.     attack:int       = 1000,
  210.     decay:int        = 1000,
  211.     sustain:int      = 3000 )
  212.     {
  213.         super(440,volume,attack,decay,sustain)
  214.     }
  215.     public override function get pulse():Number
  216.     {
  217.         return (Math.random() * 2 - 1) * updateAmplifier() * volume;
  218.     }
  219. }
noswf
  1. // forked from kappaLab's ドラムンベース(っぽいもの)
  2. package  
  3. {
  4.     
  5.     import flash.display.Sprite
  6.     import flash.display.Shape
  7.     import flash.events.Event;
  8.     import flash.events.SampleDataEvent;
  9.     import flash.filters.BlurFilter;
  10.     import flash.media.Sound;
  11.     
  12.     [SWF(backgroundColor=0x000000, frameRate=60)]
  13.     public class Drumnbass_3 extends Sprite 
  14.     {
  15.         private const PI2:Number = Math.PI * 2;
  16.         private const SAMPLE_RATE:Number = 44100;    
  17.         private const LATENCY:int = 4410 //2048~8192
  18.         private var sound:Sound;
  19.         private var delay:Delay = new Delay(LATENCY*6.05,1,-0.6,-0.2);
  20.        
  21.         private var voices:Vector.<Voice> = new Vector.<Voice>()
  22.         private var particles:Vector.<Shape> = new Vector.<Shape>()
  23.         private var count:int = 0
  24.         
  25.         public function Drumnbass_3() 
  26.         {
  27.             init()
  28.         }
  29.         
  30.         public function init():void 
  31.         {
  32.             voices[0] = new Voice(60,.4,50,8000,10000,2.15,1,1200,4)
  33.             voices[1] = new Voice(320,.2,100,500,600,4,1,500)
  34.             voices[2] = new Voice(120,.5,50,500,600,7,6,100,8)
  35.             voices[3] = new Voice(880,.5,50,700,1200,3,6,400)
  36.             voices[4] = new Voice(640,.5,100,1000,1200,9,4,100,9)
  37.             voices[5] = new Voice(440,.5,50,1000,1200,3,9,800)
  38.             
  39.             var stageWidth:Number = stage.stageWidth
  40.             var stageHeight:Number = stage.stageHeight
  41.             
  42.             
  43.             var n:int = voices.length;
  44.             for (var i:int = 0; i < n; i++) 
  45.             {
  46.                 var s:Shape = new Shape()
  47.                 var x:Number = stageHeight * Math.random() * .5 - stageHeight * .25;
  48.                 var y:Number = stageHeight * Math.random() * .5 - stageHeight * .25;
  49.                 s.graphics.beginFill(0xFFFFFF * Math.random());
  50.                 s.graphics.drawCircle(x, y, Math.random() * 20 + 20);
  51.                 s.alpha = .5
  52.                 s.x = stage.stageWidth / 2;
  53.                 s.y = stage.stageHeight / 2;
  54.                 
  55.                 particles[i] = s
  56.                 addChild(s)
  57.             }
  58.             addEventListener(Event.ENTER_FRAME,
  59.             function(e:Event):void {
  60.                 
  61.                 var n:int = particles.length
  62.                 for (var i:int = 0; i < n; i++) 
  63.                 {
  64.                     var p:Shape = particles[i]
  65.                     p.rotation += i % 2 * 2 - 1;
  66.                     p.scaleX += (1 - p.scaleX) * .4;
  67.                     p.scaleY += (1 - p.scaleY) * .4;
  68.                 }
  69.             })            
  70.             filters = [new BlurFilter(55)]
  71.             sound = new Sound()
  72.             sound.addEventListener(SampleDataEvent.SAMPLE_DATA, updateVoice)
  73.             sound.play()
  74.         }
  75.         
  76.         private function updateVoice(e:SampleDataEvent):void
  77.         {
  78.             var n:Number = LATENCY
  79.             
  80.             count++
  81.             var c8:int = count %8
  82.             var c16:int = count %16
  83.             var c32:int = count %32
  84.             var c64:int = count % 64
  85.             
  86.             if (c8 == 0 ||
  87.                 c8 == 1 ||
  88.                 c8 == 2 ||
  89.                 c8 == 3 ) {
  90.                 if (Math.random() > .3) {
  91.                     voices[2].play();
  92.                     particles[2].scaleX = particles[2].scaleY = 2
  93.                 }else {
  94.                     voices[3].play()
  95.                     particles[3].scaleX = particles[3].scaleY = 2
  96.                 }
  97.             }
  98.             if (c8 == 6 ||
  99.                 c8 == 7 ) {
  100.                 voices[1].play()
  101.                 particles[1].scaleX = particles[1].scaleY = 2.5
  102.             }
  103.             if (count % 16 == 11) {
  104.                 particles[0].scaleX = particles[0].scaleY = 3
  105.                 voices[0].play()
  106.             }
  107.             
  108.             if (count % 32 == 8) {
  109.                 particles[4].scaleX = particles[4].scaleY = 3
  110.                 voices[4].play()
  111.             }
  112.             
  113.             if (count % 32 == 10 && Math.random()>.3){
  114.                 particles[5].scaleX = particles[5].scaleY = 4
  115.                 voices[5].play()
  116.             }
  117.             for (var i:int = 0; i < n; i++) 
  118.             {
  119.                 var sample:Number = 0
  120.                 
  121.                 for each (var v:Voice in voices) 
  122.                     sample += v.pulse;
  123.                 //ディレイ
  124.                  sample = delay.process(sample)
  125.                 sample = Math.max(-1,sample)
  126.                 sample = Math.min(1,sample)
  127.                 //ロービット
  128.                  sample = int(sample*64)/64
  129.                 e.data.writeFloat(sample)
  130.                 e.data.writeFloat(sample)
  131.             }
  132.         }
  133.  
  134.     }
  135.     
  136. }
  137. class Delay {
  138.     public var time:int
  139.     public var dry:Number
  140.     public var wet:Number
  141.     public var feedback:Number
  142.     private var buf:Array=[]
  143.     private var position:Number
  144.     public function Delay(time:int, dry:Number=1, wet:Number=0.5, feedback:Number=0.3){
  145.         this.time = time
  146.         this.dry = dry
  147.         this.wet = wet
  148.         this.feedback = feedback
  149.         position = 0
  150.     }
  151.     public function process(sample:Number):Number{
  152.         var dSample:Number = 0
  153.         if(buf[position]!=undefined)
  154.             dSample = buf[position];
  155.         buf[(position+time)%time]=sample*wet+dSample*feedback
  156.         position++
  157.         position%=time
  158.         return sample*dry + dSample
  159.     }
  160. }
  161. class Voice {
  162.     
  163.     private const PI2:Number = Math.PI * 2;
  164.     private const SAMPLE_RATE:Number = 44100
  165.     
  166.     private var phase:Number = 0
  167.     public var frequency:Number     
  168.     public var volume:Number;
  169.     public var gain:Number;
  170.     public var attack:int;
  171.     public var decay:int;
  172.     public var sustain:int;
  173.     public var modFrequency:Number;
  174.     public var fmIndex:Number;
  175.     public var fmDecay:Number;
  176.     private var position:int     = 0
  177.     private var amplifier:Number = 0
  178.     private var fmAmplifier:Number = 0
  179.     
  180.     public function Voice(
  181.     frequency:Number = 440,
  182.     volume:Number    = .2,
  183.     attack:int       = 1000,
  184.     decay:int        = 1000,
  185.     sustain:int      = 5000,
  186.     modFrequency:Number = 1,
  187.     fmIndex:Number      = 1,
  188.     fmDecay:int = 4000,
  189.     gain:Number = 1 )
  190.     {
  191.         this.frequency = frequency
  192.         this.volume = volume
  193.         this.attack = attack
  194.         this.decay = decay
  195.         this.sustain = sustain
  196.         this.modFrequency = modFrequency
  197.         this.fmIndex = fmIndex
  198.         this.fmDecay = fmDecay
  199.         this.gain = gain
  200.     }
  201.     public function get pulse():Number
  202.     {
  203.         updatePhase()
  204.         updateAmplifier() 
  205.         var sample:Number
  206.         sample = Math.sin(phase+Math.sin(phase*modFrequency)*fmIndex*fmAmplifier) * amplifier;
  207.         if(gain!=1){
  208.             sample *= gain;
  209.             sample = Math.max(-1,sample)
  210.             sample = Math.min(1,sample)
  211.         }
  212.         return sample * volume
  213.     }
  214.     public function play():void 
  215.     {
  216.         position = 0
  217.         amplifier = 0
  218.         fmAmplifier = 1
  219.    }
  220.     public function updatePhase():Number
  221.     {
  222.         phase += PI2 * frequency / SAMPLE_RATE
  223.         phase %= PI2;
  224.         return phase
  225.     }    
  226.     public function updateAmplifier():Number
  227.     {
  228.         var position:int = (this.position++ )
  229.         if (position >= sustain) {
  230.             amplifier = 0
  231.             fmAmplifier = 1
  232.         }else if (position < attack) {
  233.             amplifier += 1/attack
  234.         }else if (position > (sustain-decay)) {
  235.             amplifier -= 1/decay
  236.         }
  237.         fmAmplifier -= 1/fmDecay
  238.         fmAmplifier = Math.max(fmAmplifier,0)
  239.         return amplifier;
  240.     }
  241. }
noswf
Get Adobe Flash Player