チェンジセット 2607

差分発生行の前後
無視リスト:
コミット日時:
2009/05/09 01:58:03 (3 年前)
コミッタ:
keim
ログメッセージ:

サウンドライブラリ SiON ver0.5.1 更新

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/SiOPM/trunk/samples/SiOPMJavaScriptBridge/SiOPMJavaScriptBridge.as

    r2526 r2607  
    66     
    77    import org.si.sound.*; 
    8     import org.si.sound.driver.Translator; 
     8    import org.si.sound.events.*; 
     9    import org.si.sound.mml.Translator; 
    910     
    1011     
     
    4344             
    4445            // register handlers 
    45             driver.addEventListener(SiONEvent.COMPILE_PROGRESS, _onCompileProgress); 
    46             driver.addEventListener(SiONEvent.COMPILE_COMPLETE, _onCompileComplete); 
    47             driver.addEventListener(ErrorEvent.ERROR,           _onError); 
    48             driver.addEventListener(SiONEvent.STREAM,           _onStream); 
    49             driver.addEventListener(SiONEvent.STREAM_START,     _onStreamStart); 
    50             driver.addEventListener(SiONEvent.STREAM_STOP,      _onStreamStop); 
     46            driver.addEventListener(SiONEvent.QUEUE_PROGRESS, _onCompileProgress); 
     47            driver.addEventListener(SiONEvent.QUEUE_COMPLETE, _onCompileComplete); 
     48            driver.addEventListener(ErrorEvent.ERROR,         _onError); 
     49            driver.addEventListener(SiONEvent.STREAM,         _onStream); 
     50            driver.addEventListener(SiONEvent.STREAM_START,   _onStreamStart); 
     51            driver.addEventListener(SiONEvent.STREAM_STOP,    _onStreamStop); 
    5152             
    5253            // callback onLoad 
     
    5960    // event handlers 
    6061    //-------------------------------------------------- 
    61         private function _onCompileProgress(e:SiONEvent) : void { ExternalInterface.call('SIOPM._internal_onCompileProgress', driver.compileProgress); } 
     62        private function _onCompileProgress(e:SiONEvent) : void { ExternalInterface.call('SIOPM._internal_onCompileProgress', driver.jobProgress); } 
    6263        private function _onError(e:ErrorEvent)          : void { ExternalInterface.call('SIOPM._internal_onError', e.text); } 
    6364        private function _onStream(e:SiONEvent)          : void { ExternalInterface.call('SIOPM._internal_onStream'); } 
     
    7475        { 
    7576            if (mml) { 
    76                 driver.compile(mml, 200, data); 
     77                driver.compileQueue(mml, data); 
     78                driver.startQueue(200); 
    7779                return true; 
    7880            } 
     
    124126import org.si.sound.*; 
    125127class pcmExample { 
    126     [Embed(source="hit.mp3")]   var hit_mp3:Class; 
    127     [Embed(source="kick.mp3")]  var kick_mp3:Class; 
    128     [Embed(source="sdw.mp3")]   var sdw_mp3:Class; 
    129     [Embed(source="sds.mp3")]   var sds_mp3:Class; 
    130     [Embed(source="toml.mp3")]  var toml_mp3:Class; 
    131     [Embed(source="tomh.mp3")]  var tomh_mp3:Class; 
    132     [Embed(source="hatc.mp3")]  var hatc_mp3:Class; 
    133     [Embed(source="hath.mp3")]  var hath_mp3:Class; 
    134     [Embed(source="hato.mp3")]  var hato_mp3:Class; 
    135     [Embed(source="crash.mp3")] var crash_mp3:Class; 
    136     [Embed(source="bell.mp3")]  var bell_mp3:Class; 
     128    [Embed(source="hit.mp3")]   private var hit_mp3:Class; 
     129    [Embed(source="kick.mp3")]  private var kick_mp3:Class; 
     130    [Embed(source="sdw.mp3")]   private var sdw_mp3:Class; 
     131    [Embed(source="sds.mp3")]   private var sds_mp3:Class; 
     132    [Embed(source="toml.mp3")]  private var toml_mp3:Class; 
     133    [Embed(source="tomh.mp3")]  private var tomh_mp3:Class; 
     134    [Embed(source="hatc.mp3")]  private var hatc_mp3:Class; 
     135    [Embed(source="hath.mp3")]  private var hath_mp3:Class; 
     136    [Embed(source="hato.mp3")]  private var hato_mp3:Class; 
     137    [Embed(source="crash.mp3")] private var crash_mp3:Class; 
     138    [Embed(source="bell.mp3")]  private var bell_mp3:Class; 
    137139     
    138140     
    139141    function pcmExample(driver:SiONDriver) 
    140142    { 
    141         driver.setPCMData (0, SiONUtil.serializeSound(new hit_mp3())); 
    142         driver.setWaveData(60, SiONUtil.getRawData(new kick_mp3())); //o5c 
    143         driver.setWaveData(62, SiONUtil.getRawData(new sdw_mp3()));  //o5d 
    144         driver.setWaveData(64, SiONUtil.getRawData(new sds_mp3()));  //o5e 
    145         driver.setWaveData(65, SiONUtil.getRawData(new toml_mp3())); //o5f 
    146         driver.setWaveData(67, SiONUtil.getRawData(new tomh_mp3())); //o5g 
    147         driver.setWaveData(48, SiONUtil.getRawData(new hatc_mp3())); //o4c 
    148         driver.setWaveData(50, SiONUtil.getRawData(new hath_mp3())); //o4d 
    149         driver.setWaveData(52, SiONUtil.getRawData(new hato_mp3())); //o4e 
    150         driver.setWaveData(53, SiONUtil.getRawData(new crash_mp3())); //o4f 
    151         driver.setWaveData(55, SiONUtil.getRawData(new bell_mp3()));  //o4g 
     143        driver.setPCMData(0, new hit_mp3()); 
     144        driver.setWaveData(60, new kick_mp3()); //o5c 
     145        driver.setWaveData(62, new sdw_mp3());  //o5d 
     146        driver.setWaveData(64, new sds_mp3());  //o5e 
     147        driver.setWaveData(65, new toml_mp3()); //o5f 
     148        driver.setWaveData(67, new tomh_mp3()); //o5g 
     149        driver.setWaveData(48, new hatc_mp3()); //o4c 
     150        driver.setWaveData(50, new hath_mp3()); //o4d 
     151        driver.setWaveData(52, new hato_mp3()); //o4e 
     152        driver.setWaveData(53, new crash_mp3()); //o4f 
     153        driver.setWaveData(55, new bell_mp3());  //o4g 
    152154    } 
    153155} 
    154156*/ 
     157 
  • as3/SiOPM/trunk/samples/SiOPMJavaScriptBridge/siopm_js.html

    r2526 r2607  
    33    <meta http-equiv='content-type' content='text/html;charset=utf-8'> 
    44    <title>SiOPM on javascript</title> 
    5     <script type="text/javascript" src="jquery.js"></script> 
    6     <script type="text/javascript" src="siopm.js"></script> 
     5    <script type='text/javascript' src='../script/jquery.js'></script> 
     6    <script type='text/javascript' src='../script/siopm.js'></script> 
    77    <script type="text/javascript"><!-- 
    88      function translate() { 
     
    4141      }); 
    4242    //--></script> 
     43<script type="text/javascript"> 
     44var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); 
     45document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); 
     46</script> 
     47<script type="text/javascript"> 
     48try { 
     49var pageTracker = _gat._getTracker("UA-4060125-4"); 
     50pageTracker._trackPageview(); 
     51} catch(err) {}</script> 
    4352     
    4453  </head> 
     
    4756    <input type="button"             onClick="translate();"  disabled="true" value="tss"/> 
    4857    <span id="msg">Please Enable the JavaScript.</span><br/> 
    49     <a href="siopm_mml_ref_050.html" target="_blank">MML reference</a><br/> 
    50     <textarea id="ta" style="height:90%; width:100%; font-size:12px; font-family:MS Gothic, monospace;"> 
     58    <a href="http://mmltalks.appspot.com/document/siopm_mml_ref_05.html" target="_blank">MML reference</a><br/> 
     59    <textarea id="ta" style="height:80%; width:100%; font-size:12px; font-family:MS Gothic, monospace;"> 
    5160#TITLE{Penetration SCC version (From TSSCP thread STG3 930-932 by ID:A7Ri5mEU)}; 
    5261#WAVB0{36454d4b41362f303639332309efd9cc362f220df2d9c8c3c6cbccc6bab0aeb7}; 
  • as3/SiOPM/trunk/samples/SiOPMKeyboard/KeyDisplay.as

    r2526 r2607  
    1010        private var tf0:TextField = setTextField.constant(new TextField(), {text:"<q", color:0, font:'_sans', bold:true, x:0}); 
    1111        private var tf1:TextField = setTextField.constant(new TextField(), {text:"w>", color:0, font:'_sans', bold:true, x:220}); 
    12         private var keys:Vector.<Sprite> = new Vector.<Sprite>(17, true); 
     12        private var keys :Vector.<Sprite> = new Vector.<Sprite>(17, true); 
     13        private var keyOn:Vector.<Shape>  = new Vector.<Shape>(17, true); 
    1314         
    1415        function KeyDisplay()  
     
    2122        } 
    2223         
    23         public function noteOn() : void  
     24        public function noteOn(key:int) : void  
    2425        { 
    25              
     26            while (key<0) key += 12; 
     27            while (key>16) key -= 12; 
     28            keyOn[key].visible = true; 
    2629        } 
    2730         
    28         public function noteOff() : void  
     31        public function noteOff(key:int) : void  
    2932        { 
    30              
     33            while (key<0) key += 12; 
     34            while (key>16) key -= 12; 
     35            keyOn[key].visible = false; 
    3136        } 
    3237         
     
    4146                pk = wk[k]; 
    4247                keys[k] = new Sprite(); 
     48                keyOn[k] = new Shape(); 
    4349                if (wk[k]==0) { // white 
    4450                    keys[k].graphics.beginFill(0xffffff); 
     51                    keyOn[k].graphics.beginFill(0x000080, 0.5); 
    4552                    tf = setTextField.constant(new TextField(), {text:kt[k], color:0, font:'_sans', bold:true, x:5, y:80}); 
    4653                } else {    // black 
    4754                    keys[k].graphics.beginFill(0x404040); 
     55                    keyOn[k].graphics.beginFill(0x8080ff, 0.5); 
    4856                    tf = setTextField.constant(new TextField(), {text:kt[k], color:0xffffff, font:'_sans', bold:true, x:5, y:50}); 
    4957                } 
     58                keyOn[k].graphics.drawPath(cmd, vts[wk[k]]); 
     59                keyOn[k].graphics.endFill(); 
     60                keyOn[k].visible = false; 
    5061                keys[k].graphics.lineStyle(3, 0x000000); 
    5162                keys[k].graphics.drawPath(cmd, vts[wk[k]]); 
    5263                keys[k].graphics.endFill(); 
    5364                keys[k].addChild(tf); 
     65                keys[k].addChild(keyOn[k]); 
    5466                keys[k].x = x; 
    5567                if (wk[k]==0) addChild(keys[k]); 
  • as3/SiOPM/trunk/samples/SiOPMKeyboard/main.mxml

    r2526 r2607  
    1717      import org.si.utils.SiOPMChannelParamModify; 
    1818      import org.si.sound.*; 
     19      import org.si.sound.events.*; 
    1920      import org.si.sound.module.SiOPMChannelParam; 
    20       import org.si.sound.driver.SiMMLSequencerTrack; 
     21      import org.si.sound.mml.SiMMLTrack; 
    2122      import org.si.sound.effect.SiEffectStereoDelay; 
    2223      import org.si.sound.effect.SiEffectStereoChorus; 
     
    2526    // variables 
    2627    //------------------------------ 
    27       static public  var _p:SiOPMChannelParam; 
    2828      static private var _fileSystem:TextFileSystem = new TextFileSystem(); 
    2929      static private var _dataManager:DataManager; 
    3030      static private var _driver:SiONDriver; 
     31       
     32      static private var _toneSetting:SiONToneSetting; 
    3133      static private var _keyFlag:uint; 
    3234      static private var _keyTable:Vector.<int>; 
     
    3739       
    3840       
    39     // handlers 
     41    // initializer 
    4042    //------------------------------ 
    4143      private function _onCreate() : void 
    4244      { 
     45        // initialize instances 
    4346        _fileSystem = new TextFileSystem(); 
    4447        _dataManager = new DataManager(_fileSystem, "/bin/DataManager/data"); 
    45         _driver = new SiONDriver(2, 44100, 16, 2048, true); 
    46         _driver.addEventListener(SiONEvent.STREAM_START, _onStreamStart); 
    47 //        _driver.addEventListener(SiONEvent.STREAM, _onStream); 
     48        _driver = new SiONDriver(); 
     49        _driver.debugMode = true; 
     50        _delaySend = 0.25; 
     51        _chorusSend = 0; 
     52         
    4853        _driver.addEventListener(ErrorEvent.ERROR, _onError); 
    49          
    50         // set effectors 
     54        _driver.addEventListener(SiONTrackEvent.NOTE_ON_FRAME,  _onNoteOnFrame); 
     55        _driver.addEventListener(SiONTrackEvent.NOTE_OFF_FRAME, _onNoteOffFrame); 
     56         
     57        // tone setting 
     58        _toneSetting = new SiONToneSetting(); 
     59         
     60        // effector setting 
    5161        var dly:SiEffectStereoDelay  = new SiEffectStereoDelay(); 
    52         var cho:SiEffectStereoChorus = new SiEffectStereoChorus(); 
    5362        dly.initialize(); 
    5463        dly.setParameters(200,0.2,false); 
     64        var cho:SiEffectStereoChorus = new SiEffectStereoChorus(); 
    5565        cho.initialize(); 
    5666        cho.setParameters(20,0.2,4,20); 
     67         
     68        // connect effectors 
    5769        _driver.effector.initialize(); 
    5870        _driver.effector.connect(1, dly); 
    5971        _driver.effector.connect(2, cho); 
    60         _delaySend = 0.25; 
    61         _chorusSend = 0; 
    6272 
    6373        // keyboard listener 
     
    8494        _onFileSelectorChange(); 
    8595         
    86         // start stream without data(null) and effectors reset(false). 
     96        // start stream without data 
    8797        _driver.play(null, false); 
    8898      } 
    8999       
     100       
    90101    // operations 
    91102    //------------------------------ 
    92103      private function _allNoteOff() : void 
    93104      { 
    94         for (var i:int=0; i<32; i++) { 
    95           _driver.noteOff(i+_baseNote); 
    96         } 
     105        for (var i:int=0; i<32; i++) _driver.noteOff(i+_baseNote); 
    97106      } 
    98107       
     
    106115    // driver events 
    107116    //------------------------------ 
    108       private function _onStreamStart(e:SiONEvent) : void 
    109       { 
    110       } 
    111        
    112       private function _onStream(e:SiONEvent) : void 
    113       { 
     117      private function _onNoteOnFrame(e:SiONTrackEvent) : void 
     118      { 
     119        keyboard.noteOn(e.note-_baseNote); 
     120      } 
     121       
     122      private function _onNoteOffFrame(e:SiONTrackEvent) : void 
     123      { 
     124        keyboard.noteOff(e.note-_baseNote); 
    114125      } 
    115126 
     
    129140            if ((_keyFlag & flag) == 0) { 
    130141              _keyFlag |= flag; 
    131               var trk:SiMMLSequencerTrack = _driver.noteOn(i+_baseNote, _p); 
     142              var trk:SiMMLTrack = _driver.noteOn(i+_baseNote, _toneSetting, 0, 0, 0, 0, 0, 1, 1); 
    132143              trk.channel.setStreamSend(1, _delaySend); 
    133144              trk.channel.setStreamSend(2, _chorusSend); 
     
    147158            _allNoteOff(); 
    148159            _baseNote -= 12; 
    149             if (_baseNote<36) _baseNote = 36
     160            if (_baseNote<24) _baseNote = 24
    150161            break; 
    151162          } 
    152163        } 
    153164      } 
    154        
    155        
     165             
    156166      private function _onKeyUp(e:KeyboardEvent) : void 
    157167      { 
     
    178188      } 
    179189       
    180        
    181190      private function _onChannelSelectorChange() : void 
    182191      { 
    183192        if (chSelect.selectedItem == null) return; 
    184193        var idx:int = chSelect.selectedItem.index; 
    185         _p = _dataManager.getParameter(idx); 
    186       } 
    187        
     194        _toneSetting.channelParam = _dataManager.getParameter(idx); 
     195      } 
     196 
    188197      private function _onChannelSelectorClose() : void 
    189198      { 
    190199        stage.focus = keyboard; 
    191200      } 
    192        
    193       private function dragDelay(e:SliderEvent) : void 
    194       { 
    195         _delaySend = e.value*0.01; 
    196         var i:int, imax:int = _driver.trackCount; 
    197         for (i=0; i<imax; i++) _driver.getTrack(i).channel.setStreamSend(1, _delaySend); 
    198       } 
    199        
    200       private function dragChorus(e:SliderEvent) : void 
    201       { 
    202         _chorusSend = e.value*0.01; 
    203         var i:int, imax:int = _driver.trackCount; 
    204         for (i=0; i<imax; i++) _driver.getTrack(i).channel.setStreamSend(2, _chorusSend); 
     201             
     202      private function changeEffectSend() : void 
     203      { 
     204        _delaySend  = delaySend.value  * 0.01; 
     205        _chorusSend = chorusSend.value * 0.01; 
     206        for each (var trk:SiMMLTrack in _driver.sequencer.tracks) { 
     207          trk.channel.setStreamSend(1, _delaySend); 
     208          trk.channel.setStreamSend(2, _chorusSend); 
     209        } 
    205210      } 
    206211    ]]> 
     
    217222                 close ="_onChannelSelectorClose();"/> 
    218223    <mx:HBox height="16" horizontalGap="0"> 
    219       <mx:HSlider id="delaySend"  width="120" height="16" maximum="100" tickInterval="10" snapInterval="5" value="25" toolTip="Delay send"  thumbDrag="dragDelay(event);"/> 
    220       <mx:HSlider id="chorusSend" width="120" height="16" maximum="100" tickInterval="10" snapInterval="5" value="0"  toolTip="Chorus send" thumbDrag="dragChorus(event);"/> 
     224      <mx:HSlider id="delaySend"  width="120" height="16" maximum="100" tickInterval="10" snapInterval="5" value="25" toolTip="Delay send"  change="changeEffectSend();"/> 
     225      <mx:HSlider id="chorusSend" width="120" height="16" maximum="100" tickInterval="10" snapInterval="5" value="0"  toolTip="Chorus send" change="changeEffectSend();"/> 
    221226    </mx:HBox> 
    222227    <my:KeyDisplay id="keyboard" addedToStage="stage.focus = this;"/> 
  • as3/SiOPM/trunk/src/org/si/sound/SiONData.as

    r2526 r2607  
    1111    import flash.media.*; 
    1212    import flash.utils.ByteArray; 
    13     import org.si.sound.driver.SiMMLData; 
     13    import org.si.sound.mml.SiMMLData; 
    1414    import org.si.sound.module.SiOPMTable; 
    1515    import org.si.utils.SLLint; 
  • as3/SiOPM/trunk/src/org/si/sound/SiONDriver.as

    r2526 r2607  
    1414    import flash.media.SoundChannel; 
    1515    import flash.media.SoundTransform; 
    16     import flash.display.Sprite
     16    import flash.display.*
    1717    import flash.utils.getTimer; 
    1818    import flash.utils.ByteArray; 
     
    2020    import org.si.utils.SLLint; 
    2121    import org.si.utils.SLLNumber; 
    22     import org.si.sound.driver.SiMMLSequencer; 
    23     import org.si.sound.driver.SiMMLSequencerTrack; 
     22    import org.si.sound.mml.SiMMLSequencer; 
     23    import org.si.sound.mml.SiMMLTrack; 
     24    import org.si.sound.mml.SiMMLEnvelopTable; 
     25    import org.si.sound.mml.SiMMLTable; 
    2426    import org.si.sound.module.SiOPMTable; 
    2527    import org.si.sound.module.SiOPMModule; 
    2628    import org.si.sound.module.SiOPMChannelParam; 
    2729    import org.si.sound.effect.SiEffectModule; 
     30    import org.si.sound.events.*; 
    2831     
    2932     
     
    3134     
    3235    /** SiON driver class.<br/> 
    33      *  -- BASIC USAGE --<br/> 
    34      *  1) Create new SiONDriver.<br/> 
    35      *  2) addChild the instance of SiONDriver onto the stage or stage's descendant.<br/> 
    36      *  3) addEventListner(SiONEvent.COMPILE_COMPLETE) to catch the finished timing of compile, and call compile("mmlString").<br/> 
    37      *  4) After the compiling (lets say, in the callback of the SiONEvent.COMPILE_COMPLETE event), call play() to start playing sound.<br/> 
    38      *  5) Call stop() to stop the sound.<br/> 
     36     * @see SiONData 
     37     * @see SiONToneSetting 
     38     * @see org.si.sound.events.SiONEvent 
     39     * @see org.si.sound.events.SiONTrackEvent 
     40     * @see org.si.sound.module.SiOPMModule 
     41     * @see org.si.sound.mml.SiMMLSequencer 
     42     * @see org.si.sound.effect.SiEffectModule 
     43@example 1) The simplest sample. Create new instance and call play with MML string.<br/> 
     44<listing version="3.0"> 
     45// create driver instance. 
     46public var driver = new SiONDriver(); 
     47... 
     48// call play() with mml string whenever you want to play sound. 
     49driver.play("t100 l8 [ ccggaag4 ffeeddc4 | [ggffeed4]2 ]2"); 
     50</listing> 
    3951     */ 
    4052    public class SiONDriver extends Sprite 
     
    4355    //---------------------------------------- 
    4456        /** version number */ 
    45         static public const VERSION:String = "0.5.0"; 
     57        static public const VERSION:String = "0.5.1"; 
     58         
    4659         
    4760        // event listener type 
    4861        private const NO_LISTEN:int = 0; 
    49         private const LISTEN_COMPILE:int = 1; 
     62        private const LISTEN_QUEUE:int = 1; 
    5063        private const LISTEN_PROCESS:int = 2; 
    5164         
     
    5871    // valiables 
    5972    //---------------------------------------- 
    60         /** sound module. */ 
     73        /** SiOPM sound module. */ 
    6174        public var module:SiOPMModule; 
    6275         
    63         /** effector. */ 
     76        /** effector module. */ 
    6477        public var effector:SiEffectModule; 
    6578         
    66         /** mml sequencer. */ 
     79        /** mml sequencer module. */ 
    6780        public var sequencer:SiMMLSequencer; 
    6881         
    69         // protected: 
    70         protected var _data:SiONData;             // data to compile or process 
    71         protected var _mmlString:String;          // mml string of previous compiling 
    72         protected var _sound:Sound;               // sound stream instance 
    73         protected var _soundChannel:SoundChannel;     // sound channel instance 
    74         protected var _soundTransform:SoundTransform; // sound transform 
    75          
    76         protected var _channelCount:int;          // module output channels (1 or 2) 
    77         protected var _sampleRate:int;            // module output frequency ratio (44100 or 22050) 
    78         protected var _bitRate:int;               // module output bitrate (0 or 8 or 16) 
    79         protected var _bufferLength:int;          // module and streaming buffer size (8192, 4096 or 2048) 
    80         protected var _throwErrorEvent:Boolean;   // true; throw ErrorEvent, false; throw Error 
    81          
    82         protected var _compileInterval:int        // interrupting interval in compile 
    83         protected var _compileProgress:Number;    // progression of compile on this que 
    84         protected var _isPaused:Boolean;          // flag to pause 
    85         protected var _position:Number;           // start position [ms] 
    86          
    87         protected var _timeCompile:int;           // total compile time. 
    88         protected var _timeProcess:int;           // averge time process in 1sec. 
    89         protected var _timeProcessTotal:int;      // total processing time in last 8 bufferings. 
    90         protected var _timeProcessData:SLLint;    // processing time data of last 8 bufferings. 
    91         protected var _timeProcessAveRatio:Number;// number to averaging _timeProcessTotal 
    92         protected var _timePrevStream:int;        // previous streaming time. 
    93         protected var _latency:Number;            // streaming latency [ms] 
    94          
    95         protected var _listenEvent:int;           // current lintening event 
    96          
    97         static protected var _compileQue:Vector.<SiONCompileQue> = null;   // compiling que 
     82         
     83        // private: 
     84        private var _data:SiONData;             // data to compile or process 
     85        private var _mmlString:String;          // mml string of previous compiling 
     86        private var _sound:Sound;               // sound stream instance 
     87        private var _soundChannel:SoundChannel;     // sound channel instance 
     88        private var _soundTransform:SoundTransform; // sound transform 
     89         
     90        private var _channelCount:int;          // module output channels (1 or 2) 
     91        private var _sampleRate:int;            // module output frequency ratio (44100 or 22050) 
     92        private var _bitRate:int;               // module output bitrate (0 or 8 or 16) 
     93        private var _bufferLength:int;          // module and streaming buffer size (8192, 4096 or 2048) 
     94        private var _debugMode:Boolean;         // true; throw Error, false; throw ErrorEvent 
     95        private var _dispatchStreamEvent:Boolean; // dispatch steam event 
     96        private var _cannotChangeBPM:Boolean;     // internal flag not to change bpm 
     97 
     98        private var _queueInterval:int;         // interupting interval to execute queued jobs 
     99        private var _queueLength:int;           // queue length to execute 
     100        private var _jobProgress:Number;        // progression of current job 
     101        private var _currentJob:int;            // current job 0=no job, 1=compile, 2=render 
     102         
     103         
     104        private var _isPaused:Boolean;          // flag to pause 
     105        private var _position:Number;           // start position [ms] 
     106         
     107        private var _triggerEventQueue:Vector.<SiONTrackEvent>; 
     108         
     109        private var _renderBuffer:Vector.<Number>;  // rendering buffer 
     110        private var _renderBufferIndex:int;         // rendering buffer writing index 
     111        private var _renderBufferSizeMax:int;       // maximum value of rendering buffer size 
     112         
     113        private var _timeCompile:int;           // previous compiling time. 
     114        private var _timeRender:int;            // previous rendering time. 
     115        private var _timeProcess:int;           // averge processing time in 1sec. 
     116        private var _timeProcessTotal:int;      // total processing time in last 8 bufferings. 
     117        private var _timeProcessData:SLLint;    // processing time data of last 8 bufferings. 
     118        private var _timeProcessAveRatio:Number;// number to averaging _timeProcessTotal 
     119        private var _timePrevStream:int;        // previous streaming time. 
     120        private var _latency:Number;            // streaming latency [ms] 
     121        private var _prevFrameTime:int;         // previous frame time 
     122        private var _frameRate:int;             // frame rate 
     123         
     124        private var _eventListenerPrior:int;    // event listeners priority 
     125        private var _listenEvent:int;           // current lintening event 
     126         
     127        static private var _jobQueue:Vector.<SiONDriverJob> = null;   // compiling/rendering jobs queue 
    98128         
    99129         
     
    103133    //---------------------------------------- 
    104134        // data 
    105         /** MML string. This property is only available during compile. */ 
     135        /** MML string (this property is only available during compile). */ 
    106136        public function get mmlString() : String { return _mmlString; } 
    107137         
    108         /** Data to compile and process. */ 
     138        /** Data to compile, render and process. */ 
    109139        public function get data() : SiONData { return _data; } 
    110140         
     
    117147         
    118148        // paramteters 
    119         /** Track count. This value is only available after play(). */ 
    120         public function get trackCount() : int { return sequencer.trackCount; } 
     149        /** Track count, this value is only available after play(). */ 
     150        public function get trackCount() : int { return sequencer.tracks.length; } 
     151         
     152        /** Streaming buffer length. */ 
     153        public function get bufferLength() : int { return _bufferLength; } 
    121154         
    122155        /** Sound volume. */ 
     
    130163        public function get pan() : Number       { return _soundTransform.pan; } 
    131164        public function set pan(p:Number) : void { 
    132             _soundTransform.pan = p;  
     165            _soundTransform.pan = p; 
    133166            if (_soundChannel) _soundChannel.soundTransform = _soundTransform; 
    134167        } 
     
    136169         
    137170        // measured time 
    138         /** total compiling time. [ms] */ 
     171        /** previous compiling time [ms]. */ 
    139172        public function get compileTime() : int { return _timeCompile; } 
    140173         
    141         /** average processing time per 1sec. [ms] */ 
     174        /** previous rendering time [ms]. */ 
     175        public function get renderTime() : int { return _timeRender; } 
     176         
     177        /** average processing time in 1sec [ms]. */ 
    142178        public function get processTime() : int { return _timeProcess; } 
    143179         
    144         /** compiling progression in one que. 0=start -> 1=finish. */ 
    145         public function get compileProgress() : Number { return _compileProgress; } 
    146          
    147         /** compiling que length. */ 
    148         public function get compileQueLength() : int { return _compileQue.length; } 
    149          
    150         /** streaming latency */ 
     180        /** progression of current compiling/rendering (0=start -> 1=finish). */ 
     181        public function get jobProgress() : Number { return _jobProgress; } 
     182         
     183        /** progression of all queued jobs (0=start -> 1=finish). */ 
     184        public function get jobQueueProgress() : Number { 
     185            if (_queueLength == 0) return 1; 
     186            return (_queueLength - _jobQueue.length - 1 + _jobProgress) / _queueLength; 
     187        } 
     188         
     189        /** compiling/rendering jobs queue length. */ 
     190        public function get jobQueueLength() : int { return _jobQueue.length; } 
     191         
     192        /** streaming latency [ms]. */ 
    151193        public function get latency() : Number { return _latency; } 
    152194         
    153195         
    154         // flag 
    155         /** Is compiling ? */ 
    156         public function get isCompiling() : Boolean { return (_compileProgress>0 && _compileProgress<1); } 
     196        // flags 
     197        /** Is job executing ? */ 
     198        public function get isJobExecuting() : Boolean { return (_jobProgress>0 && _jobProgress<1); } 
    157199         
    158200        /** Is playing sound ? */ 
     
    173215        } 
    174216         
     217        /** Beat par minute. */ 
     218        public function get bpm() : Number { 
     219            return (sequencer.isReadyToProcess) ? sequencer.bpm : sequencer.setting.defaultBPM; 
     220        } 
     221        public function set bpm(t:Number) : void { 
     222            if (sequencer.isReadyToProcess) { 
     223                if (_cannotChangeBPM) throw errorCannotChangeBPM(); 
     224                sequencer.bpm = t; 
     225            } else { 
     226                sequencer.setting.defaultBPM = t; 
     227            } 
     228        } 
     229         
     230        /** Debug mode, true; throw Error / false; throw ErrorEvent when error appears. */ 
     231        public function get debugMode() : Boolean { return _debugMode; } 
     232        public function set debugMode(mode:Boolean) : void { _debugMode = mode; } 
     233         
    175234         
    176235         
     
    178237    // constructor 
    179238    //---------------------------------------- 
    180         /** Create driver to manage the SiOPM module, compiler and sequencer. 
     239        /** Create driver to manage the sound module, sequencer and effectors. 
     240         *  @param bufferLength Buffer size of sound stream. 8192, 4096 or 2048 is available, but no check. 
    181241         *  @param channel Channel count. 1 or 2 is available. 
    182242         *  @param sampleRate Sampling ratio of wave. 22050 or 44100 is available. 
    183243         *  @param bitRate Bit ratio of wave. 0, 8 or 16 is available. 0 means float value [-1 to 1]. 
    184          *  @param bufferLength Buffer size of sound stream. 8192, 4096 or 2048 is available, but no check. 
    185          *  @param throwErrorEvent true; throw ErrorEvent when it errors. false; throw Error when it errors. 
    186          */ 
    187         function SiONDriver(channelCount:int=2, sampleRate:int=44100, bitRate:int=0, bufferLength:int=8192, throwErrorEvent:Boolean=true) 
    188         { 
    189             if (!_compileQue) _compileQue = new Vector.<SiONCompileQue>(); 
     244         *  @param frameRate frame rate of stage. 
     245         */ 
     246        function SiONDriver(bufferLength:int=2048, channelCount:int=2, sampleRate:int=44100, bitRate:int=0) 
     247        { 
     248            if (!_jobQueue) _jobQueue = new Vector.<SiONDriverJob>(); 
    190249             
    191250            module = new SiOPMModule(); 
    192251            effector = new SiEffectModule(module); 
    193             sequencer = new SiMMLSequencer(module); 
     252            sequencer = new SiMMLSequencer(module, _callbackEventTriggerOn, _callbackEventTriggerOff); 
    194253            _sound = new Sound(); 
    195254            _soundTransform = new SoundTransform(); 
    196255 
    197256            // initialize 
    198             _throwErrorEvent = throwErrorEvent; 
    199              
    200257            _channelCount = channelCount; 
    201258            _sampleRate = 44100; // sampleRate; 44100 is only available now. 
     
    203260            _bufferLength = bufferLength; 
    204261            _listenEvent = NO_LISTEN; 
     262            _dispatchStreamEvent = false; 
     263            _cannotChangeBPM = false; 
     264            _debugMode = false; 
    205265             
    206266            _soundTransform.volume = 1; 
     
    208268            _position = 0; 
    209269             
    210             _compileInterval = 0; 
    211             _compileProgress = 0; 
     270            _eventListenerPrior = 1; 
     271            _triggerEventQueue = new Vector.<SiONTrackEvent>(); 
     272             
     273            _queueInterval = 500; 
     274            _jobProgress = 0; 
     275            _currentJob = 0; 
     276            _queueLength = 0; 
    212277             
    213278            _timeCompile = 0; 
     
    217282            _timePrevStream = 0; 
    218283            _latency = 0; 
     284            _prevFrameTime = 0; 
     285            _frameRate = 1; 
    219286             
    220287            _mmlString    = null; 
     
    229296         
    230297         
    231     // operations for data 
    232     //---------------------------------------- 
    233         /** Compile the MML string.  
    234          *  After calling this function, the SiONEvent.COMPILE_PROGRESS, SiONEvent.COMPILE_COMPLETE and ErrorEvent.ERROR events will be dispatched.<br/> 
    235          *  The SiONEvent.COMPILE_PROGRESS is dispatched when it's compiling in the interval of the argument "interval".<br/> 
    236          *  The SiONEvent.COMPILE_COMPLETE is dispatched when the compile is finished successfully.<br/> 
     298    // interfaces for data preparation 
     299    //---------------------------------------- 
     300        /** Compile MML string immeriately.  
     301         *  @param mml MML string to compile. 
     302         *  @param data SiONData to compile. The SiONDriver creates new SiONData instance when this argument is null. 
     303         *  @return Compiled data. 
     304         */ 
     305        public function compile(mml:String, data:SiONData=null) : SiONData 
     306        { 
     307            try { 
     308                // stop sound 
     309                stop(); 
     310                 
     311                // compile immediately 
     312                var t:int = getTimer(); 
     313                _prepareCompile(mml, data); 
     314                _jobProgress = sequencer.compile(0); 
     315                _timeCompile = getTimer() - t; 
     316                _mmlString = null; 
     317            } catch(e:Error) { 
     318                // error 
     319                if (_debugMode) throw e; 
     320                else dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 
     321            } 
     322             
     323            return _data; 
     324        } 
     325         
     326         
     327        /** Push queue job to compile MML string. Start compiling after calling startQueue.<br/> 
     328         *  @param mml MML string to compile. 
     329         *  @param data SiONData to compile. 
     330         *  @return Queue length. 
     331         *  @see #startQueue() 
     332         */ 
     333        public function compileQueue(mml:String, data:SiONData) : int 
     334        { 
     335            if (mml == null || data == null) return _jobQueue.length; 
     336            return _jobQueue.push(new SiONDriverJob(mml, null, data)); 
     337        } 
     338         
     339         
     340         
     341         
     342    // interfaces for sound rendering 
     343    //---------------------------------------- 
     344        /** Render sound immeriately. 
     345         *  @param data SiONData or mml String to play. 
     346         *  @param renderBuffer Rendering target. null to create new buffer. The length of renderBuffer limits rendering length except for 0. 
     347         *  @param resetEffector reset all effectors before play data. 
     348         *  @return rendered data. 
     349         */ 
     350        public function render(data:*, renderBuffer:Vector.<Number>=null, resetEffector:Boolean=true) : Vector.<Number> 
     351        { 
     352            try { 
     353                // stop sound 
     354                stop(); 
     355                 
     356                // rendering immediately 
     357                var t:int = getTimer(); 
     358                if (resetEffector) effector.initialize(); 
     359                _prepareRender(data, renderBuffer); 
     360                while(true) { if (_rendering()) break; } 
     361                _timeRender = getTimer() - t; 
     362            } catch (e:Error) { 
     363                // error 
     364                _removeAllEventListners(); 
     365                if (_debugMode) throw e; 
     366                else dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 
     367            } 
     368             
     369            return _renderBuffer; 
     370        } 
     371         
     372         
     373        /** Push queue job to render sound. Start rendering after calling startQueue.<br/> 
     374         *  @param data SiONData or mml String to render. 
     375         *  @param renderBuffer Rendering target. The length of renderBuffer limits rendering length except for 0. 
     376         *  @return Queue length. 
     377         *  @see #startQueue() 
     378         */ 
     379        public function renderQueue(data:*, renderBuffer:Vector.<Number>) : int 
     380        { 
     381            if (data == null || renderBuffer == null) return _jobQueue.length; 
     382             
     383            if (data is String) { 
     384                var compiled:SiONData = new SiONData(); 
     385                _jobQueue.push(new SiONDriverJob(data as String, null, compiled)); 
     386                return _jobQueue.push(new SiONDriverJob(null, renderBuffer, compiled)); 
     387            } else  
     388            if (data is SiONData) { 
     389                return _jobQueue.push(new SiONDriverJob(null, renderBuffer, data as SiONData)); 
     390            } 
     391             
     392            var e:Error = errorDataIncorrect(); 
     393            if (_debugMode) throw e; 
     394            else dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 
     395            return _jobQueue.length; 
     396        } 
     397         
     398         
     399         
     400         
     401    // interfaces for jobs queue 
     402    //---------------------------------------- 
     403        /** Execute all elements of queue pushed by compileQueue and renderQueue. 
     404         *  After calling this function, the SiONEvent.QUEUE_PROGRESS, SiONEvent.QUEUE_COMPLETE and ErrorEvent.ERROR events will be dispatched.<br/> 
     405         *  The SiONEvent.QUEUE_PROGRESS is dispatched when it's executing queued job.<br/> 
     406         *  The SiONEvent.QUEUE_COMPLETE is dispatched when finish all queued jobs.<br/> 
    237407         *  The ErrorEvent.ERROR is dispatched when some error appears during the compile.<br/> 
    238          *  @param mml MML string to compile. 
    239          *  @param interavl Interval to interrupt compiling [ms]. The value of 0 sets no interruption and returns SiONData immediately. 
    240          *  @param data SiONData to compile. The SiONDriver creates new SiONData instance when this argument is null. 
    241          *  @return This function returns compiled data only when the argument "interval" set to 0, and returns null in other cases. 
    242          */ 
    243         public function compile(mml:String, interval:int=0, data:SiONData=null) : SiONData 
    244         { 
    245             // stop sound 
     408         *  @param interval Interupting interval 
     409         *  @return Queue length. 
     410         *  @see #compileQueue() 
     411         *  @see #renderQueue() 
     412         */ 
     413        public function startQueue(interval:int=500) : int 
     414        { 
    246415            stop(); 
    247              
     416            _queueLength = _jobQueue.length; 
     417            if (_jobQueue.length > 0) { 
     418                _queueInterval = interval; 
     419                _executeNextJob(); 
     420                _queue_addAllEventListners(); 
     421            } 
     422            return _queueLength; 
     423        } 
     424         
     425         
     426         
     427         
     428    // interfaces for sound streaming 
     429    //---------------------------------------- 
     430        /** Play sound. 
     431         *  @param data SiONData or mml String to play. You can pass null when resume after pause or streaming without any data. 
     432         *  @param resetEffector reset all effectors before play data. 
     433         *  @return SoundChannel instance to play data. This instance is same as soundChannel property. 
     434         *  @see #soundChannel 
     435         */ 
     436        public function play(data:*=null, resetEffector:Boolean=true) : SoundChannel 
     437        { 
    248438            try { 
    249                 if (interval > 0) { 
    250                      // push compile que 
    251                     _pushCompileQue(mml, interval, data); 
    252                     _compile_addAllEventListners(); 
     439                if (_isPaused) { 
     440                    _isPaused = false; 
    253441                } else { 
    254                     // compile immediately 
    255                     var t:int = getTimer(); 
    256                     _prepareCompile(mml, 0, data); 
    257                     _compileProgress = sequencer.compile(0); 
    258                     _timeCompile += getTimer() - t; 
    259                     return _data; 
     442                    // stop sound 
     443                    stop(); 
     444                     
     445                    // preparation 
     446                    if (resetEffector) effector.initialize(); 
     447                    _prepareProcess(data); 
     448                     
     449                    // dispatch streaming start event 
     450                    var event:SiONEvent = new SiONEvent(SiONEvent.STREAM_START, this, null, true); 
     451                    dispatchEvent(event); 
     452                    if (event.isDefaultPrevented()) return null;   // canceled 
     453                     
     454                    // set position 
     455                    if (_data && _position > 0) { sequencer.dummyProcess(_position * _sampleRate * 0.001); } 
     456                     
     457                    // start stream 
     458                    _process_addAllEventListners(); 
     459                    _soundChannel = _sound.play(); 
     460                    _soundChannel.soundTransform = _soundTransform; 
     461                     
     462                    // initialize 
     463                    _timeProcessTotal = 0; 
     464                    for (var i:int=0; i<TIME_AVARAGING_COUNT; i++) { 
     465                        _timeProcessData.i = 0; 
     466                        _timeProcessData = _timeProcessData.next; 
     467                    } 
     468                    _isPaused = false; 
    260469                } 
    261470            } catch(e:Error) { 
    262471                // error 
    263                 if (_throwErrorEvent) dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 
    264                 else throw e; 
    265             } 
    266              
    267             return null; 
    268         } 
    269          
    270          
    271          
    272          
    273     // operations for sound 
    274     //---------------------------------------- 
    275         /** Play sound. 
    276          *  @param data Data to play. You can pass null when resume after pause. 
    277          *  @param resetEffector Reset effector before play data. 
    278          */ 
    279         public function play(data:SiONData=null, resetEffector:Boolean=true) : void 
    280         { 
    281             if (_isPaused) { 
    282                 _isPaused = false; 
    283             } else { 
    284                 _data = data; 
    285                  
    286                 // stop sound 
    287                 stop(); 
    288                  
    289                 // preparation 
    290                 if (resetEffector) effector.initialize(); 
    291                 module.initialize(_channelCount, _bufferLength); 
    292                 sequencer.prepareProcess(_data, _sampleRate, _bufferLength); // set tables inside 
    293                 if (_data) _parseSystemCommand(_data.systemCommands);        // parse #EFFECT 
    294                 effector.prepareProcess();                                   // set stream number inside 
    295                 module.reset(); 
    296                  
    297                 // set position 
    298                 if (_data && _position > 0) { sequencer.dummyProcess(_position * _sampleRate * 0.001); } 
    299                  
    300                 // dispatch streaming start event 
    301                 dispatchEvent(new SiONEvent(SiONEvent.STREAM_START, this)); 
    302                  
    303                 // start stream 
    304                 _process_addAllEventListners(); 
    305                 _soundChannel = _sound.play(); 
    306                 _soundChannel.soundTransform = _soundTransform; 
    307                  
    308                 // initialize 
    309                 _timeProcessTotal = 0; 
    310                 for (var i:int=0; i<TIME_AVARAGING_COUNT; i++) { 
    311                     _timeProcessData.i = 0; 
    312                     _timeProcessData = _timeProcessData.next; 
    313                 } 
    314                 _isPaused = false; 
    315             } 
     472                if (_debugMode) throw e; 
     473                else dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 
     474            } 
     475             
     476            return _soundChannel; 
    316477        } 
    317478         
     
    325486                _soundChannel = null; 
    326487                _latency = 0; 
     488                 
    327489                // dispatch streaming stop event 
    328490                dispatchEvent(new SiONEvent(SiONEvent.STREAM_STOP, this)); 
     
    338500         
    339501         
    340         /** Get track instance. This function only is available after play(). 
    341          *  Most common timing to call is in the event listener of SiONEvent.STREAM_START. 
    342          *  @param trackIndex Track index. This must be less than SiMMLDriver.trackCount. 
    343          *  @return Track instance. When the trackIndex is out of range, returns null. 
    344          */ 
    345         public function getTrack(trackIndex:int) : SiMMLSequencerTrack 
    346         { 
    347             return sequencer.getTrack(trackIndex); 
    348         } 
    349          
    350          
     502         
     503         
     504    // Interface for data register 
     505    //---------------------------------------- 
     506        /** Set wave table data refered by %4. 
     507         *  @param index wave table number. 
     508         *  @param table wave shape vector ranges in -1 to 1. 
     509         */ 
     510        public function setWaveTable(index:int, table:Vector.<Number>) : void 
     511        { 
     512            var len:int, bits:int=-1; 
     513            for (len=table.length; len>0; len>>=1) bits++; 
     514            if (bits<2) return; 
     515            var serialized:Vector.<int> = SiONUtil.serializeVectorPCM(table, new Vector.<int>()); 
     516            serialized.length = 1<<bits; 
     517            SiOPMTable.registerWaveTable(index, serialized, bits); 
     518        } 
     519         
     520         
     521        /** Set PCM data rederd from %7. 
     522         *  @param index PCM data number. 
     523         *  @param sound Sound instance to set. 
     524         *  @param samplingOctave Sampling frequency. The value of 5 means that "o5a" is original frequency. 
     525         */ 
     526        public function setPCMData(index:int, sound:Sound, samplingOctave:int=5) : void 
     527        { 
     528            var data:Vector.<int> = SiONUtil.serialize(sound); 
     529            SiOPMTable.registerPCMData(index, data, samplingOctave); 
     530        } 
     531         
     532         
     533        /** Set wave data refered by %10. 
     534         *  @param index note number. 128-255 for bank1. 
     535         *  @param sound Sound instance to set. 
     536         *  @param isOneShot True to set "one shot" sound. The "one shot" sound ignores note off. 
     537         *  @param isStereo True to set as stereo data. 
     538         */ 
     539        public function setWaveData(index:int, sound:Sound, isOneShot:Boolean=true, isStereo:Boolean=false) : void 
     540        { 
     541            var data:Vector.<int> = SiONUtil.getRawData(sound); 
     542            SiOPMTable.registerSample(index, data, ((isOneShot) ? 2 : 0) + ((isStereo) ? 1 : 0)); 
     543        } 
     544         
     545         
     546         
     547         
     548    // Interface for intaractivity 
     549    //---------------------------------------- 
     550        /** Note on. This function only is available after play(). The NOTE_ON_STREAM event is dispatched inside. 
     551         *  @param note note number [0-127]. 
     552         *  @param setting tone setting. 
     553         *  @param length note length in 16th beat. 0 sets no note off, this means you should call noteOff(). 
     554         *  @param delay note on delay units in 16th beat. 
     555         *  @param quant quantize in 16th beat. 0 sets no quantization. 4 sets quantization by 4th beat. 
     556         *  @param trackID new tracks id. 
     557         *  @param eventTriggerID Event trigger id. 
     558         *  @param noteOnTrigger note on trigger type. 
     559         *  @param noteOffTrigger note off trigger type. 
     560         *  @return SiMMLTrack to play the note. 
     561         */ 
     562        public function noteOn(note:int, setting:SiONToneSetting,  
     563                               length:Number=0, delay:Number=0, quant:int=0, trackID:int=0,  
     564                               eventTriggerID:int=0, noteOnTrigger:int=0, noteOffTrigger:int=0) : SiMMLTrack 
     565        { 
     566            trackID = (trackID & SiMMLTrack.TRACK_ID_FILTER) | SiMMLTrack.DRIVER_TRACK_ID_OFFSET; 
     567            var mmlTrack:SiMMLTrack = sequencer.getFreeControlableTrack(trackID) || sequencer.newControlableTrack(trackID); 
     568            var delaySamples:int = sequencer.calcSampleDelay(0, delay, quant); 
     569            if (mmlTrack) { 
     570                if (setting) setting.setTrackTone(mmlTrack); 
     571                mmlTrack.setEventTrigger(eventTriggerID, noteOnTrigger, noteOffTrigger); 
     572                mmlTrack.keyOn(note, sequencer.calcSampleLength(length), delaySamples); 
     573            } 
     574            return mmlTrack; 
     575        } 
     576         
     577         
     578        /** Note off. This function only is available after play(). The NOTE_OFF_STREAM event is dispatched inside. 
     579         *  @param note note number [0-127]. 
     580         *  @param trackID track id to note off. 
     581         *  @return The SiMMLTrack switched key off. Returns null when tracks are overflowed. 
     582         */ 
     583        public function noteOff(note:int, trackID:int=0) : SiMMLTrack 
     584        { 
     585            trackID = (trackID & SiMMLTrack.TRACK_ID_FILTER) | SiMMLTrack.DRIVER_TRACK_ID_OFFSET; 
     586            var mmlTrack:SiMMLTrack = sequencer.findControlableTrack(trackID, note); 
     587            if (mmlTrack) mmlTrack.keyOff(); 
     588            return mmlTrack; 
     589        } 
     590         
     591         
     592         
     593         
     594    //==================================================================================================== 
     595    // Internal uses 
     596    //==================================================================================================== 
     597    // callback for event trigger 
     598    //---------------------------------------- 
     599        // call back when sound streaming 
     600        private function _callbackEventTriggerOn(track:SiMMLTrack, pitch:int) : Boolean 
     601        { 
     602            return _publishEventTrigger(track, track.eventTriggerTypeOn, SiONTrackEvent.NOTE_ON_FRAME, SiONTrackEvent.NOTE_ON_STREAM); 
     603        } 
     604         
     605        // call back when sound streaming 
     606        private function _callbackEventTriggerOff(track:SiMMLTrack) : Boolean 
     607        { 
     608            return _publishEventTrigger(track, track.eventTriggerTypeOff, SiONTrackEvent.NOTE_OFF_FRAME, SiONTrackEvent.NOTE_OFF_STREAM); 
     609        } 
     610         
     611        // publish event trigger 
     612        private function _publishEventTrigger(track:SiMMLTrack, type:int, frameEvent:String, streamEvent:String) : Boolean 
     613        { 
     614            var event:SiONTrackEvent; 
     615            if (type & 1) { // frame event. dispatch later 
     616                event = new SiONTrackEvent(frameEvent, this, track); 
     617                _triggerEventQueue.push(event); 
     618            } 
     619            if (type & 2) { // sound event. dispatch immediately 
     620                event = new SiONTrackEvent(streamEvent, this, track); 
     621                dispatchEvent(event); 
     622                return !(event.isDefaultPrevented()); 
     623            } 
     624            return true; 
     625        } 
     626         
     627         
     628    // operate event listener 
     629    //---------------------------------------- 
     630        // add all event listners 
     631        private function _queue_addAllEventListners() : void 
     632        { 
     633            if (_listenEvent != NO_LISTEN) throw errorDriverBusy(LISTEN_QUEUE); 
     634            addEventListener(Event.ENTER_FRAME, _queue_onEnterFrame, false, _eventListenerPrior); 
     635            _listenEvent = LISTEN_QUEUE; 
     636        } 
     637         
     638         
     639        // add all event listners 
     640        private function _process_addAllEventListners() : void 
     641        { 
     642            if (_listenEvent != NO_LISTEN) throw errorDriverBusy(LISTEN_PROCESS); 
     643            addEventListener(Event.ENTER_FRAME, _process_onEnterFrame, false, _eventListenerPrior); 
     644            _dispatchStreamEvent = (hasEventListener(SiONEvent.STREAM)); 
     645            _prevFrameTime = getTimer(); 
     646            _listenEvent = LISTEN_PROCESS; 
     647        } 
     648         
     649         
     650        // remove all event listners 
     651        private function _removeAllEventListners() : void 
     652        { 
     653            switch (_listenEvent) { 
     654            case LISTEN_QUEUE: 
     655                removeEventListener(Event.ENTER_FRAME, _queue_onEnterFrame); 
     656                break; 
     657            case LISTEN_PROCESS: 
     658                removeEventListener(Event.ENTER_FRAME, _process_onEnterFrame); 
     659                _dispatchStreamEvent = false; 
     660                break; 
     661            } 
     662            _listenEvent = NO_LISTEN; 
     663        } 
     664         
     665         
     666         
     667         
     668    // parse 
     669    //---------------------------------------- 
    351670        // parse system command on SiONDriver 
    352         private function _parseSystemCommand(systemCommands:Array) : void 
    353         { 
    354             var id:int
     671        private function _parseSystemCommand(systemCommands:Array) : Boolean 
     672        { 
     673            var id:int, effectSet:Boolean = false
    355674            for each (var cmd:* in systemCommands) { 
    356675                switch(cmd.command){ 
    357676                case "#EFFECT": 
     677                    if (!effectSet) effector.initialize();  // initialize effect 
     678                    effectSet = true; 
    358679                    effector.parseMML(cmd.number, cmd.content); 
    359680                    break; 
    360681                } 
    361682            } 
    362         } 
    363          
    364          
    365          
    366          
    367     // Data register 
    368     //---------------------------------------- 
    369         /** Set wave table data */ 
    370         public function setWaveTable(index:int, table:Vector.<Number>, bits:int) : void 
    371         { 
    372             //SiOPMTable.registerWaveTable(index, table, bits); 
    373         } 
    374          
    375          
    376         /** Set PCM data */ 
    377         public function setPCMData(index:int, serialized:Vector.<int>, samplingOctave:int=5) : void 
    378         { 
    379             SiOPMTable.registerPCMData(index, serialized, samplingOctave); 
    380         } 
    381          
    382          
    383         /** Set wave data */ 
    384         public function setWaveData(index:int, rawData:Vector.<int>, channelCount:int=1) : void 
    385         { 
    386             SiOPMTable.registerSample(index, rawData, channelCount); 
    387         } 
    388          
    389          
    390          
    391          
    392     // MIDI interface (still in a planning stage) 
    393     //---------------------------------------- 
    394         /** Note on. This function only is available after play(). 
    395          *  @param channel Channel to switch key on. 
    396          *  @param note Note number to switch key on. 
    397          *  @return The track switched key key on. Returns null when tracks are overflowed. 
    398          */ 
    399         public function noteOn(note:int, param:SiOPMChannelParam=null) : SiMMLSequencerTrack 
    400         { 
    401             var trk:SiMMLSequencerTrack = sequencer.getFreeControlableTrack() || sequencer.newControlableTrack(); 
    402             if (trk) { 
    403                 if (param) trk.channel.setSiOPMChannelParam(param, false); 
    404                 trk.keyOnDelay = (_timePrevStream - getTimer()) * 44.1; 
    405                 trk.keyOn(note); 
    406             } 
    407             return trk; 
    408         } 
    409          
    410          
    411         /** Note off. This function only is available after play().  
    412          *  @param channel Channel to switch key off. 
    413          *  @param note Note number to switch key off. 
    414          *  @return The track switched key off. Returns null when no tracks run specifyed note. 
    415          */ 
    416         public function noteOff(note:int) : SiMMLSequencerTrack 
    417         { 
    418             var trk:SiMMLSequencerTrack = sequencer.findControlableTrack(note); 
    419             if (trk) trk.keyOff(); 
    420             return trk; 
    421         } 
    422          
    423          
    424          
    425          
    426     // operate event listener 
    427     //---------------------------------------- 
    428         // add all event listners 
    429         private function _compile_addAllEventListners() : void 
    430         { 
    431             addEventListener(Event.ENTER_FRAME, _compile_onEnterFrame); 
    432             _listenEvent = LISTEN_COMPILE; 
    433         } 
    434          
    435          
    436         // add all event listners 
    437         private function _process_addAllEventListners() : void 
    438         { 
    439             addEventListener(Event.ENTER_FRAME, _process_onEnterFrame); 
    440             _listenEvent = LISTEN_PROCESS; 
    441         } 
    442          
    443          
    444         // remove all event listners 
    445         private function _removeAllEventListners() : void 
    446         { 
    447             switch (_listenEvent) { 
    448             case LISTEN_COMPILE: 
    449                 removeEventListener(Event.ENTER_FRAME, _compile_onEnterFrame); 
    450                 break; 
    451             case LISTEN_PROCESS: 
    452                 removeEventListener(Event.ENTER_FRAME, _process_onEnterFrame); 
    453                 break; 
    454             } 
    455             _listenEvent = NO_LISTEN; 
    456         } 
    457          
    458          
    459          
    460          
    461     // compile 
    462     //---------------------------------------- 
    463         // Stac que 
    464         private function _pushCompileQue(mml:String, interval:int, data:SiONData) : void 
     683            return effectSet; 
     684        } 
     685         
     686         
     687         
     688         
     689    // jobs queue 
     690    //---------------------------------------- 
     691        // cancel 
     692        private function _cancelAllJobs() : void 
     693        { 
     694            _data = null; 
     695            _mmlString = null; 
     696            _currentJob = 0; 
     697            _jobQueue.length = 0; 
     698            _queueLength = 0; 
     699            _removeAllEventListners(); 
     700            dispatchEvent(new SiONEvent(SiONEvent.QUEUE_CANCEL, this, null)); 
     701        } 
     702         
     703         
     704        // next job 
     705        private function _executeNextJob() : Boolean 
     706        { 
     707            _data = null; 
     708            _mmlString = null; 
     709            _currentJob = 0; 
     710            if (_jobQueue.length == 0) { 
     711                _queueLength = 0; 
     712                _removeAllEventListners(); 
     713                dispatchEvent(new SiONEvent(SiONEvent.QUEUE_COMPLETE, this, null)); 
     714                return true; 
     715            } 
     716             
     717            var queue:SiONDriverJob = _jobQueue.shift(); 
     718            if (queue.mml) _prepareCompile(queue.mml, queue.data); 
     719            else _prepareRender(queue.data, queue.buffer); 
     720            return false; 
     721        } 
     722         
     723         
     724        // on enterFrame 
     725        private function _queue_onEnterFrame(e:Event) : void 
    465726        { 
    466727            try { 
    467                 if (isCompiling) { 
    468                     _compileQue.push(new SiONCompileQue(mml, interval, data)); 
    469                 } else { 
    470                     _prepareCompile(mml, interval, data); 
     728                var event:SiONEvent, t:int = getTimer(); 
     729                 
     730                switch (_currentJob) { 
     731                case 1: // compile 
     732                    _jobProgress = sequencer.compile(_queueInterval); 
     733                    _timeCompile += getTimer() - t; 
     734                    break; 
     735                case 2: // render 
     736                    _jobProgress += (1 - _jobProgress) * 0.5; 
     737                    while (getTimer() - t <= _queueInterval) {  
     738                        if (_rendering()) { 
     739                            _jobProgress = 1; 
     740                            break; 
     741                        } 
     742                    } 
     743                    _timeRender += getTimer() - t; 
     744                    break; 
    471745                } 
    472             } catch(e:Error) { 
    473                 // error 
    474                 if (_throwErrorEvent) dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 
    475                 else throw e; 
    476             } 
    477         } 
    478          
    479          
    480         // Compile staced que 
    481         private function _execCompileQue() : Boolean 
    482         { 
    483             if (_compileQue.length == 0) return false; 
    484             var que:SiONCompileQue = _compileQue.shift(); 
    485             _prepareCompile(que.mml, que.interval, que.data); 
    486             return true; 
    487         } 
    488          
    489          
    490         // prepare to compile 
    491         private function _prepareCompile(mml:String, interval:int, data:SiONData) : void 
    492         { 
    493             _data = data || new SiONData(); 
    494             _mmlString = mml; 
    495             _compileInterval = interval; 
    496             sequencer.prepareCompile(_data, _mmlString); 
    497             _compileProgress = 0.01; 
    498         } 
    499          
    500          
    501         // on enterFrame 
    502         private function _compile_onEnterFrame(e:Event) : void 
    503         { 
    504             try { 
    505                 // compile 
    506                 var t:int = getTimer(); 
    507                 _compileProgress = sequencer.compile(_compileInterval); 
    508                 _timeCompile += getTimer() - t; 
    509746                 
    510                 if (_compileProgress == 1) { 
    511                     // complete 
    512                     dispatchEvent(new SiONEvent(SiONEvent.COMPILE_COMPLETE, this)); 
    513                     // execute next que 
    514                     if (!_execCompileQue()) { 
    515                         // finished 
    516                         _removeAllEventListners(); 
    517                         _data = null; 
    518                         _mmlString = null; 
    519                     } 
    520                 } else { 
    521                     // progress 
    522                     dispatchEvent(new SiONEvent(SiONEvent.COMPILE_PROGRESS, this)); 
     747                // finish job 
     748                if (_jobProgress == 1) { 
     749                    // finish all jobs 
     750                    if (_executeNextJob()) return; 
    523751                } 
     752                 
     753                // progress 
     754                event = new SiONEvent(SiONEvent.QUEUE_PROGRESS, this, null, true); 
     755                dispatchEvent(event); 
     756                if (event.isDefaultPrevented()) _cancelAllJobs();   // canceled 
    524757            } catch (e:Error) { 
    525758                // error 
    526759                _removeAllEventListners(); 
    527                 if (_throwErrorEvent) dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 
    528                 else throw e; 
    529             } 
     760                if (_debugMode) throw e; 
     761                else dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 
     762            } 
     763        } 
     764         
     765         
     766         
     767    // compile 
     768    //---------------------------------------- 
     769        // prepare to compile 
     770        private function _prepareCompile(mml:String, data:SiONData) : void 
     771        { 
     772            _data = data || new SiONData(); 
     773            _mmlString = mml; 
     774            sequencer.prepareCompile(_data, _mmlString); 
     775            _jobProgress = 0.01; 
     776            _timeCompile = 0;  
     777            _currentJob = 1; 
     778        } 
     779         
     780         
     781         
     782         
     783    // render 
     784    //---------------------------------------- 
     785        // prepare for rendering 
     786        private function _prepareRender(data:*, renderBuffer:Vector.<Number>) : void 
     787        { 
     788            _prepareProcess(data); 
     789            _renderBuffer = renderBuffer || new Vector.<Number>(); 
     790            _renderBufferSizeMax = _renderBuffer.length; 
     791            _renderBufferIndex = 0; 
     792            _jobProgress = 0.01; 
     793            _timeRender = 0; 
     794            _currentJob = 2; 
     795        } 
     796         
     797         
     798        // rendering @return true when finished rendering. 
     799        private function _rendering() : Boolean 
     800        { 
     801            var i:int, j:int, imax:int,  
     802                output:Vector.<Number> = module.output,  
     803                finished:Boolean = false; 
     804             
     805            // processing 
     806            sequencer.process(); 
     807            effector.process(); 
     808             
     809            // limit rendering length 
     810            imax = _bufferLength<<1; 
     811            if (_renderBufferSizeMax != 0 && _renderBufferSizeMax < _renderBufferIndex+imax) { 
     812                imax = _renderBufferSizeMax - _renderBufferIndex; 
     813                finished = true; 
     814            } 
     815             
     816            // extend buffer 
     817            if (_renderBuffer.length < _renderBufferIndex+imax) { 
     818                _renderBuffer.length = _renderBufferIndex+imax; 
     819            } 
     820             
     821            // copy output 
     822            for (i=0, j=_renderBufferIndex; i<imax; i++, j++) { 
     823                _renderBuffer[j] = output[i]; 
     824            } 
     825             
     826            // incerement index 
     827            _renderBufferIndex += imax; 
     828             
     829            return (finished || (_renderBufferSizeMax==0 && sequencer.isFinished)); 
    530830        } 
    531831         
     
    535835    // process 
    536836    //---------------------------------------- 
     837        // prepare for processing 
     838        private function _prepareProcess(data:*) : void 
     839        { 
     840            if (data is String) { 
     841                _data = compile(data as String); 
     842            } else { 
     843                if (!(data == null || data is SiONData)) throw errorDataIncorrect(); 
     844                _data = data; 
     845            } 
     846            module.initialize(_channelCount, _bufferLength); 
     847            module.reset();                                                 // reset channels 
     848            sequencer.prepareProcess(_data, _sampleRate, _bufferLength);    // set track channels (this must be called after module.reset(). 
     849            if (_data) _parseSystemCommand(_data.systemCommands);           // parse #EFFECT (initialize effector inside) 
     850            effector.prepareProcess();                                      // set stream number inside 
     851        } 
     852         
     853         
    537854        // on enterFrame 
    538855        private function _process_onEnterFrame(e:Event) : void 
    539856        { 
     857            // frame rate 
     858            var t:int = getTimer(); 
     859            _frameRate = t - _prevFrameTime; 
     860            _prevFrameTime = t; 
     861             
     862            // frame trigger 
     863            if (_triggerEventQueue.length > 0) { 
     864                _triggerEventQueue = _triggerEventQueue.filter(function(e:SiONTrackEvent, i:int, v:Vector.<SiONTrackEvent>) : Boolean { 
     865                    if (e._decrementTimer(_frameRate)) { 
     866                        dispatchEvent(e); 
     867                        return false; 
     868                    } 
     869                    return true; 
     870                }); 
     871            } 
    540872        } 
    541873         
     
    561893                    } 
    562894                } else { 
     895                    var t:int = getTimer(); 
    563896                    // processing 
    564                     var t:int = getTimer()
     897                    _cannotChangeBPM = true
    565898                    sequencer.process(); 
    566899                    effector.process(); 
     900                    _cannotChangeBPM = false; 
    567901                     
    568902                    // calculate the average of processing time 
     
    579913                     
    580914                    // dispatch streaming event 
    581                     dispatchEvent(new SiONEvent(SiONEvent.STREAM, this, buffer)); 
     915                    if (_dispatchStreamEvent) { 
     916                        var event:SiONEvent = new SiONEvent(SiONEvent.STREAM, this, buffer, true); 
     917                        dispatchEvent(event); 
     918                        if (event.isDefaultPrevented()) stop();   // canceled 
     919                    } 
    582920                } 
    583921            } catch (e:Error) { 
    584922                // error 
    585923                _removeAllEventListners(); 
    586                 if (_throwErrorEvent) dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 
    587                 else throw e; 
    588             } 
     924                if (_debugMode) throw e; 
     925                else dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 
     926            } 
     927        } 
     928         
     929         
     930         
     931         
     932    // error 
     933    //---------------------------------------- 
     934        private function errorDataIncorrect() : Error { 
     935            return new Error("SiONDriver error; data incorrect in play() or render()."); 
     936        } 
     937         
     938         
     939        private function errorDriverBusy(execID:int) : Error { 
     940            var states:Array = ["compiling", "streaming", "rendering"]; 
     941            return new Error("SiONDriver error: Driver busy. Call " + states[execID] + " while " + states[_listenEvent] + "."); 
     942        } 
     943         
     944         
     945        private function errorCannotChangeBPM() : Error { 
     946            return new Error("SiONDriver error: Cannot change bpm while rendering (SiONTrackEvent.NOTE_*_STREAM)."); 
    589947        } 
    590948    } 
     
    596954import org.si.sound.SiONData; 
    597955 
    598 class SiONCompileQue 
     956class SiONDriverJob 
    599957{ 
    600958    public var mml:String; 
    601     public var interval:int
     959    public var buffer:Vector.<Number>
    602960    public var data:SiONData; 
    603961     
    604     function SiONCompileQue(mml_:String, interval_:int, data_:SiONData)  
     962    function SiONDriverJob(mml_:String, buffer_:Vector.<Number>, data_:SiONData)  
    605963    { 
    606964        mml = mml_; 
    607         interval = interval_; 
     965        buffer = buffer_; 
    608966        data = data_ || new SiONData(); 
    609967    } 
  • as3/SiOPM/trunk/src/org/si/sound/SiONUtil.as

    r2526 r2607  
    1616     
    1717     
     18    /** Utilities for SiON */ 
    1819    public class SiONUtil { 
    1920         
    20     // PCM data serialization 
     21    // PCM data serialization (for PCM Data) 
    2122    //-------------------------------------------------- 
    2223        /** Serialize Sound wave */ 
    23         static public function serializeSound(data:Sound, sampleMax:int=1048576) : Vector.<int> 
     24        static public function serialize(data:Sound, sampleMax:int=1048576) : Vector.<int> 
    2425        { 
    2526            var wave:ByteArray = new ByteArray(); 
     
    5859         
    5960         
    60     // raw wave data 
     61    // raw wave data (for Sampler Data) 
    6162    //-------------------------------------------------- 
    6263        /** get raw data from Sound */ 
     
    6566            var wave:ByteArray = new ByteArray(); 
    6667            var samples:int = data.extract(wave, sampleMax); 
    67             return rawdataByteArrayPCM(wave, new Vector.<int>, channels); 
     68            return getRawDataByteArrayPCM(wave, new Vector.<int>, channels); 
    6869        } 
    6970         
    7071         
    7172        /** get raw data from Vector.<Number> wave */ 
    72         static public function rawdataVectorPCM(src:Vector.<Number>, dst:Vector.<int>, channels:int=1) : Vector.<int> 
     73        static public function getRawDataVectorPCM(src:Vector.<Number>, dst:Vector.<int>, channels:int=1) : Vector.<int> 
    7374        { 
    7475            var i:int, j0:int, j1:int, imax:int=src.length>>1; 
     
    9192         
    9293        /** get raw data from ByteArray wave */ 
    93         static public function rawdataByteArrayPCM(src:ByteArray, dst:Vector.<int>, channels:int=1) : Vector.<int> 
     94        static public function getRawDataByteArrayPCM(src:ByteArray, dst:Vector.<int>, channels:int=1) : Vector.<int> 
    9495        { 
    9596            var i:int, imax:int=src.length>>3; 
     
    108109            return dst; 
    109110        } 
    110          
    111  
    112     // Wave shaper 
    113     //-------------------------------------------------- 
    114         /** wave shaper for Vector.<Number> */ 
    115         static public function waveShapeVector(src:Vector.<Number>, distortion:Number) : void 
    116         { 
    117             var coef:Number = 2 * distortion / (1-distortion), 
    118                 c1:Number = 1 + coef; 
    119             var i:int, imax:int=src.length, n:Number; 
    120             for (i=0; i<imax; i++) { 
    121                 n = src[i]; 
    122                 src[i] = c1 * n / (1 + coef * ((n<0) ? -n : n)); 
    123             } 
    124         } 
    125          
    126          
    127         /** wave shaper for ByteArray */ 
    128         static public function waveShapeByteArray(src:ByteArray, distortion:Number) : void 
    129         { 
    130             var coef:Number = 2 * distortion / (1-distortion), 
    131                 c1:Number = 1 + coef; 
    132             var i:int, imax:int=src.length>>3, n:Number; 
    133             for (i=0; i<imax; i++) { 
    134                 src.position = i; 
    135                 n = src.readFloat(); 
    136                 src.position = i; 
    137                 src.writeFloat(c1 * n / (1 + coef * ((n<0) ? -n : n))); 
    138             } 
    139         } 
    140          
    141          
    142         /** wave shaper for raw data */ 
    143         static public function waveShapeRawData(src:Vector.<int>, channels:int, distortion:Number) : void 
    144         { 
    145             var coef:Number = 2 * distortion / (1-distortion), 
    146                 c1:Number = (1 + coef) * 32768; 
    147             var i:int, imax:int=src.length, n:Number; 
    148             if (channels == 2) { 
    149                 for (i=0; i<imax; i++) { 
    150                     n = (src[i] & 65535) * 0.000030517578125 - 1; 
    151                     src[i] = int(c1 * n / (1 + coef * ((n<0) ? -n : n))) + 32768; 
    152                     n = (src[i] >> 16) * 0.000030517578125 - 1; 
    153                     src[i] += (int(c1 * n / (1 + coef * ((n<0) ? -n : n))) + 32768)<<16; 
    154                 } 
    155             } else { 
    156                 for (i=0; i<imax; i++) { 
    157                     n = src[i] * 0.000030517578125; 
    158                     src[i] = int(c1 * n / (1 + coef * ((n<0) ? -n : n))); 
    159                 } 
    160             } 
    161         } 
    162          
    163          
    164111    } 
    165112} 
  • as3/SiOPM/trunk/src/org/si/sound/bytecode/SoundClass.as

    r2526 r2607  
    44    import flash.events.Event; 
    55    import flash.utils.ByteArray; 
     6    import flash.media.Sound; 
    67     
    78     
     
    4950                loader.loadBytes(bytes); 
    5051                 
    51             function _write(vu:Vector.<uint>) : ByteArray { 
    52                 for (var ui:uint in vu) { bytes.writeUnsignedInt(ui); } 
    53                 return ba; 
    54             } 
     52            function _write(vu:Vector.<uint>) : void { for each (var ui:uint in vu) { bytes.writeUnsignedInt(ui); } } 
    5553                 
    5654                function _onComplete(e:Event) : void { 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiCtrlFilterBase.as

    r2526 r2607  
    1010package org.si.sound.effect { 
    1111    import org.si.sound.module.SiOPMTable; 
    12     import org.si.sound.driver.SiMMLTable; 
     12    import org.si.sound.mml.SiMMLTable; 
    1313    import org.si.utils.SLLint; 
    1414     
     
    1919    public class SiCtrlFilterBase extends SiEffectBase 
    2020    { 
     21    // variables 
     22    //------------------------------------------------------------ 
    2123        protected var _p0r:Number, _p1r:Number, _p0l:Number, _p1l:Number; 
    2224        protected var _cutIndex:int, _res:Number, _table:SiOPMTable; 
     
    2729         
    2830         
     31         
     32         
     33    // constructor 
     34    //------------------------------------------------------------ 
     35        /** constructor */ 
     36        function SiCtrlFilterBase() {} 
     37         
     38         
     39         
     40         
     41    // operation 
     42    //------------------------------------------------------------ 
    2943        /** set parameters 
    3044         *  @param cut table index for cutoff(0-255). 255 to set no tables. 
     
    5973         
    6074         
    61         // overrided funcitons 
    62         //------------------------------------------------------------ 
     75    // overrided funcitons 
     76    //------------------------------------------------------------ 
     77        /** @private */ 
    6378        override public function initialize() : void 
    6479        { 
     
    6984         
    7085 
     86        /** @private */ 
    7187        override public function mmlCallback(args:Vector.<Number>) : void 
    7288        { 
     
    7793         
    7894         
     95        /** @private */ 
    7996        override public function prepareProcess() : int 
    8097        { 
     
    83100         
    84101         
     102        /** @private */ 
    85103        override public function process(channels:int, buffer:Vector.<Number>, startIndex:int, length:int) : int 
    86104        { 
     
    104122         
    105123         
    106         public function processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 
     124        /** @private */ 
     125        protected function processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 
    107126        { 
    108127        } 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiCtrlFilterHighPass.as

    r2526 r2607  
    1212    public class SiCtrlFilterHighPass extends SiCtrlFilterBase 
    1313    { 
    14         override public function processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 
     14        /** @private */ 
     15        override protected function processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 
    1516        { 
    1617            var i:int, n:Number, imax:int = startIndex + length, 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiCtrlFilterLowPass.as

    r2526 r2607  
    1212    public class SiCtrlFilterLowPass extends SiCtrlFilterBase 
    1313    { 
    14         override public function processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 
     14        /** @private */ 
     15        override protected function processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 
    1516        { 
    1617            var i:int, n:Number, imax:int = startIndex + length, 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectAutoPan.as

    r2526 r2607  
    1515    public class SiEffectAutoPan extends SiEffectBase 
    1616    { 
     17    // variables 
     18    //------------------------------------------------------------ 
    1719        private var _stereo:Boolean; 
    1820         
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectBase.as

    r2526 r2607  
    99 
    1010package org.si.sound.effect { 
    11     /** Effector basic class */ 
     11    /** Effector basic class. */ 
    1212    public class SiEffectBase 
    1313    { 
     14    // variables 
     15    //------------------------------------------------------------ 
    1416        /** @private [internal use] used by manager */ 
    1517        public var _isFree:Boolean = true; 
    1618         
    1719         
    18         /** initializer. */ 
     20         
     21         
     22    // constructor 
     23    //------------------------------------------------------------ 
     24        /** Constructor. do nothing. */ 
     25        function SiEffectBase() {} 
     26         
     27         
     28         
     29         
     30    // callback functions 
     31    //------------------------------------------------------------ 
     32        /** Initializer. The system calls this when the instance is created. */ 
    1933        public function initialize() : void 
    2034        { 
    2135        } 
    2236         
    23         /** parameter setting by mml arguments  
     37         
     38        /** Parameter setting by mml arguments. The sequencer calls this when "#EFFECT" appears. 
    2439         *  @param args The arguments refer from mml. The value of Number.NaN is put when its abbriviated. 
    2540         */ 
     
    2742        { 
    2843        } 
    29  
    30         /** prepare processing.  
     44         
     45         
     46        /** Prepare processing. The system calls this before processing. 
    3147         *  @return requesting channels count. 
    3248         */ 
     
    3652        } 
    3753         
    38         /** process effect to stream buffer  
     54         
     55        /** Process effect to stream buffer. The system calls this to process. 
    3956         *  @param channels Stream channel count. 1=monoral(same data on buffer[i] ans buffer[i+1]). 2=stereo. 
    4057         *  @param buffer Stream buffer to apply effect. This is standard stereo stream buffer like [L0,R0,L1,R1,L2,R2 ... ]. 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectCompressor.as

    r2526 r2607  
    1111    import org.si.utils.SLLNumber; 
    1212     
     13     
     14     
    1315    /** Compressor. */ 
    1416    public class SiEffectCompressor extends SiEffectBase 
    1517    { 
     18    // variables 
     19    //------------------------------------------------------------ 
    1620        private var _windowRMSList:SLLNumber = null; 
    1721        private var _windowSamples:int; 
     
    2428         
    2529         
    26         /** constructor */ 
    27         function SiEffectCompressor() 
    28         { 
    29         } 
    3030         
    3131         
    32         /** constructor 
     32    // constructor 
     33    //------------------------------------------------------------ 
     34        /** constructor */ 
     35        function SiEffectCompressor() {} 
     36         
     37         
     38         
     39         
     40    // operation 
     41    //------------------------------------------------------------ 
     42        /** set parameters. 
    3343         *  @param thres threshold(0-1). 
    3444         *  @param slope slope(0-1). 
     
    4757         
    4858         
    49         // overrided funcitons 
    50         //------------------------------------------------------------ 
     59         
     60         
     61    // overrided funcitons 
     62    //------------------------------------------------------------ 
     63        /** @private */ 
    5164        override public function initialize() : void 
    5265        { 
     
    5568         
    5669 
     70        /** @private */ 
    5771        override public function mmlCallback(args:Vector.<Number>) : void 
    5872        { 
     
    6579         
    6680         
     81        /** @private */ 
    6782        override public function prepareProcess() : int 
    6883        { 
     
    7489         
    7590         
     91        /** @private */ 
    7692        override public function process(channels:int, buffer:Vector.<Number>, startIndex:int, length:int) : int 
    7793        { 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectEqualiser.as

    r2526 r2607  
    1212    public class SiEffectEqualiser extends SiEffectBase 
    1313    { 
     14    // variables 
     15    //------------------------------------------------------------ 
    1416        // filter pipes 
    1517        private var f1p0L:Number, f1p1L:Number, f1p2L:Number, f1p3L:Number; 
     
    2527         
    2628         
    27         /** constructor */ 
    28         function SiEffectEqualiser() 
    29         { 
    30         } 
    3129         
    3230         
    33         /** constructor 
     31    // constructor 
     32    //------------------------------------------------------------ 
     33        /** constructor */ 
     34        function SiEffectEqualiser() {} 
     35         
     36         
     37         
     38         
     39    // operation 
     40    //------------------------------------------------------------ 
     41        /** set parameters 
    3442         *  @param lowGain low gain(0-1-..). 
    3543         *  @param midGain middle gain(0-1-..). 
     
    4856         
    4957         
    50         // overrided funcitons 
    51         //------------------------------------------------------------ 
     58         
     59         
     60    // overrided funcitons 
     61    //------------------------------------------------------------ 
     62        /** @private */ 
    5263        override public function initialize() : void 
    5364        { 
     
    5667         
    5768 
     69        /** @private */ 
    5870        override public function mmlCallback(args:Vector.<Number>) : void 
    5971        { 
     
    6678         
    6779         
     80        /** @private */ 
    6881        override public function prepareProcess() : int 
    6982        { 
     
    7487         
    7588         
     89        /** @private */ 
    7690        override public function process(channels:int, buffer:Vector.<Number>, startIndex:int, length:int) : int 
    7791        { 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectModule.as

    r2526 r2607  
    1515     
    1616     
    17     /** Effect Module */ 
     17    /** Effect Module. */ 
    1818    public class SiEffectModule 
    1919    { 
     
    3030    // constructor 
    3131    //-------------------------------------------------------------------------------- 
    32         /** constructor. */ 
    33         function SiEffectModule(module:SiOPMModule, userEffector:*=undefined)  
     32        /** Constructor. */ 
     33        function SiEffectModule(module:SiOPMModule)  
    3434        { 
    3535            _module = module; 
     
    5454            register("hf", SiFilterHighPass); 
    5555            register("bf", SiFilterBandPass); 
    56             register("af", SiFilterAllPass); 
    5756            register("nf", SiFilterNotch); 
    5857            register("pf", SiFilterPeak); 
     58            register("af", SiFilterAllPass); 
    5959             
    6060            register("nlf", SiCtrlFilterLowPass); 
     
    6767    // operations 
    6868    //-------------------------------------------------------------------------------- 
    69         /** initialize all effectors. */ 
     69        /** @parivate [internal use] initialize all effectors. */ 
    7070        public function initialize() : void 
    7171        { 
     
    7474         
    7575         
    76         /** prepare for processing. */ 
     76        /** @parivate [internal use] prepare for processing. */ 
    7777        public function prepareProcess() : void 
    7878        { 
     
    100100         
    101101         
    102         /** processing. */ 
     102        /** @parivate [internal use] processing. */ 
    103103        public function process() : void 
    104104        { 
     
    123123    // effector instance manager 
    124124    //-------------------------------------------------------------------------------- 
    125         /** register effector class */ 
     125        /** Register effector class 
     126         *  @param name Effector name. 
     127         *  @param cls SiEffectBase based class. 
     128         */ 
    126129        public function register(name:String, cls:Class) : void 
    127130        { 
     
    130133         
    131134         
    132         /** get effector instance by name */ 
     135        /** Get effector instance by name  
     136         *  @param name Effector name. 
     137         */ 
    133138        public function getInstance(name:String) : SiEffectBase 
    134139        { 
     
    145150    // effector connection 
    146151    //-------------------------------------------------------------------------------- 
    147         /** clear effector chain. */ 
     152        /** Clear effector slot.  
     153         *  @param slot Effector slot number. 
     154         */ 
    148155        public function clear(slot:int) : void 
    149156        { 
     
    153160         
    154161         
    155         /** connect effector. */ 
     162        /** Connect effector to the slot. 
     163         *  @param slot Effector slot number. 
     164         *  @param effector Effector instance. 
     165         */ 
    156166        public function connect(slot:int, effector:SiEffectBase) : void 
    157167        { 
     
    160170         
    161171         
    162         /** Parse MML for effector */ 
     172        /** Parse MML for effector  
     173         *  @param slot Effector slot number. 
     174         *  @param mml MML string. 
     175         */ 
    163176        public function parseMML(slot:int, mml:String) : void 
    164177        { 
     
    213226    public var chain:Vector.<SiEffectBase> = new Vector.<SiEffectBase>(); 
    214227        public function get isActive() : Boolean { return (chain.length > 0); } 
     228    function EffectorChain() {} 
    215229} 
    216230 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectStereoChorus.as

    r2526 r2607  
    1212    public class SiEffectStereoChorus extends SiEffectBase 
    1313    { 
     14    // variables 
     15    //------------------------------------------------------------ 
    1416        static private const DELAY_BUFFER_BITS:int = 12; 
    1517        static private const DELAY_BUFFER_FILTER:int = (1<<DELAY_BUFFER_BITS)-1; 
     
    2729         
    2830         
     31         
     32         
     33    // constructor 
     34    //------------------------------------------------------------ 
    2935        /** constructor */ 
    3036        function SiEffectStereoChorus() 
     
    3642         
    3743         
    38         /** constructor 
     44         
     45         
     46    // operation 
     47    //------------------------------------------------------------ 
     48        /** set parameter 
    3949         *  @param delayTime delay time[ms]. maximum value is about 94. 
    4050         *  @param feedback feedback ratio(0-1). 
     
    5464         
    5565         
    56         // overrided funcitons 
    57         //------------------------------------------------------------ 
     66         
     67         
     68    // overrided funcitons 
     69    //------------------------------------------------------------ 
     70        /** @private */ 
    5871        override public function initialize() : void 
    5972        { 
     
    6578         
    6679 
     80        /** @private */ 
    6781        override public function mmlCallback(args:Vector.<Number>) : void 
    6882        { 
     
    7488         
    7589         
     90        /** @private */ 
    7691        override public function prepareProcess() : int 
    7792        { 
     
    8297         
    8398         
     99        /** @private */ 
    84100        override public function process(channels:int, buffer:Vector.<Number>, startIndex:int, length:int) : int 
    85101        { 
     
    91107            imax = startIndex + length; 
    92108            for (i=startIndex; i<imax-istep;) { 
    93                 processLFO(buffer, i, istep); 
     109                _processLFO(buffer, i, istep); 
    94110                _lfoPhase = (_lfoPhase + 1) & 255; 
    95111                i += istep; 
    96112                istep = _lfoStep<<1; 
    97113            } 
    98             processLFO(buffer, i, imax-i); 
     114            _processLFO(buffer, i, imax-i); 
    99115            _lfoResidueStep = istep - (imax - i); 
    100116            return channels; 
     
    102118         
    103119         
    104         public function processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 
     120        // process inside 
     121        private function _processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 
    105122        { 
    106123            var i:int, n:Number, m:Number, p:int, imax:int = startIndex + length, dly:int=int(_sin[_lfoPhase] * _depth); 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectStereoDelay.as

    r2526 r2607  
    1212    public class SiEffectStereoDelay extends SiEffectBase 
    1313    { 
     14    // variables 
     15    //------------------------------------------------------------ 
    1416        static private const DELAY_BUFFER_BITS:int = 16; 
    1517        static private const DELAY_BUFFER_FILTER:int = (1<<DELAY_BUFFER_BITS)-1; 
     
    2325         
    2426         
     27         
     28         
     29    // constructor 
     30    //------------------------------------------------------------ 
    2531        /** constructor */ 
    2632        function SiEffectStereoDelay() 
     
    3238         
    3339         
    34         /** constructor 
     40         
     41         
     42    // operation 
     43    //------------------------------------------------------------ 
     44        /** set parameters 
    3545         *  @param delayTime delay time[ms]. maximum value is about 1500. 
    3646         *  @param feedback feedback decay(-1-1). Negative value to invert phase. 
     
    4858         
    4959         
    50         // overrided funcitons 
    51         //------------------------------------------------------------ 
     60         
     61         
     62    // overrided funcitons 
     63    //------------------------------------------------------------ 
     64        /** @private */ 
    5265        override public function initialize() : void 
    5366        { 
     
    5669         
    5770 
     71        /** @private */ 
    5872        override public function mmlCallback(args:Vector.<Number>) : void 
    5973        { 
     
    6478         
    6579         
     80        /** @private */ 
    6681        override public function prepareProcess() : int 
    6782        { 
     
    7489         
    7590         
     91        /** @private */ 
    7692        override public function process(channels:int, buffer:Vector.<Number>, startIndex:int, length:int) : int 
    7793        { 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectTable.as

    r2526 r2607  
    99 
    1010package org.si.sound.effect { 
     11    /** @private Tables used in effectors. */ 
    1112    public class SiEffectTable { 
     13        /** sin table */ 
    1214        public var sinTable:Vector.<Number>; 
    1315         
    1416         
     17        /** constructor. */ 
    1518        function SiEffectTable() 
    1619        { 
     
    2225         
    2326         
     27        /** instance */ 
    2428        static public var instance:SiEffectTable; 
    2529         
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectWaveShaper.as

    r2526 r2607  
    1212    public class SiEffectWaveShaper extends SiEffectBase 
    1313    { 
     14    // variables 
     15    //------------------------------------------------------------ 
    1416        private var _coefficient:int; 
    1517         
    1618         
     19         
     20         
     21    // constructor 
     22    //------------------------------------------------------------ 
     23        /** constructor */ 
     24        function SiEffectWaveShaper() {}         
     25         
     26         
     27         
     28    // operations 
     29    //------------------------------------------------------------ 
    1730        /** set parameters 
    1831         *  @param distortion distortion(0-1). 
     
    2437         
    2538         
    26         // overrided funcitons 
    27         //------------------------------------------------------------ 
     39         
     40         
     41    // overrided funcitons 
     42    //------------------------------------------------------------ 
     43        /** @private */ 
    2844        override public function initialize() : void 
    2945        { 
     
    3248         
    3349 
     50        /** @private */ 
    3451        override public function mmlCallback(args:Vector.<Number>) : void 
    3552        { 
     
    3855         
    3956         
     57        /** @private */ 
    4058        override public function prepareProcess() : int 
    4159        { 
     
    4462         
    4563         
     64        /** @private */ 
    4665        override public function process(channels:int, buffer:Vector.<Number>, startIndex:int, length:int) : int 
    4766        { 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterAllPass.as

    r2526 r2607  
    1212    public class SiFilterAllPass extends SiFilterBase 
    1313    { 
     14    // operations 
     15    //------------------------------------------------------------ 
    1416        /** set parameters 
    1517         *  @param freq cutoff frequency[Hz]. 
     
    2729         
    2830         
    29         // overrided funcitons 
    30         //------------------------------------------------------------ 
     31    // overrided funcitons 
     32    //------------------------------------------------------------ 
     33        /** @private */ 
    3134        override public function initialize() : void 
    3235        { 
     
    3538         
    3639 
     40        /** @private */ 
    3741        override public function mmlCallback(args:Vector.<Number>) : void 
    3842        { 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterBandPass.as

    r2526 r2607  
    1212    public class SiFilterBandPass extends SiFilterBase 
    1313    { 
     14    // operations 
     15    //------------------------------------------------------------ 
    1416        /** set parameters 
    1517         *  @param freq cutoff frequency[Hz]. 
     
    2931         
    3032         
    31         // overrided funcitons 
    32         //------------------------------------------------------------ 
     33         
     34         
     35    // overrided funcitons 
     36    //------------------------------------------------------------ 
     37        /** @private */ 
    3338        override public function initialize() : void 
    3439        { 
     
    3742         
    3843 
     44        /** @private */ 
    3945        override public function mmlCallback(args:Vector.<Number>) : void 
    4046        { 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterBase.as

    r2526 r2607  
    1212    public class SiFilterBase extends SiEffectBase 
    1313    { 
     14    // variables 
     15    //------------------------------------------------------------ 
    1416        protected var _a1:Number, _a2:Number, _b0:Number, _b1:Number, _b2:Number; 
    1517        private var _in1L:Number, _in2L:Number, _out1L:Number, _out2L:Number; 
     
    1719         
    1820         
    19         // Math calculation 
    20         //------------------------------------------------------------ 
     21         
     22         
     23    // Math calculation 
     24    //------------------------------------------------------------ 
     25        /** hyperbolic sinh. */ 
    2126        protected function sinh(n:Number) : Number { 
    2227            return (Math.exp(n) - Math.exp(-n)) * 0.5; 
     
    2429         
    2530         
    26         // overrided funcitons 
    27         //------------------------------------------------------------ 
     31         
     32         
     33    // constructor 
     34    //------------------------------------------------------------ 
     35        /** constructor */ 
     36        function SiFilterBase() {} 
     37         
     38         
     39         
     40         
     41    // overrided funcitons 
     42    //------------------------------------------------------------ 
     43        /** @private */ 
    2844        override public function prepareProcess() : int 
    2945        { 
     
    3349         
    3450         
     51        /** @private */ 
    3552        override public function process(channels:int, buffer:Vector.<Number>, startIndex:int, length:int) : int 
    3653        { 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterHighPass.as

    r2526 r2607  
    1212    public class SiFilterHighPass extends SiFilterBase 
    1313    { 
     14    // operations 
     15    //------------------------------------------------------------ 
    1416        /** set parameters 
    1517         *  @param freq cutoff frequency[Hz]. 
     
    2830         
    2931         
    30         // overrided funcitons 
    31         //------------------------------------------------------------ 
     32    // overrided funcitons 
     33    //------------------------------------------------------------ 
     34        /** @private */ 
    3235        override public function initialize() : void 
    3336        { 
     
    3639         
    3740 
     41        /** @private */ 
    3842        override public function mmlCallback(args:Vector.<Number>) : void 
    3943        { 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterLowPass.as

    r2526 r2607  
    1212    public class SiFilterLowPass extends SiFilterBase 
    1313    { 
     14    // operations 
     15    //------------------------------------------------------------ 
    1416        /** set parameters 
    1517         *  @param freq cutoff frequency[Hz]. 
     
    2830         
    2931         
    30         // overrided funcitons 
    31         //------------------------------------------------------------ 
     32    // overrided funcitons 
     33    //------------------------------------------------------------ 
     34        /** @private */ 
    3235        override public function initialize() : void 
    3336        { 
     
    3639         
    3740 
     41        /** @private */ 
    3842        override public function mmlCallback(args:Vector.<Number>) : void 
    3943        { 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterNotch.as

    r2526 r2607  
    1212    public class SiFilterNotch extends SiFilterBase 
    1313    { 
     14    // operations 
     15    //------------------------------------------------------------ 
    1416        /** set parameters 
    1517         *  @param freq cutoff frequency[Hz]. 
     
    2830         
    2931         
    30         // overrided funcitons 
    31         //------------------------------------------------------------ 
     32    // overrided funcitons 
     33    //------------------------------------------------------------ 
     34        /** @private */ 
    3235        override public function initialize() : void 
    3336        { 
     
    3639         
    3740 
     41        /** @private */ 
    3842        override public function mmlCallback(args:Vector.<Number>) : void 
    3943        { 
  • as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterPeak.as

    r2526 r2607  
    1212    public class SiFilterPeak extends SiFilterBase 
    1313    { 
     14    // operations 
     15    //------------------------------------------------------------ 
    1416        /** set parameters 
    1517         *  @param freq cutoff frequency[Hz]. 
     
    3133         
    3234         
    33         // overrided funcitons 
    34         //------------------------------------------------------------ 
     35    // overrided funcitons 
     36    //------------------------------------------------------------ 
     37        /** @private */ 
    3538        override public function initialize() : void 
    3639        { 
     
    3942         
    4043 
     44        /** @private */ 
    4145        override public function mmlCallback(args:Vector.<Number>) : void 
    4246        { 
  • as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelBase.as

    r2526 r2607  
    115115        public function getSiOPMChannelParam(param:SiOPMChannelParam) : void {} 
    116116         
    117         /** algorism (@al) */ 
     117        /** algorism (&#64;al) */ 
    118118        public function setAlgorism(cnt:int, alg:int) : void {} 
    119         /** feedback (@fb) */ 
     119        /** feedback (&#64;fb) */ 
    120120        public function setFeedBack(fb:int, fbc:int) : void {} 
    121         /** parameters (@ call from SiMMLSequencerTrack.setChannelParameters()) */ 
     121        /** parameters (&#64; call from SiMMLTrack._setChannelParameters()) */ 
    122122        public function setParameters(param:Vector.<int>) : void {} 
    123         /** pgType & ptType (@ call from SiMMLChannelSetting.selectTone()/initializeTone()) */ 
     123        /** pgType & ptType (&#64; call from SiMMLChannelSetting.selectTone()/initializeTone()) */ 
    124124        public function setType(pgType:int, ptType:int) : void {} 
    125125        /** Release rate (s) */ 
     
    145145        /** active operator index (i). */ 
    146146        public function set activeOperatorIndex(i:int) : void { } 
    147         /** Release rate (@rr) */ 
     147        /** Release rate (&#64;rr) */ 
    148148        public function set rr(r:int) : void {} 
    149         /** total level (@tl)  */ 
     149        /** total level (&#64;tl)  */ 
    150150        public function set tl(i:int) : void {} 
    151         /** fine multiple (@ml)  */ 
     151        /** fine multiple (&#64;ml)  */ 
    152152        public function set fmul(i:int) : void {} 
    153         /** phase (@ph) */ 
     153        /** phase (&#64;ph) */ 
    154154        public function set phase(i:int) : void {} 
    155         /** detune (@dt) */ 
     155        /** detune (&#64;dt) */ 
    156156        public function set detune(i:int) : void {} 
    157         /** fixed pitch (@fx) */ 
     157        /** fixed pitch (&#64;fx) */ 
    158158        public function set fixedPitch(i:int) : void {} 
    159         /** ssgec (@se) */ 
     159        /** ssgec (&#64;se) */ 
    160160        public function set ssgec(i:int) : void {} 
    161161         
     
    167167        public function get bufferIndex() : int { return _bufferIndex; } 
    168168         
     169        /** is idling ? */ 
     170        public function get isIdling() : Boolean { return _isIdling; } 
    169171         
    170172         
     
    265267         
    266268         
    267         /** LP Filter envelop (@f). 
     269        /** LP Filter envelop (&#64;f). 
    268270         *  @param ar attack rate. 
    269271         *  @param dr1 decay rate 1. 
     
    293295         
    294296         
    295         /** LP Filter resonance (@f) [0,9]. */ 
     297        /** LP Filter resonance (&#64;f) [0,9]. */ 
    296298        public function setFilterResonance(i:int) : void 
    297299        { 
     
    312314    // connection control 
    313315    //-------------------------------------------------- 
    314         /** Set input pipe (@i).  
    315          *  @param level Input level. The value for a standard FM sound module is 15. 
     316        /** Set input pipe (&#64;i).  
     317         *  @param level Input level. The value for a standard FM sound module is 5. 
    316318         *  @param pipeIndex Input pipe index (0-3). 
    317319         */ 
    318320        public function setInput(level:int, pipeIndex:int) : void 
    319321        { 
    320             var i:int; 
    321  
    322322            // pipe index 
    323323            pipeIndex &= 3; 
    324              
    325             // input level 
    326             _inputLevel = level; 
    327324             
    328325            // set pipe 
     
    330327                _inPipe = _chip.getPipe(pipeIndex, _bufferIndex); 
    331328                _inputMode = INPUT_PIPE; 
     329                _inputLevel = level + 10; 
    332330            } else { 
    333331                _inPipe = _chip.zeroBuffer; 
    334332                _inputMode = INPUT_ZERO; 
    335             } 
    336         } 
    337          
    338          
    339         /** Set ring modulation pipe (@r). 
     333                _inputLevel = 0; 
     334            } 
     335        } 
     336         
     337         
     338        /** Set ring modulation pipe (&#64;r). 
    340339         *  @param level. Input level(0-8). 
    341340         *  @param pipeIndex Input pipe index (0-3). 
     
    356355         
    357356         
    358         /** Set output pipe (@o). 
     357        /** Set output pipe (&#64;o). 
    359358         *  @param outputMode Output mode. 0=standard stereo out, 1=overwrite pipe. 2=add pipe. 
    360          *  @param outputIndex Output stream/pipe index (0-3). 
     359         *  @param pipeIndex Output stream/pipe index (0-3). 
    361360         */ 
    362         public function setOutput(outputMode:int, outputIndex:int) : void 
    363         { 
    364             if (outputIndex > 3) return; 
     361        public function setOutput(outputMode:int, pipeIndex:int) : void 
     362        { 
    365363            var i:int, flagAdd:Boolean; 
     364             
     365            // pipe index 
     366            pipeIndex &= 3; 
    366367 
    367368            // set pipe 
    368369            if (outputMode == OUTPUT_STANDARD) { 
    369                 outputIndex = 4;                  // pipe[4] is used. 
    370                 flagAdd = false;                  // ovewrite mode 
     370                pipeIndex = 4;      // pipe[4] is used. 
     371                flagAdd = false;    // ovewrite mode 
    371372            } else { 
    372373                flagAdd = (outputMode == OUTPUT_ADD);  // ovewrite/additional mode 
     
    377378 
    378379            // set output pipe 
    379             _outPipe = _chip.getPipe(outputIndex, _bufferIndex); 
     380            _outPipe = _chip.getPipe(pipeIndex, _bufferIndex); 
    380381 
    381382            // set base pipe 
     
    472473        { 
    473474            _bufferIndex = 0; 
    474             _isIdling = false; 
    475475        } 
    476476         
     
    507507             
    508508            // update buffer index 
     509            _bufferIndex += len; 
     510        } 
     511         
     512         
     513        /** Buffering without processnig */ 
     514        public function nop(len:int) : void 
     515        { 
     516            _nop(len); 
    509517            _bufferIndex += len; 
    510518        } 
     
    639647        protected function _nop(len:int) : void 
    640648        { 
    641             var i:int; 
    642             // buffering 
    643             var bp:SLLint = _basePipe, 
    644                 op:SLLint = _outPipe; 
    645             for (i=0; i<len; i++) { 
    646                 // increment 
    647                 op.i = bp.i; 
    648                 bp = bp.next; 
    649                 op = op.next; 
    650             } 
    651             // update pointers 
    652             _basePipe = bp; 
    653             _outPipe  = op; 
     649            var i:int, p:SLLint; 
     650             
     651            // rotate output buffer 
     652            if (_outputMode == OUTPUT_STANDARD) { 
     653                _outPipe = _chip.getPipe(4, (_bufferIndex + len) & (_chip.bufferLength-1)); 
     654            } else { 
     655                for (p=_outPipe, i=0; i<len; i++) p = p.next; 
     656                _outPipe  = p; 
     657                _basePipe = (_outputMode == OUTPUT_ADD) ? p : _chip.zeroBuffer; 
     658            } 
     659             
     660            // rotate input buffer when connected by @i 
     661            if (_inputMode == INPUT_PIPE) { 
     662                for (p=_inPipe, i=0; i<len; i++) p = p.next; 
     663                _inPipe = p; 
     664            } 
     665             
     666            // rotate ring buffer 
     667            if (_ringPipe) { 
     668                for (p=_ringPipe, i=0; i<len; i++) p = p.next; 
     669                _ringPipe = p; 
     670            } 
    654671        } 
    655672         
  • as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelFM.as

    r2526 r2607  
    1515     
    1616     
    17     /** FM sound channel. <br/
     17    /** FM sound channel. <p
    1818     *  The calculation of this class is based on OPM emulation (refer from sources of mame, fmgen and x68sound). 
    1919     *  And it has some extension to simulate other sevral fm sound modules (OPNA, OPLL, OPL2, OPL3, OPX, MA3, MA5, MA7, TSS and DX7). 
     
    3434     *    <li>ring modulation (from C64?)</li> 
    3535     *  </ul> 
     36     *  </p> 
    3637     */ 
    3738    public class SiOPMChannelFM extends SiOPMChannelBase 
     
    297298    // interfaces 
    298299    //-------------------------------------------------- 
    299         /** Set algorism (@al)  
     300        /** Set algorism (&#64;al)  
    300301         *  @param cnt Operator count. 
    301302         *  @param alg Algolism number of the operator's connection. 
     
    315316         
    316317         
    317         /** Set feedback(@fb). This also initializes the input mode(@i).  
     318        /** Set feedback(&#64;fb). This also initializes the input mode(&#64;i).  
    318319         *  @param fb Feedback level. Ussualy in the range of 0-7. 
    319320         *  @param fbc Feedback connection. Operator index which feeds back its output. 
     
    338339         
    339340         
    340         /** Set parameters (@ command). */ 
     341        /** Set parameters (&#64; command). */ 
    341342        override public function setParameters(param:Vector.<int>) : void 
    342343        { 
     
    347348         
    348349         
    349         /** pgType & ptType (@) */ 
     350        /** pgType & ptType (&#64;) */ 
    350351        override public function setType(pgType:int, ptType:int) : void 
    351352        { 
     353            var funcIndex:int = _operatorCount-1; 
     354            if (pgType >= SiOPMTable.PG_PCM) { 
     355                _updateOperatorCount(1); 
     356                funcIndex = 4; 
     357            } 
    352358            activeOperator.pgType = pgType; 
    353359            activeOperator.ptType = ptType; 
    354             if (operator[0]._pgType >= SiOPMTable.PG_PCM) _funcProcess = _funcProcessList[_lfo_on][4]; 
    355             else _funcProcess = _funcProcessList[_lfo_on][_operatorCount-1]; 
     360            _funcProcess = _funcProcessList[_lfo_on][funcIndex]; 
    356361        } 
    357362         
     
    368373         
    369374         
    370         /** Set input pipe(@i). This function is almost same as super.setInput(). This also initializes the feed back setting(@fb).  
    371          *  @param level Input level. The value for a standard FM sound module is 5. 
    372          *  @param pipeIndex Input pipe index (0-3). 
    373          */ 
    374         override public function setInput(level:int, pipeIndex:int) : void 
    375         { 
    376             var i:int; 
    377              
    378             // pipe index 
    379             pipeIndex &= 3; 
    380              
    381             // set pipe 
    382             if (level > 0) { 
    383                 _inPipe = _chip.getPipe(pipeIndex, _bufferIndex); 
    384                 _inputMode = INPUT_PIPE; 
    385                 _inputLevel = level + 10;   // different from super.setInput() 
    386             } else { 
    387                 _inPipe = _chip.zeroBuffer; 
    388                 _inputMode = INPUT_ZERO; 
    389                 _inputLevel = 0; 
    390             } 
    391         } 
    392          
    393          
    394375         
    395376         
     
    412393        } 
    413394         
    414         /** release rate (@rr) */ 
     395        /** release rate (&#64;rr) */ 
    415396        override public function set rr(i:int) : void { activeOperator.rr = i; } 
    416397         
    417         /** total level (@tl) */ 
     398        /** total level (&#64;tl) */ 
    418399        override public function set tl(i:int) : void { activeOperator.tl = i; } 
    419400         
    420         /** fine multiple (@ml) */ 
     401        /** fine multiple (&#64;ml) */ 
    421402        override public function set fmul(i:int) : void { activeOperator.fmul = i; } 
    422403         
    423         /** phase  (@ph) */ 
     404        /** phase  (&#64;ph) */ 
    424405        override public function set phase(i:int) : void { activeOperator.keyOnPhase = i; } 
    425406         
    426         /** detune (@dt) */ 
     407        /** detune (&#64;dt) */ 
    427408        override public function set detune(i:int) : void { activeOperator.detune = i; } 
    428409         
    429         /** fixed pitch (@fx) */ 
     410        /** fixed pitch (&#64;fx) */ 
    430411        override public function set fixedPitch(i:int) : void { activeOperator.fixedPitchIndex = i; } 
    431412         
    432         /** ssgec (@se) */ 
     413        /** ssgec (&#64;se) */ 
    433414        override public function set ssgec(i:int) : void { activeOperator.ssgec = i; } 
    434415         
     
    12681249            // select processing function 
    12691250            _funcProcess = _funcProcessList[_lfo_on][_operatorCount-1]; 
     1251             
    12701252            // default active operator is the last one. 
    12711253            activeOperator = operator[_operatorCount-1]; 
  • as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelManager.as

    r2526 r2607  
    1616        static public const CT_CHANNEL_FM:int = 0; 
    1717        static public const CT_CHANNEL_SAMPLER:int = 1; 
    18         static public const CT_EFFECT_DELAY:int = 2; 
    19         static public const CT_MAX:int = 3; 
     18        static public const CT_MAX:int = 2; 
    2019         
    2120         
     
    6261    // operations 
    6362    //-------------------------------------------------- 
    64         /** allocate channels */ 
     63        // allocate channels. 
    6564        private function _alloc(count:int) : void 
    6665        { 
     
    167166            _channelManagers[CT_CHANNEL_FM]      = new SiOPMChannelManager(SiOPMChannelFM,          CT_CHANNEL_FM); 
    168167            _channelManagers[CT_CHANNEL_SAMPLER] = new SiOPMChannelManager(SiOPMChannelSampler,     CT_CHANNEL_SAMPLER); 
    169             _channelManagers[CT_EFFECT_DELAY]    = new SiOPMChannelManager(SiOPMChannelEffectDelay, CT_EFFECT_DELAY); 
    170168        } 
    171169         
  • as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelParam.as

    r2526 r2607  
    99 
    1010package org.si.sound.module { 
    11     import org.si.sound.mml.MMLSequence; 
     11    import org.si.sound.mml.base.MMLSequence; 
    1212     
    1313     
    14     /** SiOPM Parameters */ 
     14    /** SiOPM Channel Parameters. This is a member of SiONToneSetting.  
     15     *  @see org.si.sound.SiONToneSetting 
     16     *  @see org.si.sound.module.SiOPMOperatorParam 
     17     */ 
    1518    public class SiOPMChannelParam 
    1619    { 
     
    7477            lfoFreqStep = SiOPMTable.LFO_TIMER_INITIAL/(fps*2.882352941176471); 
    7578        } 
    76          
    7779        public function get lfoFrame() : int 
    7880        { 
     
    8183         
    8284         
     85        /** constructor */ 
    8386        function SiOPMChannelParam() 
    8487        { 
     
    9497         
    9598         
     99        /** initializer */ 
    96100        public function initialize() : SiOPMChannelParam 
    97101        { 
     
    133137         
    134138         
     139        /** copier */ 
    135140        public function copyFrom(org:SiOPMChannelParam) : SiOPMChannelParam 
    136141        { 
     
    171176         
    172177         
     178        /** information */ 
    173179        public function toString() : String 
    174180        { 
  • as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelSampler.as

    r2526 r2607  
    9797    // interfaces 
    9898    //-------------------------------------------------- 
    99         /** Set algorism (@al)  
     99        /** Set algorism (&#64;al)  
    100100         *  @param cnt Operator count. 
    101101         *  @param alg Algolism number of the operator's connection. 
     
    106106         
    107107         
    108         /** Set parameters (@ command). */ 
    109         override public function setParameters(param:Vector.<int>) : void 
    110         { 
     108        /** pgType & ptType (&#64; call from SiMMLChannelSetting.selectTone()/initializeTone()) */ 
     109        override public function setType(pgType:int, ptType:int) : void  
     110        { 
     111            _bankNumber = pgType & 1; 
    111112        } 
    112113         
     
    132133        } 
    133134         
    134         /** phase (@ph) */ 
     135        /** phase (&#64;ph) */ 
    135136        override public function set phase(i:int) : void { 
    136137            _samplePhaseReset = (i!=-1); 
     
    182183                _isNoteOn = true; 
    183184                _isIdling = false; 
    184                 var idx:int = _waveNumber + (_bankNumber<<7) + SiOPMTable.PG_SAMPLE; 
     185                var idx:int = _waveNumber + (_bankNumber<<7) + SiOPMTable.PG_SAMPLE, 
     186                    flag:int = _table.waveFixedBits[idx]; 
    185187                _sample = _table.waveTables[idx]; 
    186188                _sampleLength = _sample.length; 
    187                 _sampleChannelCount = _table.waveFixedBits[idx]; 
     189                _sampleChannelCount = (flag & 1) ? 2 : 1; 
     190                _isOneShot = Boolean(flag >> 1); 
    188191                if (_samplePhaseReset) _sampleIndex = 0; 
    189192            } 
     
    194197        override public function noteOff() : void 
    195198        { 
    196             _isNoteOn = false; 
    197199            if (!_isOneShot) { 
     200                _isNoteOn = false; 
    198201                _isIdling = true; 
    199202                _sample = null; 
     
    210213         
    211214         
    212         /** Prepare buffering */ 
    213         override public function prepareBuffer() : void 
    214         { 
    215             _bufferIndex = 0; 
    216             _isIdling = false; 
    217         } 
    218          
    219          
    220215        /** Buffering */ 
    221216        override public function buffer(len:int) : void 
     
    223218            var i:int, imax:int, vol:Number; 
    224219            if (_isIdling || _sample == null) { 
    225                 _nop(len);  // idling 
     220                //_nop(len); 
    226221            } else { 
    227222                var residureLen:int = _sampleLength - _sampleIndex, 
     
    237232                    _chip.streamBuffer[0].writeVectorInt(_sample, _sampleIndex, _bufferIndex, procLen, vol, _pan, _sampleChannelCount); 
    238233                } 
    239                 if (len > procLen) _nop(len - procLen); 
     234                if (len > procLen) { 
     235                    _isIdling = true; 
     236                    _sample = null; 
     237                    //_nop(len - procLen); 
     238                } 
    240239            } 
    241240             
     
    244243            _sampleIndex += len; 
    245244        } 
     245         
     246         
     247        /** Buffering without processnig */ 
     248        override public function nop(len:int) : void 
     249        { 
     250            //_nop(len); 
     251            _bufferIndex += len; 
     252        } 
    246253    } 
    247254} 
  • as3/SiOPM/trunk/src/org/si/sound/module/SiOPMModule.as

    r2526 r2607  
    2121    // constants 
    2222    //-------------------------------------------------- 
     23        /** maximum value of stream buffer size */ 
    2324        static public const STREAM_SIZE_MAX:int = 8; 
     25        /** pipe size */ 
    2426        static public const PIPE_SIZE:int = 5; 
    2527         
     
    3638        public var streamBuffer:Vector.<SiOPMStream>; 
    3739         
    38         /** Operator */ 
    39         protected var _freeOperators:Vector.<SiOPMOperator>; 
    40         /** buffer length */ 
    41         protected var _bufferLength:int; 
     40        private var _freeOperators:Vector.<SiOPMOperator>;   // Free list for SiOPMOperator 
     41        private var _bufferLength:int;                       // buffer length 
    4242         
    4343        // pipes 
     
    5454         
    5555         
    56         /** stream count */ 
     56        /** stream buffer count */ 
    5757        public function set streamCount(count:int) : void  
    5858        { 
     
    147147        } 
    148148         
     149         
    149150        /** Clear all buffer. */ 
    150151        public function clearAllBuffers() : void 
  • as3/SiOPM/trunk/src/org/si/sound/module/SiOPMOperator.as

    r2011 r2607  
    1212     
    1313     
    14     /** SiOPM operator class.<br/> 
     14    /** SiOPM operator class. 
     15     *  <p> 
    1516     *  This operator based on the OPM emulation of MAME, but its extended in below points,<br/> 
    1617     *  1) You can set the phase offest of pulse generator. <br/> 
    17      *  2) You can select the wave form from some wave tables (see class SiOPMTable). 
    18      *  3) You can set the key scale level. 
    19      *  4) You can fix the pitch. 
    20      *  5) You can set the ssgec in OPNA. 
     18     *  2) You can select the wave form from some wave tables (see class SiOPMTable).<br/> 
     19     *  3) You can set the key scale level.<br/> 
     20     *  4) You can fix the pitch.<br/> 
     21     *  5) You can set the ssgec in OPNA.<br/> 
     22     *  </p> 
    2123     */ 
    2224    public class SiOPMOperator 
     
    4143    // Never access these valiables in other classes reason for the maintenances. 
    4244    //---------------------------------------------------------------------------------------------------- 
    43         /** table */ 
     45        /** @private table */ 
    4446        internal var _table:SiOPMTable; 
    45         /** chip */ 
     47        /** @private chip */ 
    4648        internal var _chip:SiOPMModule; 
    4749         
    4850         
    4951    // FM module parameters 
    50         /** Attack rate [0,63] */ 
     52        /** @private Attack rate [0,63] */ 
    5153        internal var _ar:int; 
    52         /** Decay rate [0,63] */ 
     54        /** @private Decay rate [0,63] */ 
    5355        internal var _dr:int; 
    54         /** Sustain rate [0,63] */ 
     56        /** @private Sustain rate [0,63] */ 
    5557        internal var _sr:int; 
    56         /** Release rate [0,63] */ 
     58        /** @private Release rate [0,63] */ 
    5759        internal var _rr:int; 
    58         /** Sustain level [0,15] */ 
     60        /** @private Sustain level [0,15] */ 
    5961        internal var _sl:int; 
    60         /** Total level [0,127] */ 
     62        /** @private Total level [0,127] */ 
    6163        internal var _tl:int; 
    62         /** Key scaling rate = 5-ks [5,2] */ 
     64        /** @private Key scaling rate = 5-ks [5,2] */ 
    6365        internal var _ks:int; 
    64         /** Key scaling level [0,3] */ 
     66        /** @private Key scaling level [0,3] */ 
    6567        internal var _ksl:int; 
    66         /** _multiple = (mul) ? (mul<<7) : 64; [64,128,256,384,512...] */ 
     68        /** @private _multiple = (mul) ? (mul<<7) : 64; [64,128,256,384,512...] */ 
    6769        internal var _multiple:int; 
    68         /** dt1 [0,7]. */ 
     70        /** @private dt1 [0,7]. */ 
    6971        internal var _dt1:int; 
    70         /** dt2 [0,3]. This value is linked with _pitchIndexShift */ 
     72        /** @private dt2 [0,3]. This value is linked with _pitchIndexShift */ 
    7173        internal var _dt2:int; 
    72         /** Amp modulation shift [16,0] */ 
     74        /** @private Amp modulation shift [16,0] */ 
    7375        internal var _ams:int; 
    74         /** Key code = oct<<4 + note [0,127] */ 
     76        /** @private Key code = oct<<4 + note [0,127] */ 
    7577        internal var _kc:int; 
    76         /** SSG type envelop control */ 
     78        /** @private SSG type envelop control */ 
    7779        internal var _ssg_type:int; 
    78         /** Mute [0/SiOPMTable.ENV_BOTTOM] */ 
     80        /** @private Mute [0/SiOPMTable.ENV_BOTTOM] */ 
    7981        internal var _mute:int; 
    8082         
    8183         
    8284    // pulse generator 
    83         /** pulse generator type */ 
     85        /** @private pulse generator type */ 
    8486        internal var _pgType:int; 
    85         /** pitch table type */ 
     87        /** @private pitch table type */ 
    8688        internal var _ptType:int; 
    87         /** wave table */ 
     89        /** @private wave table */ 
    8890        internal var _waveTable:Vector.<int>; 
    89         /** phase shift */ 
     91        /** @private phase shift */ 
    9092        internal var _waveFixedBits:int; 
    91         /** phase step shift */ 
     93        /** @private phase step shift */ 
    9294        internal var _wavePhaseStepShift:int; 
    93         /** pitch table */ 
     95        /** @private pitch table */ 
    9496        internal var _pitchTable:Vector.<int>; 
    95         /** pitch table index filter */ 
     97        /** @private pitch table index filter */ 
    9698        internal var _pitchTableFilter:int; 
    97         /** phase */ 
     99        /** @private phase */ 
    98100        internal var _phase:int; 
    99         /** phase step */ 
     101        /** @private phase step */ 
    100102        internal var _phase_step:int; 
    101         /** keyOn phase */ 
     103        /** @private keyOn phase */ 
    102104        internal var _keyon_phase:int; 
    103         /** pitch fixed */ 
     105        /** @private pitch fixed */ 
    104106        internal var _pitchFixed:Boolean; 
    105         /** dt1 table */ 
     107        /** @private dt1 table */ 
    106108        internal var _dt1Table:Vector.<int>; 
    107109 
    108110         
    109         /** pitch index = note * 64 + key fraction */ 
     111        /** @private pitch index = note * 64 + key fraction */ 
    110112        internal var _pitchIndex:int; 
    111         /** pitch index shift. This value is linked with dt2 and detune. */ 
     113        /** @private pitch index shift. This value is linked with dt2 and detune. */ 
    112114        internal var _pitchIndexShift:int; 
    113         /** pitch index shift by pitch modulation. This value is linked with dt2. */ 
     115        /** @private pitch index shift by pitch modulation. This value is linked with dt2. */ 
    114116        internal var _pitchIndexShift2:int; 
    115         /** frequency modulation left-shift. 15 for FM, fb+6 for feedback. */ 
     117        /** @private frequency modulation left-shift. 15 for FM, fb+6 for feedback. */ 
    116118        internal var _fmShift:int; 
    117119         
    118120         
    119121    // envelop generator 
    120         /** State [EG_ATTACK, EG_DECAY, EG_SUSTAIN, EG_RELEASE, EG_OFF] */ 
     122        /** @private State [EG_ATTACK, EG_DECAY, EG_SUSTAIN, EG_RELEASE, EG_OFF] */ 
    121123        internal var _eg_state:int; 
    122         /** Envelop generator updating timer, initialized (2047 * 3) << CLOCK_RATIO_BITS. */ 
     124        /** @private Envelop generator updating timer, initialized (2047 * 3) << CLOCK_RATIO_BITS. */ 
    123125        internal var _eg_timer:int; 
    124         /** Timer stepping by samples */ 
     126        /** @private Timer stepping by samples */ 
    125127        internal var _eg_timer_step:int; 
    126         /** Counter rounded on 8. */ 
     128        /** @private Counter rounded on 8. */ 
    127129        internal var _eg_counter:int; 
    128         /** Internal sustain level [0,SiOPMTable.ENV_BOTTOM] */ 
     130        /** @private Internal sustain level [0,SiOPMTable.ENV_BOTTOM] */ 
    129131        internal var _eg_sustain_level :int; 
    130         /** Internal total level [0,1024] = ((tl + f(kc, ksl)) << 3) + _eg_tl_offset + 192. */ 
     132        /** @private Internal total level [0,1024] = ((tl + f(kc, ksl)) << 3) + _eg_tl_offset + 192. */ 
    131133        internal var _eg_total_level:int; 
    132         /** Internal total level offset by volume [-192,832]*/ 
     134        /** @private Internal total level offset by volume [-192,832]*/ 
    133135        internal var _eg_tl_offset:int; 
    134         /** Internal key scaling rate = _kc >> _ks [0,32] */ 
     136        /** @private Internal key scaling rate = _kc >> _ks [0,32] */ 
    135137        internal var _eg_key_scale_rate:int; 
    136         /** Internal key scaling level right shift = _ksl[0,1,2,3]->[8,2,1,0] */ 
     138        /** @private Internal key scaling level right shift = _ksl[0,1,2,3]->[8,2,1,0] */ 
    137139        internal var _eg_key_scale_level_rshift:int; 
    138         /** Envelop generator level [0,1024] */ 
     140        /** @private Envelop generator level [0,1024] */ 
    139141        internal var _eg_level:int; 
    140         /** Envelop generator output [0,1024<<3] */ 
     142        /** @private Envelop generator output [0,1024<<3] */ 
    141143        internal var _eg_out:int; 
    142         /** SSG envelop control ar switch */ 
     144        /** @private SSG envelop control ar switch */ 
    143145        internal var _eg_ssgec_ar:int; 
    144         /** SSG envelop control state */ 
     146        /** @private SSG envelop control state */ 
    145147        internal var _eg_ssgec_state:int; 
    146148         
    147         /** Increment table picked up from _eg_incTables or _eg_incTablesAtt. */ 
     149        /** @private Increment table picked up from _eg_incTables or _eg_incTablesAtt. */ 
    148150        internal var _eg_incTable:Vector.<int>; 
    149         /** The level to shift the state to next. */ 
     151        /** @private The level to shift the state to next. */ 
    150152        internal var _eg_stateShiftLevel:int; 
    151         /** Next status list */ 
     153        /** @private Next status list */ 
    152154        internal var _eg_nextState:Vector.<int>; 
    153         /** _eg_level converter */ 
     155        /** @private _eg_level converter */ 
    154156        internal var _eg_levelTable:Vector.<int>; 
    155         /** Next status table */ 
     157        // Next status table 
    156158        static private var _table_nextState:Array = [ 
    157159            //            EG_ATTACK,  EG_DECAY,   EG_SUSTAIN, EG_RELEASE, EG_OFF 
     
    162164         
    163165    // pipes 
    164         /** flag that is final carrior. */ 
     166        /** @private flag that is final carrior. */ 
    165167        internal var _final:Boolean; 
    166         /** modulator output */ 
     168        /** @private modulator output */ 
    167169        internal var _inPipe:SLLint; 
    168         /** base */ 
     170        /** @private base */ 
    169171        internal var _basePipe:SLLint; 
    170         /** output */ 
     172        /** @private output */ 
    171173        internal var _outPipe:SLLint; 
    172         /** feed back */ 
     174        /** @private feed back */ 
    173175        internal var _feedPipe:SLLint; 
    174176         
     
    581583    // internal operations 
    582584    //-------------------------------------------------- 
    583         /** Update envelop generator. This code is only for testing. */ 
     585        /** @private Update envelop generator. This code is only for testing. */ 
    584586        internal function eg_update() : void 
    585587        { 
     
    602604         
    603605         
    604         /** Update pulse generator. This code is only for testing. */ 
     606        /** @private Update pulse generator. This code is only for testing. */ 
    605607        internal function pg_update() : void 
    606608        { 
     
    614616         
    615617         
    616         /** Shift envelop generator state. */ 
     618        /** @private Shift envelop generator state. */ 
    617619        internal function _eg_shiftState(state:int) : void 
    618620        { 
  • as3/SiOPM/trunk/src/org/si/sound/module/SiOPMOperatorParam.as

    r2011 r2607  
    99 
    1010package org.si.sound.module { 
    11     /** OPM Parameters */ 
     11    /** OPM Parameters. This is a member of SiOPMChannelParam.  
     12     *  @see org.si.sound.SiONToneSetting 
     13     *  @see org.si.sound.module.SiOPMChannelParam 
     14     */ 
    1215    public class SiOPMOperatorParam 
    1316    { 
     
    7073         
    7174         
     75        /** constructor */ 
    7276        function SiOPMOperatorParam() 
    7377        { 
     
    7680         
    7781         
     82        /** intialize all parameters. */ 
    7883        public function initialize() : void 
    7984        { 
     
    100105         
    101106         
     107        /** copy all parameters. */ 
    102108        public function copyFrom(org:SiOPMOperatorParam) : void 
    103109        { 
     
    124130         
    125131         
     132        /** all parameters in 1line. */ 
    126133        public function toString() : String 
    127134        { 
  • as3/SiOPM/trunk/src/org/si/sound/module/SiOPMTable.as

    r2526 r2607  
    9292        static public const PG_CUSTOM     :int = 256;   // (256- 511) custom wave table. PG_CUSTOM+[0,255] 
    9393        static public const PG_PCM        :int = 512;   // (512-767)  pcm module.PG_PCM+[0,255] 
    94         static public const PG_SAMPLE     :int = 768;   // (768-1023) samplar module.PG_SAMPLE+[0,255] 
    95         static public const DEFAULT_PG_MAX:int = 1024;  // max value of pgType = 1023 
     94        static public const PG_SAMPLE     :int = 768;   // (768-1024) samplar module.PG_SAMPLE+[0,255] 
     95        static public const DEFAULT_PG_MAX:int = 1024;  // max value of pgType = 1024 
    9696        static public const PG_FILTER     :int = 1023;  // pg number loops between 0 to 1023 
    9797 
     
    11061106         
    11071107        /** Register Sampler data. */ 
    1108         static public function registerSample(index:int, table:Vector.<int>, channelCount:int) : void 
     1108        static public function registerSample(index:int, table:Vector.<int>, flag:int) : void 
    11091109        { 
    11101110            // offset index 
     
    11131113            // register wave table 
    11141114            instance.waveTables[table_index]    = table; 
    1115             instance.waveFixedBits[table_index] = channelCount
     1115            instance.waveFixedBits[table_index] = flag
    11161116        } 
    11171117    } 
  • as3/SiOPM/trunk/src/org/si/sound/mx/SiOPMPlayer.as

    r2526 r2607  
    1313    import flash.media.SoundChannel; 
    1414    import mx.core.UIComponent; 
    15     import org.si.sound.SiOPMData; 
    16     import org.si.sound.SiOPMEvent; 
    17     import org.si.sound.SiOPMDriver; 
    18     import org.si.sound.driver.SiMMLSequencerTrack; 
     15        import org.si.sound.events.*; 
     16    import org.si.sound.SiONData; 
     17    import org.si.sound.SiONDriver; 
    1918     
    2019     
     
    2625    //---------------------------------------- 
    2726        /** driver. */ 
    28         public var driver:SiOPMDriver; 
     27        public var driver:SiONDriver; 
    2928         
    30         private var _lineCommand:Vector.<int> = new Vector.<int>(65); 
    31         private var _lineVectorL:Vector.<Number> = new Vector.<Number>(130); 
    32         private var _lineVectorR:Vector.<Number> = new Vector.<Number>(130); 
    3329         
    3430         
     
    4137         *  @param bitRate Bit ratio of wave. 8 or 16 is available. 
    4238         *  @param bufferSize Buffer size of sound stream. 8192, 4096 or 2048 is available, but no check. 
    43          *  @param throwErrorEvent true; throw ErrorEvent when it errors. false; throw Error when it errors. 
    4439         */ 
    45         function SiOPMPlayer(channelCount:int=2, sampleRate:int=44100, bitRate:int=16, bufferSize:int=8192, throwErrorEvent:Boolean=true
     40        function SiOPMPlayer(bufferSize:int=2048, channelCount:int=2, sampleRate:int=44100, bitRate:int=0
    4641        { 
    47             driver = new SiOPMDriver(channelCount, sampleRate, bitRate, bufferSize, throwErrorEvent); 
    48             driver.addEventListener(SiOPMEvent.COMPILE_COMPLETE, _throughEvent); 
    49             driver.addEventListener(SiOPMEvent.COMPILE_PROGRESS, _throughEvent); 
    50             driver.addEventListener(SiOPMEvent.STREAM,           _onStream); 
    51             driver.addEventListener(SiOPMEvent.STREAM_START,     _throughEvent); 
    52             driver.addEventListener(SiOPMEvent.STREAM_STOP,      _throughEvent); 
    53             driver.addEventListener(ErrorEvent.ERROR,            _throughEvent); 
    54  
    55             function _throughEvent(e:Event) : void { dispatchEvent(e); } 
    56             for (var i:int=0; i<130; i+=2) { 
    57                 _lineCommand[i>>1] = (i) ? 2 : 1; 
    58                 _lineVectorL[i] = _lineVectorR[i] = i; 
    59             } 
     42            driver = new SiONDriver(bufferSize, channelCount, sampleRate, bitRate); 
     43            driver.addEventListener(SiONEvent.STREAM, _onStream); 
    6044        } 
    6145         
    6246         
    63         private function _onStream(event:SiOPMEvent) : void  
     47        private function _onStream(event:SiONEvent) : void  
    6448        { 
    65             var data:Vector.<Number> = event.driver.module.output, 
    66                 ci:int, i:int, imax:int = data.length, step:int = imax>>7; 
    67             for (ci=1, i=0; ci<130; i+=step, ci+=2) { 
    68                 _lineVectorL[ci] = data[i]*16+20; 
    69                 _lineVectorR[ci] = data[i+1]*16+60; 
    70             } 
    71             graphics.clear(); 
    72             graphics.lineStyle(1, 0xffffff); 
    73             graphics.drawPath(_lineCommand, _lineVectorL); 
    74             graphics.drawPath(_lineCommand, _lineVectorR); 
    75             dispatchEvent(event); 
    7649        } 
    7750    }