チェンジセット 649

差分発生行の前後
無視リスト:
コミット日時:
2008/06/17 17:43:27 (4 年前)
コミッタ:
zk33
ログメッセージ:

サンプラー的なもの、まだ途中だけどひとまず動くようになったのでコミットしておいてみる。

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/sazameki/branches/fp10/src/Example.as

    r364 r649  
    1 /* 
    2  * -------------------------------------- 
    3  * sazameki -- audio manipulating library 
    4  * http://sazameki.org/ 
    5  * -------------------------------------- 
    6  *  
    7  * - developed by     Takaaki Yamazaki 
    8  *                    http://www.zkdesign.jp/ 
    9  * - supported by     Spark project 
    10  *                    http://www.libspark.org/ 
    11  */ 
    12  
    13 /* 
    14  * Licensed under the MIT License 
    15  *  
    16  * Copyright (c) 2008 Takaaki Yamazaki 
    17  *  
    18  * Permission is hereby granted, free of charge, to any person obtaining a copy 
    19  * of this software and associated documentation files (the "Software"), to deal 
    20  * in the Software without restriction, including without limitation the rights 
    21  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
    22  * copies of the Software, and to permit persons to whom the Software is 
    23  * furnished to do so, subject to the following conditions: 
    24  *  
    25  * The above copyright notice and this permission notice shall be included in 
    26  * all copies or substantial portions of the Software. 
    27  *  
    28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
    29  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
    30  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
    31  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
    32  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
    33  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
    34  * THE SOFTWARE. 
    35  */ 
    36  
    37 package  { 
     1package  { 
    382        import flash.display.Sprite; 
    393        import flash.media.Sound; 
  • as3/sazameki/branches/fp10/src/org/sazameki/audio/core/Sample.as

    r364 r649  
    4242        */ 
    4343        public class Sample { 
     44                /* 
     45                public var left:Vector.<Number>; 
     46                public var right:Vector.<Number>; 
    4447                 
    45                 public var left:Number; 
    46                 public var right:Number; 
    47                  
    48                 public function Sample(left:Number=0.0,right:Number=0.0) { 
     48                public function Sample(length:uint, setting:AudioSetting = null ) { 
    4949                        this.left=left; 
    5050                        this.right=right; 
    5151                } 
    5252                 
     53                */ 
     54                 
     55                public var left:Number; 
     56                public var right:Number; 
     57                public function Sample(left:Number=0, right:Number = 0) 
     58                { 
     59                        this.left = left; 
     60                        this.right = right; 
     61                         
     62                } 
    5363                public function toString():String{ 
    5464                        return('[l:'+left+',r:'+right+']'); 
  • as3/sazameki/branches/fp10/src/org/sazameki/audio/processor/effects/Delay.as

    r364 r649  
    3838        import org.sazameki.audio.core.Sample; 
    3939        import org.sazameki.audio.engine.ssGenerator.SsAudioSetting; 
     40        import org.sazameki.audio.processor.AudioProcessor; 
    4041        import org.sazameki.audio.processor.SsAudioProcessor; 
    4142        import org.sazameki.data.RingArray; 
    4243 
    43         public class Delay extends SsAudioProcessor { 
     44        public class Delay extends AudioProcessor 
     45        { 
    4446                 
    4547                private var _buffer:RingArray; 
  • as3/sazameki/branches/fp10/src/org/sazameki/audio/processor/oscillator/Oscillator.as

    r364 r649  
    3737        import org.sazameki.audio.core.Sample; 
    3838        import org.sazameki.audio.core.AudioSetting; 
     39        import org.sazameki.audio.core.SampleBuffer; 
    3940        import org.sazameki.audio.engine.ssGenerator.SsAudioSetting; 
     41        import org.sazameki.audio.processor.AudioProcessor; 
    4042        import org.sazameki.audio.processor.envelope.IEnvelope; 
    4143        import org.sazameki.audio.processor.SsAudioProcessor; 
    4244        import org.sazameki.audio.utils.Converter; 
    4345 
    44         public class Oscillator extends SsAudioProcessor{ 
     46        public class Oscillator extends AudioProcessor{ 
    4547                 
    4648                 
    47                 protected var minFreq:Number
    48                 protected var maxFreq:Number
     49                protected var _minFreq:Number=440
     50                protected var _maxFreq:Number=440
    4951                protected var diffFreq:Number; 
    5052                protected var phase:Number; 
    51                 protected var freq:Number; 
     53                protected var _freq:Number; 
    5254                protected var phaseModCoeff:Number; 
    5355                 
     
    6466                } 
    6567                 
    66                 override public function initialize(setting:SsAudioSetting,params:Array=null,additionalProcessors:Object=null):void{ 
     68                public function set minFreq(value:Number):void  
     69                { 
     70                        _minFreq = value; 
     71                         
     72                } 
     73                 
     74                public function set freq(value:Number):void  
     75                { 
     76                        _minFreq = value; 
     77                        _maxFreq = value; 
     78                } 
     79                 
     80                override public function initialize(setting:AudioSetting,params:Array=null,additionalProcessors:Object=null):void{ 
    6781                        super.initialize(setting,params); 
    6882                        phase=0; 
    6983                         
    7084                        //params:ピッチの設定(min,max) 
    71                          
    72                         minFreq=getFreq(params[0]); 
    73                         if(params[1]){ 
    74                                 maxFreq=getFreq(params[1]); 
    75                         }else{ 
    76                                 maxFreq=minFreq; 
     85                        if(params){ 
     86                                _minFreq=getFreq(params[0]); 
     87                                if(params[1]){ 
     88                                        _maxFreq=getFreq(params[1]); 
     89                                }else{ 
     90                                        _maxFreq=_minFreq; 
     91                                } 
     92                                freq=_minFreq; 
     93                                diffFreq=_maxFreq-_minFreq; 
     94 
     95                                //phase modulationする? 
     96                                if(params[2]){ 
     97                                        phaseModCoeff=params[2]; 
     98                                } 
    7799                        } 
    78                         freq=minFreq; 
    79                         diffFreq=maxFreq-minFreq; 
    80  
    81                         //phase modulationする? 
    82                         if(params[2]){ 
    83                                 phaseModCoeff=params[2]; 
    84                         } 
    85                          
    86100                         
    87101                        //pitch envelope 
     
    130144                 
    131145                 
    132                 override public function processAudio(samples:Array):void{ 
     146                override public function processAudio(samples:SampleBuffer):void{ 
    133147                         
    134148                        //サンプル生成 
    135                         var len:int=samples.length; 
    136                         var sample:Sample; 
     149                        var len:int = samples.length; 
     150                         
     151                         
     152                        var bufferL:Vector.<Number> = samples.left; 
     153                        var bufferR:Vector.<Number> = samples.right; 
     154                        var hasRight:Boolean = Boolean(bufferR); 
    137155                        var sig:Number; 
    138156                        var c:Number=Math.PI*2/_setting.sampleRate; 
     
    140158                         
    141159                        for(var i:int=0;i<len;i++){ 
    142                                 sample=samples[i]; 
    143                                 input=sample.left
     160                                 
     161                                input = bufferL[i]
    144162                                sig=generate(phase); 
    145163                                 
     
    150168                                 
    151169                                //波形とボリュームのエンベロープ適用 
    152                                 sample.left=sample.right=sig; 
     170                                bufferL[i] = sig; 
     171                                if(hasRight){ bufferR[i] = sig } 
    153172                                 
    154173                                //ピッチエンベロープ取得して今のピッチ設定 
    155174                                if(pitchEnvelope){ 
    156                                         freq=minFreq+(diffFreq*pitchEnvelope.getEnvAt(_idx)); 
     175                                        _freq=_minFreq+(diffFreq*pitchEnvelope.getEnvAt(_idx)); 
    157176                                }else{ 
    158                                         freq=minFreq; 
     177                                        _freq=_minFreq; 
    159178                                } 
    160179                                 
    161180                                //phase modulation 
    162181                                if(phaseModCoeff){ 
    163                                         freq+=input*phaseModCoeff; 
     182                                        _freq+=input*phaseModCoeff; 
    164183                                } 
    165184                                 
    166185                                 
    167186                                //phaseの加算 
    168                                 phase+=c*freq; 
     187                                phase+=c*_freq; 
    169188 
    170189                                _idx++; 
  • as3/sazameki/branches/fp10/src/org/sazameki/audio/utils/Converter.as

    r364 r649  
    1 /* 
    2  * -------------------------------------- 
    3  * sazameki -- audio manipulating library 
    4  * http://sazameki.org/ 
    5  * -------------------------------------- 
    6  *  
    7  * - developed by     Takaaki Yamazaki 
    8  *                    http://www.zkdesign.jp/ 
    9  * - supported by     Spark project 
    10  *                    http://www.libspark.org/ 
    11  */ 
    12  
    13 /* 
    14  * Licensed under the MIT License 
    15  *  
    16  * Copyright (c) 2008 Takaaki Yamazaki 
    17  *  
    18  * Permission is hereby granted, free of charge, to any person obtaining a copy 
    19  * of this software and associated documentation files (the "Software"), to deal 
    20  * in the Software without restriction, including without limitation the rights 
    21  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
    22  * copies of the Software, and to permit persons to whom the Software is 
    23  * furnished to do so, subject to the following conditions: 
    24  *  
    25  * The above copyright notice and this permission notice shall be included in 
    26  * all copies or substantial portions of the Software. 
    27  *  
    28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
    29  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
    30  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
    31  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
    32  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
    33  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
    34  * THE SOFTWARE. 
    35  */ 
    36  
    37  
    38  
    39  
    40 package org.sazameki.audio.utils { 
     1package org.sazameki.audio.utils { 
    412        /** 
    423        * Converter for converting MIDI note number to frequency.