チェンジセット 3480

差分発生行の前後
無視リスト:
コミット日時:
2010/03/04 01:54:56 (2 年前)
コミッタ:
keim
ログメッセージ:

SiON ver0.59 updated. This version is only for development.

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/SiOPM/trunk/src/org/si/license.txt

    r3165 r3480  
    11License 
    22------- 
    3 Copyright (c) 2009 Kei Mesuda (keim) All rights reserved.  
     3Copyright (c) 2008-2010 Kei Mesuda (keim) All rights reserved.  
    44 
    55Redistribution and use in source and binary forms,  
  • as3/SiOPM/trunk/src/org/si/sion/SiONDriver.as

    r3450 r3480  
    3535    import org.si.sion.utils.Fader; 
    3636    import org.si.sion.namespaces._sion_internal; 
     37     
     38     
     39    // Dispatching events 
     40    /** @eventType org.si.sion.events.SiONEvent.QUEUE_PROGRESS */ 
     41    [Event(name="queueProgress",   type="org.si.sion.events.SiONEvent")] 
     42    /** @eventType org.si.sion.events.SiONEvent.QUEUE_COMPLETE */ 
     43    [Event(name="queueComplete",   type="org.si.sion.events.SiONEvent")] 
     44    /** @eventType org.si.sion.events.SiONEvent.QUEUE_CANCEL */ 
     45    [Event(name="queueCancel",     type="org.si.sion.events.SiONEvent")] 
     46    /** @eventType org.si.sion.events.SiONEvent.STREAM */ 
     47    [Event(name="stream",          type="org.si.sion.events.SiONEvent")] 
     48    /** @eventType org.si.sion.events.SiONEvent.STREAM_START */ 
     49    [Event(name="streamStart",     type="org.si.sion.events.SiONEvent")] 
     50    /** @eventType org.si.sion.events.SiONEvent.STREAM_STOP */ 
     51    [Event(name="streamStop",      type="org.si.sion.events.SiONEvent")] 
     52    /** @eventType org.si.sion.events.SiONEvent.FINISH_SEQUENCE */ 
     53    [Event(name="finishSequence",  type="org.si.sion.events.SiONEvent")] 
     54    /** @eventType org.si.sion.events.SiONEvent.FADE_PROGRESS */ 
     55    [Event(name="fadeProgress",    type="org.si.sion.events.SiONEvent")] 
     56    /** @eventType org.si.sion.events.SiONEvent.FADE_IN_COMPLETE */ 
     57    [Event(name="fadeInComplete",  type="org.si.sion.events.SiONEvent")] 
     58    /** @eventType org.si.sion.events.SiONEvent.FADE_OUT_COMPLETE */ 
     59    [Event(name="fadeOutComplete", type="org.si.sion.events.SiONEvent")] 
     60    /** @eventType org.si.sion.events.SiONTrackEvent.NOTE_ON_STREAM */ 
     61    [Event(name="noteOnStream",    type="org.si.sion.events.SiONTrackEvent")] 
     62    /** @eventType org.si.sion.events.SiONTrackEvent.NOTE_OFF_STREAM */ 
     63    [Event(name="noteOffStream",   type="org.si.sion.events.SiONTrackEvent")] 
     64    /** @eventType org.si.sion.events.SiONTrackEvent.NOTE_ON_FRAME */ 
     65    [Event(name="noteOnFrame",     type="org.si.sion.events.SiONTrackEvent")] 
     66    /** @eventType org.si.sion.events.SiONTrackEvent.NOTE_OFF_FRAME */ 
     67    [Event(name="noteOffFrame",    type="org.si.sion.events.SiONTrackEvent")] 
     68    /** @eventType org.si.sion.events.SiONTrackEvent.BEAT */ 
     69    [Event(name="beat",            type="org.si.sion.events.SiONTrackEvent")] 
     70    /** @eventType org.si.sion.events.SiONTrackEvent.CHANGE_BPM */ 
     71    [Event(name="changeBPM",       type="org.si.sion.events.SiONTrackEvent")] 
    3772     
    3873     
     
    568603                    _soundChannel = _sound.play(); 
    569604                    _soundChannel.soundTransform = _soundTransform; 
     605                    _process_addAllEventListners(); 
    570606                } 
    571607            } catch(e:Error) { 
     
    12231259             
    12241260            // processing 
    1225             sequencer.process(); 
    1226             effector._process(); 
    1227             module.limitLevel(); 
     1261            module._beginProcess(); 
     1262            effector._beginProcess(); 
     1263            sequencer._process(); 
     1264            effector._endProcess(); 
     1265            module._endProcess(); 
    12281266             
    12291267            // limit rendering length 
     
    12761314            module.initialize(_channelCount, _bufferLength); 
    12771315            module.reset();                                                 // reset channels 
    1278             sequencer.prepareProcess(_data, _sampleRate, _bufferLength);    // set track channels (this must be called after module.reset()). 
     1316            sequencer._prepareProcess(_data, _sampleRate, _bufferLength);   // set track channels (this must be called after module.reset()). 
    12791317            if (_data) _parseSystemCommand(_data.systemCommands);           // parse #EFFECT (initialize effector inside) 
    12801318            effector._prepareProcess();                                     // set stream number inside 
     
    13021340            _prevFrameTime = t; 
    13031341             
    1304             // preserve stop 
    1305             if (_preserveStop) stop(); 
    1306              
    1307             // frame trigger 
    1308             if (_trackEventQueue.length > 0) { 
    1309                 _trackEventQueue = _trackEventQueue.filter(function(e:SiONTrackEvent, i:int, v:Vector.<SiONTrackEvent>) : Boolean { 
    1310                     if (e._decrementTimer(_frameRate)) { 
    1311                         dispatchEvent(e); 
    1312                         return false; 
    1313                     } 
    1314                     return true; 
    1315                 }); 
     1342            // first streaming 
     1343            if (_isFirstStreaming) { 
     1344                _firstStream(); 
     1345            } else { 
     1346                // preserve stop 
     1347                if (_preserveStop) stop(); 
     1348 
     1349                // frame trigger 
     1350                if (_trackEventQueue.length > 0) { 
     1351                    _trackEventQueue = _trackEventQueue.filter(function(e:SiONTrackEvent, i:int, v:Vector.<SiONTrackEvent>) : Boolean { 
     1352                        if (e._decrementTimer(_frameRate)) { 
     1353                            dispatchEvent(e); 
     1354                            return false; 
     1355                        } 
     1356                        return true; 
     1357                    }); 
     1358                } 
    13161359            } 
    13171360        } 
     
    13331376                _inStreaming = true; 
    13341377                 
    1335                 if (_isFirstStreaming) _firstStream(e.data);  // first streaming 
    1336                 else if (_isPaused) _fillzero(e.data);        // paused 
    1337                 else { 
     1378                if (_isPaused || _isFirstStreaming) { 
     1379                    _fillzero(e.data); 
     1380                } else { 
    13381381                    var t:int = getTimer(); 
     1382                     
    13391383                    // processing 
    1340                     sequencer.process(); 
    1341                     effector._process(); 
    1342                     module.limitLevel(); 
     1384                    module._beginProcess(); 
     1385                    effector._beginProcess(); 
     1386                    sequencer._process(); 
     1387                    effector._endProcess(); 
     1388                    module._endProcess(); 
    13431389                     
    13441390                    // calculate the average of processing time 
     
    13971443         
    13981444        // first streaming 
    1399         private function _firstStream(buffer:ByteArray) : void { 
     1445        private function _firstStream() : void { 
    14001446            _isFirstStreaming = false; 
    14011447             
    1402             // start enter frame event 
    1403             _process_addAllEventListners(); 
    1404              
    14051448            // dispatch streaming start event 
    1406             var event:SiONEvent = new SiONEvent(SiONEvent.STREAM_START, this, buffer, true); 
     1449            var event:SiONEvent = new SiONEvent(SiONEvent.STREAM_START, this, null, true); 
    14071450            dispatchEvent(event); 
    14081451            if (event.isDefaultPrevented()) stop();   // canceled 
    1409              
    1410             _fillzero(buffer); 
    14111452        } 
    14121453         
  • as3/SiOPM/trunk/src/org/si/sion/effector/SiEffectBase.as

    r3196 r3480  
    5050         
    5151        /** Process effect to stream buffer. The system calls this to process. 
    52          *  @param channels Stream channel count. 1=monoral(same data on buffer[i] ans buffer[i+1]). 2=stereo. 
    53          *  @param buffer Stream buffer to apply effect. This is standard stereo stream buffer like [L0,R0,L1,R1,L2,R2 ... ]. 
    54          *  @param startIndex startIndex to apply effect. You CANNOT use this index to the stream buffer directly. Should be x2 because its a stereo stream. 
    55          *  @param length length to apply effect. You CANNOT use this length to the stream buffer directly. Should be x2 because its a stereo stream. 
     52         *  @param channels Stream channel count. 1=monoral(same data in buffer[i*2] and buffer[i*2+1]). 2=stereo. 
     53         *  @param buffer Stream buffer to apply effect. The order is same as wave format [L0,R0,L1,R1,L2,R2 ... ]. 
     54         *  @param startIndex startIndex to apply effect. You CANNOT use this index to the stream buffer directly. Should be doubled because its a stereo stream. 
     55         *  @param length length to apply effect. You CANNOT use this length to the stream buffer directly. Should be doubled because its a stereo stream. 
    5656         *  @return output channels count. 
    5757         */ 
  • as3/SiOPM/trunk/src/org/si/sion/effector/SiEffectCompressor.as

    r2625 r3480  
    1818        private var _windowRMSTotal:Number; 
    1919        private var _windwoRMSAveraging:Number; 
    20         private var _thres:Number;  // threshold 
    21         private var _slope:Number;  // slope angle 
     20        private var _threshold2:Number; // threshold^2 
    2221        private var _attRate:Number;    // attack rate  (per sample decay) 
    2322        private var _relRate:Number;    // release rate (per sample decay) 
     23        private var _maxGain:Number;    // max gain 
     24        private var _gain:Number;       // gain 
    2425         
    2526         
     
    3839        /** set parameters. 
    3940         *  @param thres threshold(0-1). 
    40          *  @param slope slope(0-1). 
    4141         *  @param wndTime window to calculate gain[ms]. 
    42          *  @param attTime attack [ms]. 
    43          *  @param relTime release [ms]. 
     42         *  @param attTime attack time [ms/6db]. 
     43         *  @param relTime release time [ms/-6db]. 
     44         *  @param maxGain max gain [db]. 
    4445         */ 
    45         public function setParameters(thres:Number=0.5, slope:Number=0.5, wndTime:Number=50, attTime:Number=20, relTime:Number=20) : void { 
    46             _thres = thres; 
    47             _slope = slope; 
     46        public function setParameters(thres:Number=0.7, wndTime:Number=50, attTime:Number=20, relTime:Number=20, maxGain:Number=-6) : void { 
     47            _threshold2 = thres*thres; 
    4848            _windowSamples = int(wndTime * 44.1); 
    4949            _windwoRMSAveraging = 1/_windowSamples; 
    50             _attRate = (attTime == 0) ? 0 : Math.exp(-1.0 / (attTime * 44.1)); 
    51             _relRate = (relTime == 0) ? 0 : Math.exp(-1.0 / (relTime * 44.1)); 
     50            _attRate = (attTime == 0) ? 0.5 : (Math.pow(2, -1/(attTime * 44.1))); 
     51            _relRate = (relTime == 0) ? 2.0 : (Math.pow(2,  1/(relTime * 44.1))); 
     52            _maxGain = Math.pow(2, -maxGain/6); 
    5253        } 
    5354         
     
    6768        override public function mmlCallback(args:Vector.<Number>) : void 
    6869        { 
    69             setParameters((!isNaN(args[0])) ? args[0]*0.01 : 0.5
    70                           (!isNaN(args[0])) ? args[0]*0.01 : 0.5
    71                           (!isNaN(args[0])) ? args[0] : 50, 
    72                           (!isNaN(args[0])) ? args[0] : 20, 
    73                           (!isNaN(args[0])) ? args[0] : 20); 
     70            setParameters((!isNaN(args[0])) ? args[0]*0.01 : 0.7
     71                          (!isNaN(args[1])) ? args[1] : 50
     72                          (!isNaN(args[2])) ? args[2] : 20, 
     73                          (!isNaN(args[3])) ? args[3] : 20, 
     74                          (!isNaN(args[4])) ? -args[4] : -6); 
    7475        } 
    7576         
     
    8182            _windowRMSList = SLLNumber.allocRing(_windowSamples); 
    8283            _windowRMSTotal = 0; 
     84            _gain = 2; 
    8385            return 2; 
    8486        } 
     
    9294             
    9395            var i:int, imax:int = startIndex + length; 
    94             var l:Number, r:Number, rms:Number, dt:Number, gain:Number, env:Number; 
    95             env = 0; 
    96             gain = 1; 
     96            var l:Number, r:Number, rms2:Number; 
    9797            for (i=startIndex; i<imax; i+=2) { 
    9898                l = buffer[i]; 
     
    102102                _windowRMSList.n = l * l + r * r; 
    103103                _windowRMSTotal  += _windowRMSList.n; 
    104                 rms = Math.sqrt(_windowRMSTotal * _windwoRMSAveraging); 
     104                rms2 = _windowRMSTotal * _windwoRMSAveraging; 
     105                _gain *= (rms2 > _threshold2) ? _attRate : _relRate; 
     106                if (_gain > _maxGain) _gain = _maxGain; 
    105107 
    106                 dt = (rms > env) ? _attRate : _relRate; 
    107                 env = (1 - dt) * rms + dt * env; 
    108  
    109                 if (env > _thres) gain = gain - (env - _thres) * _slope; 
    110  
    111                 l *= gain; 
    112                 r *= gain; 
     108                l *= _gain; 
     109                r *= _gain; 
    113110                l = (l>1) ? 1 : (l<-1) ? -1 : l; 
    114111                r = (r>1) ? 1 : (r<-1) ? -1 : r; 
  • as3/SiOPM/trunk/src/org/si/sion/effector/SiEffectModule.as

    r3196 r3480  
    1414    public class SiEffectModule 
    1515    { 
     16    // constant 
     17    //-------------------------------------------------------------------------------- 
     18         
     19         
     20         
    1621    // valiables 
    1722    //-------------------------------------------------------------------------------- 
    1823        private var _module:SiOPMModule; 
    19         private var _effectConnectors:Vector.<SiEffectConnector>; 
    20         private var _slotCount:int; 
     24        private var _freeEffects:Vector.<SiEffectStream>; 
     25        private var _localEffects:Vector.<SiEffectStream>; 
     26        private var _globalEffects:Vector.<SiEffectStream>; 
     27        private var _masterEffect:SiEffectStream; 
     28        private var _globalEffectCount:int; 
    2129        static private var _effectorInstances:* = {}; 
    2230         
     
    3038        { 
    3139            _module = module; 
    32             _effectConnectors = new Vector.<SiEffectConnector>(SiOPMModule.STREAM_SIZE_MAX); 
    33             for (var i:int=0; i<SiOPMModule.STREAM_SIZE_MAX; i++) { 
    34                 _effectConnectors[i] = new SiEffectConnector(); 
    35             } 
    36             _slotCount = 1; 
     40            _freeEffects   = new Vector.<SiEffectStream>(); 
     41            _localEffects  = new Vector.<SiEffectStream>(); 
     42            _globalEffects = new Vector.<SiEffectStream>(SiOPMModule.STREAM_SEND_SIZE, true); 
     43            _masterEffect  = new SiEffectStream(_module, _module.outputStream); 
    3744 
    3845            // initialize table 
     
    4855            register("ds",      SiEffectDownSampler); 
    4956            register("speaker", SiEffectSpeakerSimulator); 
    50             register("comp",    SiEffectCompressor); // bugful!! 
     57            register("comp",    SiEffectCompressor); 
    5158             
    5259            register("lf", SiFilterLowPass); 
     
    6774    //-------------------------------------------------------------------------------- 
    6875        /** Initialize all effectors. This function is called from SiONDriver.play() with the 2nd argment true.  
    69         *  When you want to connect effectors by code, you have to call this first, then call connect() and SiONDriver.play() with the 2nd argment false. 
     76        *  When you want to connect effectors by code, you have to call this first, then call connect() and SiONDriver.play() with the 2nd argment false. 
    7077         */ 
    7178        public function initialize() : void 
    7279        { 
    73             for (var slot:int=0; slot<SiOPMModule.STREAM_SIZE_MAX; slot++) { 
    74                 _effectConnectors[slot].clear(); 
    75             } 
     80            var effect:SiEffectStream, i:int; 
     81            for each (effect in _localEffects) _freeEffects.push(effect); 
     82            _localEffects.length = 0; 
     83            _globalEffects[0] = _masterEffect; 
     84            for (i=1; i<SiOPMModule.STREAM_SEND_SIZE; i++) _globalEffects[i] = null; 
     85            _globalEffectCount = 0; 
     86        } 
     87         
     88         
     89        public function reset() : void 
     90        { 
    7691        } 
    7792         
     
    8095        _sion_internal function _prepareProcess() : void 
    8196        { 
    82             var i:int, slot:int; 
    83              
    84             // preparetion for all effectors 
    85             _slotCount = 1; 
    86             for (slot=0; slot<SiOPMModule.STREAM_SIZE_MAX; slot++) { 
    87                 if (_effectConnectors[slot].prepareProcess() > 0) _slotCount = slot+1; 
    88             } 
    89              
    90             // set modules number of streams and channels 
    91             _module.streamCount = _slotCount; 
    92             for (slot=1; slot<_slotCount; slot++) { 
    93                 _module.streamBuffer[slot].channels = _effectConnectors[slot].requestChannels; 
    94             } 
     97            var slot:int, channelCount:int; 
     98             
     99            // local effect 
     100            for (slot=0; slot<_localEffects.length; slot++) { 
     101                _localEffects[slot].prepareProcess(); 
     102            } 
     103             
     104            // global effect (slot1-slot7) 
     105            _globalEffectCount = 0; 
     106            for (slot=1; slot<SiOPMModule.STREAM_SEND_SIZE; slot++) { 
     107                _module.streamSlot[slot] = null; // reset module's stream slot 
     108                if (_globalEffects[slot]) { 
     109                    channelCount = _globalEffects[slot].prepareProcess(); 
     110                    if (channelCount > 0) { 
     111                        _module.streamSlot[slot] = _globalEffects[slot]._stream; 
     112                        _globalEffectCount++; 
     113                    } 
     114                } 
     115            } 
     116             
     117            // master effect (slot0) 
     118            _masterEffect.prepareProcess(); 
     119        } 
     120         
     121         
     122        /** @private [sion internal] Clear output buffer. */ 
     123        _sion_internal function _beginProcess() : void 
     124        { 
     125            var slot:int; 
     126             
     127            // local effect 
     128            for (slot=0; slot<_localEffects.length; slot++) { 
     129                _localEffects[slot]._stream.clear(); 
     130            } 
     131             
     132            // global effect (slot1-slot7) 
     133            for (slot=1; slot<SiOPMModule.STREAM_SEND_SIZE; slot++) { 
     134                if (_globalEffects[slot]) _globalEffects[slot]._stream.clear(); 
     135            } 
     136             
     137            // do nothing on master effect 
    95138        } 
    96139         
    97140         
    98141        /** @private [sion internal] processing. */ 
    99         _sion_internal function _process() : void 
    100         { 
    101             var i:int, slot:int, buffer:Vector.<Number>, ec:SiEffectConnector, 
     142        _sion_internal function _endProcess() : void 
     143        { 
     144            var i:int, slot:int, buffer:Vector.<Number>, 
    102145                bufferLength:int = _module.bufferLength, 
    103146                output:Vector.<Number> = _module.output, 
    104147                imax:int = output.length; 
    105             // effect 
    106             for (slot=1; slot<_slotCount; slot++) { 
    107                 ec = _effectConnectors[slot]; 
    108                 if (ec.isActive) { 
    109                     buffer = _module.streamBuffer[slot].buffer; 
    110                     ec.process(_module.streamBuffer[slot].channels, buffer, 0, bufferLength); 
     148             
     149            // local effect 
     150            for (slot=0; slot<_localEffects.length; slot++) { 
     151                _localEffects[slot].process(0, bufferLength); 
     152            } 
     153             
     154            // global effect (slot1-slot7) 
     155            for (slot=1; slot<SiOPMModule.STREAM_SEND_SIZE; slot++) { 
     156                if (_globalEffects[slot]) { 
     157                    _globalEffects[slot].process(0, bufferLength, false); 
    111158                    for (i=0; i<imax; i++) output[i] += buffer[i]; 
    112159                } 
    113160            } 
    114             // master effect 
    115             ec = _effectConnectors[0]; 
    116             if (ec.isActive) ec.process(_module.channelCount, output, 0, bufferLength); 
     161             
     162            // master effect (slot0) 
     163            _masterEffect.process(0, bufferLength, false); 
    117164        } 
    118165         
     
    166213        public function clear(slot:int) : void 
    167214        { 
    168             _effectConnectors[slot].clear(); 
     215            if (slot == 0) { 
     216                _masterEffect.initialize(); 
     217            } else { 
     218                if (_globalEffects[slot] != null) _freeEffects.push(_globalEffects[slot]); 
     219                _globalEffects[slot] = null; 
     220            } 
    169221        } 
    170222         
     
    176228        public function connect(slot:int, effector:SiEffectBase) : void 
    177229        { 
    178             _effectConnectors[slot].connect(effector); 
     230            if (_globalEffects[slot] == null) _globalEffects[slot] = _allocStream(); 
     231            _globalEffects[slot].connect(effector); 
    179232        } 
    180233         
     
    187240        public function parseMML(slot:int, mml:String, postfix:String) : void 
    188241        { 
    189             _effectConnectors[slot].parseMML(mml, postfix); 
     242            if (_globalEffects[slot] == null) _globalEffects[slot] = _allocStream(); 
     243            _globalEffects[slot].parseMML(mml, postfix); 
    190244        } 
    191245         
     
    198252        public function getEffector(slot:int, index:int) : SiEffectBase  
    199253        { 
    200             return _effectConnectors[slot].getEffector(index); 
     254            if (_globalEffects[slot] == null) return null; 
     255            return _globalEffects[slot].getEffector(index); 
     256        } 
     257         
     258         
     259        /** Create new local effector connector */ 
     260        public function newLocalEffect() : SiEffectStream 
     261        { 
     262            var inst:SiEffectStream = _allocStream(); 
     263            _localEffects.push(inst); 
     264            return inst; 
     265        } 
     266         
     267         
     268        /** Delete local effector connector */ 
     269        public function deleteLocalEffect(inst:SiEffectStream) : void 
     270        { 
     271            var i:int = _localEffects.indexOf(inst); 
     272            if (i != -1) _localEffects.splice(i, 0); 
     273            _freeEffects.push(inst); 
     274        } 
     275         
     276         
     277         
     278         
     279    // functory 
     280    //-------------------------------------------------------------------------------- 
     281        private function _allocStream() : SiEffectStream 
     282        { 
     283            var inst:SiEffectStream = _freeEffects.pop() || new SiEffectStream(_module); 
     284            inst.initialize(); 
     285            return inst; 
    201286        } 
    202287    } 
  • as3/SiOPM/trunk/src/org/si/sion/module/SiOPMChannelParam.as

    r3450 r3480  
    8484        { 
    8585            initSequence = new MMLSequence(); 
    86             volumes = new Vector.<Number>(SiOPMModule.STREAM_SIZE_MAX, true); 
     86            volumes = new Vector.<Number>(SiOPMModule.STREAM_SEND_SIZE, true); 
    8787 
    8888            operatorParam = new Vector.<SiOPMOperatorParam>(4); 
     
    110110            pmd = 0; 
    111111            fratio = 100; 
    112             for (i=1; i<SiOPMModule.STREAM_SIZE_MAX; i++) { volumes[i] = 0; } 
     112            for (i=1; i<SiOPMModule.STREAM_SEND_SIZE; i++) { volumes[i] = 0; } 
    113113            volumes[0] = 0.5; 
    114114            pan = 64; 
     
    148148            pmd = org.pmd; 
    149149            fratio = org.fratio; 
    150             for (i=0; i<SiOPMModule.STREAM_SIZE_MAX; i++) { volumes[i] = org.volumes[i]; } 
     150            for (i=0; i<SiOPMModule.STREAM_SEND_SIZE; i++) { volumes[i] = org.volumes[i]; } 
    151151            pan = org.pan; 
    152152             
  • as3/SiOPM/trunk/src/org/si/sion/module/SiOPMModule.as

    r3450 r3480  
    11//---------------------------------------------------------------------------------------------------- 
    2 // FM sound module based on OPM emulator and TSS algorism. 
     2// SiOPM sound module  
    33//  Copyright (c) 2008 keim All rights reserved. 
    44//  Distributed under BSD-style license (see org.si.license.txt). 
     
    99    import org.si.utils.SLLint; 
    1010    import org.si.sion.module.channels.*; 
     11    import org.si.sion.namespaces._sion_internal; 
    1112     
    1213     
    13     /** FM sound module based on OPM emulator and TSS algorism. */ 
     14    /** SiOPM sound module */ 
    1415    public class SiOPMModule 
    1516    { 
    1617    // constants 
    1718    //-------------------------------------------------- 
    18         /** maximum value of stream buffer size */ 
    19         static public const STREAM_SIZE_MAX:int = 8; 
     19        /** size of stream send */ 
     20        static public const STREAM_SEND_SIZE:int = 8; 
    2021        /** pipe size */ 
    2122        static public const PIPE_SIZE:int = 5; 
     
    3031        /** zero buffer */ 
    3132        public var zeroBuffer:SLLint; 
    32         /** stereo output buffer */ 
    33         public var streamBuffer:Vector.<SiOPMStream>; 
     33        /** output stream */ 
     34        public var outputStream:SiOPMStream; 
     35        /** slot of global mixer */ 
     36        public var streamSlot:Vector.<SiOPMStream>; 
    3437         
    3538        // buffer length 
     
    4447    //-------------------------------------------------- 
    4548        /** Buffer count */ 
    46         public function get output() : Vector.<Number> { return streamBuffer[0].buffer; } 
     49        public function get output() : Vector.<Number> { return outputStream.buffer; } 
    4750        /** Buffer channel count */ 
    48         public function get channelCount() : int { return streamBuffer[0].channels; } 
     51        public function get channelCount() : int { return outputStream.channels; } 
    4952        /** Buffer length */ 
    5053        public function get bufferLength() : int { return _bufferLength; } 
    51          
    52          
    53         /** stream buffer count */ 
    54         public function set streamCount(count:int) : void { 
    55             var i:int; 
    56              
    57             // allocate streams 
    58             if (count > STREAM_SIZE_MAX) count = STREAM_SIZE_MAX; 
    59             else if (count < 1) count = 1; 
    60             if (streamBuffer.length != count) { 
    61                 if (streamBuffer.length < count) { 
    62                     i = streamBuffer.length; 
    63                     streamBuffer.length = count; 
    64                     for (; i<count; i++) streamBuffer[i] = SiOPMStream.newStream(2, _bufferLength); 
    65                 } else { 
    66                     for (i=count; i<streamBuffer.length; i++) SiOPMStream.deleteStream(streamBuffer[i]); 
    67                     streamBuffer.length = count; 
    68                 } 
    69             } 
    70         } 
    71         public function get streamCount() : int { return streamBuffer.length; } 
    7254         
    7355         
     
    8870             
    8971            // stream buffer 
    90             streamBuffer = new Vector.<SiOPMStream>(); 
    91             streamCount = 1
     72            outputStream = new SiOPMStream(); 
     73            streamSlot = new Vector.<SiOPMStream>(STREAM_SEND_SIZE, true)
    9274 
    9375            // zero buffer gives always 0 
     
    11496        public function initialize(channelCount:int, bufferLength:int) : void 
    11597        { 
    116             var i:int, stream:SiOPMStream, bufferLength2:int = bufferLength<<1
     98            var i:int, stream:SiOPMStream
    11799 
     100            // reset stream slot 
     101            for (i=0; i<STREAM_SEND_SIZE; i++) streamSlot[i] = null; 
     102            streamSlot[0] = outputStream; 
     103             
    118104            // reallocate buffer 
    119105            if (_bufferLength != bufferLength) { 
    120106                _bufferLength = bufferLength; 
    121                 for each (stream in streamBuffer) { 
    122                     stream.buffer.length = bufferLength2; 
    123                 } 
     107                outputStream.buffer.length = bufferLength<<1; 
    124108                for (i=0; i<PIPE_SIZE; i++) { 
    125109                    SLLint.freeRing(_pipeBuffer[i]); 
     
    128112                } 
    129113            } 
    130  
    131             // set standard outputs channel count 
    132             streamBuffer[0].channels = channelCount; 
    133114             
    134115            // initialize all channels 
     
    145126         
    146127         
    147         /** Clear all buffer. */ 
    148         public function clearAllBuffers() : void 
     128        /** @private [sion internal] Clear output buffer. */ 
     129        _sion_internal function _beginProcess() : void 
    149130        { 
    150             var idx:int, i:int, imax:int, buf:Vector.<Number>, stream:SiOPMStream; 
    151             for each (stream in streamBuffer) { 
    152                 buf = stream.buffer; 
    153                 imax = buf.length; 
    154                 for (i=0; i<imax; i++) buf[i] = 0; 
    155             } 
     131            outputStream.clear(); 
    156132        } 
    157133         
    158134         
    159         /** Limit output level in the ranged of -1 ~ 1.*/ 
    160         public function limitLevel() : void 
     135        /** @private [sion internal] Limit output level in the ranged between -1 ~ 1.*/ 
     136        _sion_internal function _endProcess() : void 
    161137        { 
    162             var buf:Vector.<Number> = streamBuffer[0].buffer, 
    163                 i:int, imax:int = buf.length, n:Number; 
    164             for (i=0; i<imax; i++) { 
    165                 n = buf[i]; 
    166                 if (n < -1) buf[i] = -1; 
    167                 else if (n > 1) buf[i] = 1; 
    168             } 
     138            outputStream.limit(); 
    169139        } 
    170140         
  • as3/SiOPM/trunk/src/org/si/sion/module/SiOPMStream.as

    r3450 r3480  
    1919        public var buffer:Vector.<Number> = new Vector.<Number>(); 
    2020 
    21         /** coefficient of volume/panning */ 
    22         protected var _panTable:Vector.<Number>; 
    23         protected var _i2n:Number; 
     21        // coefficient of volume/panning 
     22        private var _panTable:Vector.<Number>; 
     23        private var _i2n:Number; 
    2424 
    2525         
     
    4040        // operation 
    4141        //-------------------------------------------------- 
     42        /** clear buffer */ 
     43        public function clear() : void 
     44        { 
     45            var i:int, imax:int = buffer.length; 
     46            for (i=0; i<imax; i++) { 
     47                buffer[i] = 0; 
     48            } 
     49        } 
     50         
     51         
     52        /** limit buffered signals between -1 and 1 */ 
     53        public function limit() : void 
     54        { 
     55            var n:Number, i:int, imax:int = buffer.length; 
     56            for (i=0; i<imax; i++) { 
     57                n = buffer[i]; 
     58                     if (n < -1) buffer[i] = -1; 
     59                else if (n >  1) buffer[i] =  1; 
     60            } 
     61        } 
     62         
     63         
    4264        /** write buffer by org.si.utils.SLLint */ 
    4365        public function write(pointer:SLLint, start:int, len:int, vol:Number, pan:int) : void  
     
    140162            bytes.position = initPosition; 
    141163        } 
    142          
    143          
    144          
    145          
    146         // factory 
    147         //-------------------------------------------------- 
    148         static private var freeBuffers:Vector.<SiOPMStream> = new Vector.<SiOPMStream>(); 
    149          
    150          
    151         /** create new stream buffer */ 
    152         static public function newStream(channels:int, bufferLength:int) : SiOPMStream 
    153         { 
    154             bufferLength <<= 1; 
    155             var stream:SiOPMStream = freeBuffers.pop() || new SiOPMStream(); 
    156             stream.channels = channels; 
    157             stream.buffer.length = bufferLength; 
    158             return stream; 
    159         } 
    160          
    161          
    162         /** delete stream buffer */ 
    163         static public function deleteStream(stream:SiOPMStream) : void 
    164         { 
    165             freeBuffers.push(stream); 
    166         } 
    167164    } 
    168165} 
  • as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMChannelBase.as

    r3450 r3480  
    5959        /** out pipe */         protected var _outPipe :SLLint; 
    6060         
    61         // Volume 
     61        // volume and stream 
     62        /** stream */           protected var _streams:Vector.<SiOPMStream>; 
     63        /** volume */           protected var _volumes:Vector.<Number>; 
    6264        /** idling flag */      protected var _isIdling:Boolean; 
    63         /** volume */           protected var _volume:Vector.<Number>; 
    6465        /** pan */              protected var _pan:int; 
    6566        /** effect send flag */ protected var _hasEffectSend:Boolean; 
     
    102103            _isFree = true; 
    103104             
    104             _volume = new Vector.<Number>(SiOPMModule.STREAM_SIZE_MAX, true); 
     105            _streams = new Vector.<SiOPMStream>(SiOPMModule.STREAM_SEND_SIZE, true); 
     106            _volumes = new Vector.<Number>(SiOPMModule.STREAM_SEND_SIZE, true); 
    105107            _filter_eg_time   = new Vector.<int>(6, true); 
    106108            _filter_eg_cutoff = new Vector.<int>(6, true); 
     
    135137         
    136138        /** Master volume (0-128) */ 
    137         public function get masterVolume() : int { return _volume[0]*128; } 
     139        public function get masterVolume() : int { return _volumes[0]*128; } 
    138140        public function set masterVolume(v:int) : void { 
    139141            v = (v<0) ? 0 : (v>128) ? 128 : v; 
    140             _volume[0] = v * 0.0078125;     // 0.0078125 = 1/128 
     142            _volumes[0] = v * 0.0078125;     // 0.0078125 = 1/128 
    141143        } 
    142144         
     
    194196    // volume control 
    195197    //-------------------------------------------------- 
    196         /** set all stream send levels by Vector.<int>. */ 
     198        /** set all stream send levels by Vector.<int>. 
     199         *  @param param Vector.<int>(8) of all volumes[0-128]. 
     200         */ 
    197201        public function setAllStreamSendLevels(param:Vector.<int>) : void 
    198202        { 
    199             var i:int, imax:int = SiOPMModule.STREAM_SIZE_MAX, v:int; 
     203            var i:int, imax:int = SiOPMModule.STREAM_SEND_SIZE, v:int; 
    200204            for (i=0; i<imax; i++) { 
    201205                v = param[i]; 
    202                 _volume[i] = (v != int.MIN_VALUE) ? (v * 0.0078125) : 0; 
     206                _volumes[i] = (v != int.MIN_VALUE) ? (v * 0.0078125) : 0; 
    203207            } 
    204208            for (_hasEffectSend=false, i=1; i<imax; i++) { 
    205                 if (_volume[i] > 0) _hasEffectSend = true; 
    206             } 
     209                if (_volumes[i] > 0) _hasEffectSend = true; 
     210            } 
     211        } 
     212         
     213         
     214        /** set stream buffer. 
     215         *  @param streamNum stream number[0-7]. The streamNum of 0 means master stream. 
     216         *  @param stream stream buffer instance. Set null to set as default. 
     217         */ 
     218        public function setStreamBuffer(streamNum:int, stream:SiOPMStream = null) : void 
     219        { 
     220            _streams[streamNum] = stream; 
    207221        } 
    208222         
     
    214228        public function setStreamSend(streamNum:int, volume:Number) : void 
    215229        { 
    216             _volume[streamNum] = volume; 
     230            _volumes[streamNum] = volume; 
    217231            if (streamNum == 0) return; 
    218232            if (volume > 0) _hasEffectSend = true; 
    219233            else { 
    220                 var i:int, imax:int = SiOPMModule.STREAM_SIZE_MAX
     234                var i:int, imax:int = SiOPMModule.STREAM_SEND_SIZE
    221235                for (_hasEffectSend=false, i=1; i<imax; i++) { 
    222                     if (_volume[i] > 0) _hasEffectSend = true; 
     236                    if (_volumes[i] > 0) _hasEffectSend = true; 
    223237                } 
    224238            } 
    225239        } 
     240         
    226241 
    227242        /** get stream send. 
     
    231246        public function getStreamSend(streamNum:int) : Number 
    232247        { 
    233             return _volume[streamNum]; 
     248            return _volumes[streamNum]; 
    234249        }         
    235250         
     
    420435        { 
    421436            // volume 
    422             var i:int, imax:int = SiOPMModule.STREAM_SIZE_MAX
     437            var i:int, imax:int = SiOPMModule.STREAM_SEND_SIZE
    423438            if (prev) { 
    424                 for (i=0; i<imax; i++) _volume[i] = prev._volume[i]; 
     439                for (i=0; i<imax; i++) { 
     440                    _volumes[i] = prev._volumes[i]; 
     441                    _streams[i] = prev._streams[i]; 
     442                } 
    425443                _pan = prev._pan; 
    426444                _hasEffectSend = prev._hasEffectSend; 
    427445                _mute = prev._mute; 
    428446            } else { 
    429                 _volume[0] = 0.5; 
    430                 for (i=1; i<imax; i++) _volume[i] = 0; 
     447                _volumes[0] = 0.5; 
     448                _streams[0] = null; 
     449                for (i=1; i<imax; i++) { 
     450                    _volumes[i] = 0; 
     451                    _streams[i] = null; 
     452                } 
    431453                _pan = 64; 
    432454                _hasEffectSend = false; 
     
    516538        public function buffer(len:int) : void 
    517539        { 
     540            var i:int, stream:SiOPMStream; 
     541             
    518542            if (_isIdling) { 
    519543                // idling process 
     
    533557                if (_outputMode == OUTPUT_STANDARD && !_mute) { 
    534558                    if (_hasEffectSend) { 
    535                         var i:int, imax:int = _chip.streamCount; 
    536                         for (i=0; i<imax; i++) { 
    537                             if (_volume[i]>0) _chip.streamBuffer[i].write(monoOut, _bufferIndex, len, _volume[i], _pan); 
     559                        for (i=0; i<SiOPMModule.STREAM_SEND_SIZE; i++) { 
     560                            if (_volumes[i]>0) { 
     561                                stream = _streams[i] || _chip.streamSlot[i]; 
     562                                if (stream) stream.write(monoOut, _bufferIndex, len, _volumes[i], _pan); 
     563                            } 
    538564                        } 
    539565                    } else { 
    540                         _chip.streamBuffer[0].write(monoOut, _bufferIndex, len, _volume[0], _pan); 
     566                        stream = _streams[0] || _chip.outputStream; 
     567                        stream.write(monoOut, _bufferIndex, len, _volumes[0], _pan); 
    541568                    } 
    542569                } 
  • as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMChannelFM.as

    r3450 r3480  
    9090            str += String(_operatorCount) + "\n"; 
    9191            $("fb ", _inputLevel-6); 
    92             $2("vol", _volume[0],  "pan", _pan-64); 
     92            $2("vol", _volumes[0],  "pan", _pan-64); 
    9393            if (operator[0]) str += String(operator[0]) + "\n"; 
    9494            if (operator[1]) str += String(operator[1]) + "\n"; 
     
    219219             
    220220            if (withVolume) { 
    221                 var imax:int = SiOPMModule.STREAM_SIZE_MAX
    222                 for (i=0; i<imax; i++) _volume[i] = param.volumes[i]; 
    223                 for (_hasEffectSend=false, i=1; i<imax; i++) if (_volume[i] > 0) _hasEffectSend = true; 
     221                var imax:int = SiOPMModule.STREAM_SEND_SIZE
     222                for (i=0; i<imax; i++) _volumes[i] = param.volumes[i]; 
     223                for (_hasEffectSend=false, i=1; i<imax; i++) if (_volumes[i] > 0) _hasEffectSend = true; 
    224224                _pan = param.pan; 
    225225            } 
     
    244244        override public function getSiOPMChannelParam(param:SiOPMChannelParam) : void 
    245245        { 
    246             var i:int, imax:int = SiOPMModule.STREAM_SIZE_MAX
    247             for (i=0; i<imax; i++) param.volumes[i] = _volume[i]; 
     246            var i:int, imax:int = SiOPMModule.STREAM_SEND_SIZE
     247            for (i=0; i<imax; i++) param.volumes[i] = _volumes[i]; 
    248248            param.pan = _pan; 
    249249            param.fratio = _freq_ratio; 
  • as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMChannelKS.as

    r3450 r3480  
    5555            str += String(_operatorCount) + "\n"; 
    5656            $("fb ", _inputLevel-6); 
    57             $2("vol", _volume[0],  "pan", _pan-64); 
     57            $2("vol", _volumes[0],  "pan", _pan-64); 
    5858            if (operator[0]) str += String(operator[0]) + "\n"; 
    5959            if (operator[1]) str += String(operator[1]) + "\n"; 
     
    277277        override public function buffer(len:int) : void 
    278278        { 
     279            var i:int, stream:SiOPMStream; 
     280             
    279281            if (_isIdling) { 
    280282                // idling process 
     
    299301                if (_outputMode == OUTPUT_STANDARD && !_mute) { 
    300302                    if (_hasEffectSend) { 
    301                         var i:int, imax:int = _chip.streamCount; 
    302                         for (i=0; i<imax; i++) { 
    303                             if (_volume[i]>0) _chip.streamBuffer[i].write(monoOut, _bufferIndex, len, _volume[i]*_expression, _pan); 
     303                        for (i=0; i<SiOPMModule.STREAM_SEND_SIZE; i++) { 
     304                            if (_volumes[i]>0) { 
     305                                stream = _streams[i] || _chip.streamSlot[i]; 
     306                                if (stream) stream.write(monoOut, _bufferIndex, len, _volumes[i]*_expression, _pan); 
     307                            } 
    304308                        } 
    305309                    } else { 
    306                         _chip.streamBuffer[0].write(monoOut, _bufferIndex, len, _volume[0]*_expression, _pan); 
     310                        stream = _streams[0] || _chip.outputStream; 
     311                        stream.write(monoOut, _bufferIndex, len, _volumes[0]*_expression, _pan); 
    307312                    } 
    308313                } 
  • as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMChannelSampler.as

    r3450 r3480  
    3939        { 
    4040            var str:String = "SiOPMChannelSampler : "; 
    41             $2("vol", _volume[0]*_expression,  "pan", _pan-64); 
     41            $2("vol", _volumes[0]*_expression,  "pan", _pan-64); 
    4242            return str; 
    4343            function $2(p:String, i:*, q:String, j:*) : void { str += "  " + p + "=" + String(i) + " / " + q + "=" + String(j) + "\n"; } 
     
    7272             
    7373            if (withVolume) { 
    74                 var imax:int = SiOPMModule.STREAM_SIZE_MAX
    75                 for (i=0; i<imax; i++) _volume[i] = param.volumes[i]; 
    76                 for (_hasEffectSend=false, i=1; i<imax; i++) if (_volume[i] > 0) _hasEffectSend = true; 
     74                var imax:int = SiOPMModule.STREAM_SEND_SIZE
     75                for (i=0; i<imax; i++) _volumes[i] = param.volumes[i]; 
     76                for (_hasEffectSend=false, i=1; i<imax; i++) if (_volumes[i] > 0) _hasEffectSend = true; 
    7777                _pan = param.pan; 
    7878            } 
     
    8585        override public function getSiOPMChannelParam(param:SiOPMChannelParam) : void 
    8686        { 
    87             var i:int, imax:int = SiOPMModule.STREAM_SIZE_MAX
    88             for (i=0; i<imax; i++) param.volumes[i] = _volume[i]; 
     87            var i:int, imax:int = SiOPMModule.STREAM_SEND_SIZE
     88            for (i=0; i<imax; i++) param.volumes[i] = _volumes[i]; 
    8989            param.pan = _pan; 
    9090        } 
     
    202202        override public function buffer(len:int) : void 
    203203        { 
    204             var i:int, imax:int, vol:Number, residue:int, processed:int
     204            var i:int, imax:int, vol:Number, residue:int, processed:int, stream:SiOPMStream
    205205            if (_isIdling || _sampleData == null || _mute) { 
    206206                //_nop(len); 
     
    208208                if (_sampleData.isExtracted) { 
    209209                    // stream extracted data 
    210                     for (residue=len, i=0, imax=0; residue>0;) { 
     210                    for (residue=len, i=0; residue>0;) { 
    211211                        // copy to buffer 
    212212                        processed = (_sampleIndex + residue < _sampleData.endPoint) ? residue : (_sampleData.endPoint - _sampleIndex); 
    213213                        if (_hasEffectSend) { 
    214                             imax = _chip.streamCount; 
    215                             for (i=0; i<imax; i++) { 
    216                                 vol = _volume[i] * _expression; 
    217                                 if (vol > 0) _chip.streamBuffer[i].writeVectorNumber(_sampleData.waveData, _sampleIndex, _bufferIndex, processed, vol, _pan, _sampleData.channelCount); 
     214                            for (i=0; i<SiOPMModule.STREAM_SEND_SIZE; i++) { 
     215                                if (_volumes[i]>0) { 
     216                                    stream = _streams[i] || _chip.streamSlot[i]; 
     217                                    if (stream) { 
     218                                        vol = _volumes[i] * _expression; 
     219                                        stream.writeVectorNumber(_sampleData.waveData, _sampleIndex, _bufferIndex, processed, vol, _pan, _sampleData.channelCount); 
     220                                    } 
     221                                } 
    218222                            } 
    219223                        } else { 
    220                             vol = _volume[0] * _expression; 
    221                             _chip.streamBuffer[0].writeVectorNumber(_sampleData.waveData, _sampleIndex, _bufferIndex, processed, vol, _pan, _sampleData.channelCount); 
     224                            stream = _streams[0] || _chip.outputStream; 
     225                            vol = _volumes[0] * _expression; 
     226                            stream.writeVectorNumber(_sampleData.waveData, _sampleIndex, _bufferIndex, processed, vol, _pan, _sampleData.channelCount); 
    222227                        } 
    223228                        _sampleIndex += processed; 
     
    255260                    // copy to buffer 
    256261                    if (_hasEffectSend) { 
    257                         imax = _chip.streamCount; 
    258                         for (i=0; i<imax; i++) { 
    259                             vol = _volume[i] * _expression; 
    260                             if (vol > 0) _chip.streamBuffer[i].writeVectorNumber(_extractedSample, 0, _bufferIndex, processed, vol, _pan, _sampleData.channelCount); 
     262                        for (i=0; i<SiOPMModule.STREAM_SEND_SIZE; i++) { 
     263                            if (_volumes[i]>0) { 
     264                                stream = _streams[i] || _chip.streamSlot[i]; 
     265                                if (stream) { 
     266                                    vol = _volumes[i] * _expression; 
     267                                    stream.writeVectorNumber(_extractedSample, 0, _bufferIndex, processed, vol, _pan, _sampleData.channelCount); 
     268                                } 
     269                            } 
    261270                        } 
    262271                    } else { 
    263                         vol = _volume[0] * _expression; 
    264                         _chip.streamBuffer[0].writeVectorNumber(_extractedSample, 0, _bufferIndex, processed, vol, _pan, _sampleData.channelCount); 
     272                        stream = _streams[0] || _chip.outputStream; 
     273                        vol = _volumes[0] * _expression; 
     274                        stream.writeVectorNumber(_extractedSample, 0, _bufferIndex, processed, vol, _pan, _sampleData.channelCount); 
    265275                    } 
    266276                } 
  • as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMOperator.as

    r3450 r3480  
    501501            // fixed pitch 
    502502            if (param.fixedPitch == 0) { 
    503                 _pitchIndex = 3840; 
    504                 _updateKC(_table.nnToKC[(_pitchIndex>>6)&127]); 
     503                //_pitchIndex = 3840; 
     504                //_updateKC(_table.nnToKC[(_pitchIndex>>6)&127]); 
    505505                _pitchFixed = false; 
    506506            } else { 
  • as3/SiOPM/trunk/src/org/si/sion/sequencer/SiMMLSequencer.as

    r3450 r3480  
    88    import flash.system.System; 
    99    import org.si.utils.SLLint; 
    10     import org.si.sion.sequencer.base.*; 
    11     import org.si.sion.module.*; 
     10    import org.si.sion.sequencer.base.MMLData; 
     11    import org.si.sion.sequencer.base.MMLExecutorConnector; 
     12    import org.si.sion.sequencer.base.MMLSequencer; 
     13    import org.si.sion.sequencer.base.MMLEvent; 
     14    import org.si.sion.sequencer.base.MMLSequenceGroup; 
     15    import org.si.sion.sequencer.base.MMLSequence; 
     16    import org.si.sion.sequencer.base.MMLParser; 
     17    import org.si.sion.sequencer.base._sion_sequencer_internal; 
     18    import org.si.sion.module.SiOPMTable; 
     19    import org.si.sion.module.SiOPMModule; 
     20    import org.si.sion.module.SiOPMChannelParam; 
    1221    import org.si.sion.utils.Translator; 
    1322    import org.si.sion.namespaces._sion_internal; 
    14     import org.si.sion.sequencer.base._sion_sequencer_internal; 
    1523     
    1624     
     
    357365    // process 
    358366    //-------------------------------------------------- 
    359         /** Prepare to process audio. 
     367        /** @private [sion internal] Prepare to process audio. 
    360368         *  @param bufferLength Buffering length of processing samples at once. 
    361369         *  @param resetParams Reset all channel parameters. 
    362370         */ 
    363         override public function prepareProcess(data:MMLData, sampleRate:int, bufferLength:int) : void 
     371        override public function _prepareProcess(data:MMLData, sampleRate:int, bufferLength:int) : void 
    364372        { 
    365373            // initialize all channels 
     
    369377             
    370378            // call super function (set mmlData/grobalSequence/defaultBPM inside) 
    371             super.prepareProcess(data, sampleRate, bufferLength); 
     379            super._prepareProcess(data, sampleRate, bufferLength); 
    372380             
    373381            if (mmlData) { 
     
    393401         
    394402 
    395         /** Process all tracks. Calls onProcess() inside. This funciton must be called after prepareProcess(). */ 
    396         override public function process() : void 
    397         { 
    398             // clear all buffers 
    399             _module.clearAllBuffers(); 
    400             _isSequenceFinished = _processAllBuffers(); 
    401         } 
    402          
    403  
    404         /** Dummy process. This funciton must be called after prepareProcess(). 
    405          *  @param length dumming sample count. [NOTICE] This value is rounded by a buffer length. Not an exact value. 
    406          */ 
    407         public function dummyProcess(sampleCount:int) : void 
    408         { 
    409             var count:int, bufCount:int = sampleCount / _module.bufferLength; 
    410             if (bufCount == 0) return; 
    411              
    412             // register dummy processing events 
    413             _registerDummyProcessEvent(); 
    414              
    415             // buffering 
    416             for (count=0; count<bufCount; count++) { 
    417                 _isSequenceFinished = _processAllBuffers(); 
    418             } 
    419              
    420             // register standard processing events 
    421             _registerProcessEvent(); 
    422         } 
    423          
    424          
    425         // buffering all 
    426         private function _processAllBuffers() : Boolean 
     403        /** @private [sion internal] Process all tracks. Calls onProcess() inside. This funciton must be called after prepareProcess(). */ 
     404        override public function _process() : void 
    427405        { 
    428406            var bufferingLength:int, len:int, trk:SiMMLTrack, data:SiMMLData, finished:Boolean; 
     
    450428            _processedSampleCount += _module.bufferLength; 
    451429             
    452             return finished; 
     430            _isSequenceFinished = finished; 
     431        } 
     432         
     433 
     434        /** Dummy process. This funciton must be called after prepareProcess(). 
     435         *  @param length dumming sample count. [NOTICE] This value is rounded by a buffer length. Not an exact value. 
     436         */ 
     437        public function dummyProcess(sampleCount:int) : void 
     438        { 
     439            var count:int, bufCount:int = sampleCount / _module.bufferLength; 
     440            if (bufCount == 0) return; 
     441             
     442            // register dummy processing events 
     443            _registerDummyProcessEvent(); 
     444             
     445            // pseudo processing 
     446            for (count=0; count<bufCount; count++) _process(); 
     447             
     448            // register standard processing events 
     449            _registerProcessEvent(); 
    453450        } 
    454451         
     
    10921089        { 
    10931090            if (_currentTrack.eventMask & SiMMLTrack.MASK_QUANTIZE) return e.next;  // check mask 
    1094             _currentTrack.quantRatio = e.data / setting.maxQuantRatio;   // quantize ratio 
     1091            _currentTrack.quantRatio = e.data / setting.maxQuantRatio;              // quantize ratio 
    10951092            return e.next; 
    10961093        } 
     
    13651362        private function _onMasterVolume(e:MMLEvent) : MMLEvent 
    13661363        { 
    1367             e = e.getParameters(_p, SiOPMModule.STREAM_SIZE_MAX); 
     1364            e = e.getParameters(_p, SiOPMModule.STREAM_SEND_SIZE); 
    13681365            if (_currentTrack.eventMask & SiMMLTrack.MASK_VOLUME) return e.next;    // check mask 
    13691366            _currentTrack.channel.setAllStreamSendLevels(_p);                       // master volume 
  • as3/SiOPM/trunk/src/org/si/sion/sequencer/SiMMLVoice.as

    r3450 r3480  
    3939        public var psmTension:int; 
    4040         
    41         /** quantize ratio (same as "q" command), set -1 to ignore. @default -1 */ 
    42         public var quantRatio:int
     41        /** gate time (same as "q" command * 0.125), set Number.NaN to ignore. @default Number.NaN */ 
     42        public var gateTime:Number
    4343        /** track pitch shift (same as "k" command). @default 0 */ 
    4444        public var pitchShift:int; 
     
    192192             
    193193            // track settings 
    194             if (quantRatio!=-1) track.quantRatio = quantRatio*0.125
     194            if (!isNaN(gateTime)) track.quantRatio = gateTime
    195195            track.pitchShift = pitchShift; 
    196196            track.setPortament(portament); 
     
    230230            psmTension = 8; 
    231231             
    232             quantRatio = -1
     232            gateTime = Number.NaN
    233233            pitchShift = 0; 
    234234            portament = 0; 
     
    279279            psmTension = src.psmTension; 
    280280             
    281             quantRatio = src.quantRatio
     281            gateTime = src.gateTime
    282282            pitchShift = src.pitchShift; 
    283283            portament = src.portament; 
  • as3/SiOPM/trunk/src/org/si/sion/sequencer/base/MMLSequencer.as

    r3450 r3480  
    235235    // process 
    236236    //-------------------------------------------------- 
    237         /** Prepare to process audio. Override and call this in the overrided function. 
     237        /** @private [sion internal] Prepare to process audio. Override and call this in the overrided function. 
    238238         *  @param bufferLength Sample count to buffer samples at once. 
    239239         *  @param sampleRate Sampling rate. 44100 or 22050 is available. 
    240240         *  @param resetParams Reset all channel parameters. 
    241241         */ 
    242         public function prepareProcess(data:MMLData, sampleRate:int, bufferLength:int) : void 
     242        public function _prepareProcess(data:MMLData, sampleRate:int, bufferLength:int) : void 
    243243        { 
    244244            if (sampleRate!=22050 && sampleRate!=44100) throw new Error ("MMLSequencer error: Only 22050 or 44100 sampling rate is available."); 
     
    259259         
    260260         
    261         /** Process all tracks. override this function.  
     261        /** @private [sion internal] Process all tracks. override this function.  
    262262         *  @return Returns true when all processes are finished. 
    263263         */ 
    264         public function process() : void 
     264        public function _process() : void 
    265265        { 
    266266            // DO NOTHING !! 
  • as3/SiOPM/trunk/src/org/si/sion/utils/SiONPresetVoice.as

    r3450 r3480  
    8080                _new("ramp",      "Ramp wave sample",   new SiONVoice(5,160)); 
    8181 
    82                 /* 
    8382                _percuss("bassdrum",  "Simple bass drum",      0, 63, 28, -128); 
    8483                _percuss("snare",     "Simple snare drum",    17, 63, 32, 0, 64, 1); 
     
    8685                _percuss("openedhh",  "Simple opened hi-hat", 19, 63, 28, 0); 
    8786                _percuss("symbal",    "Simple symbal",        16, 48, 24, 0); 
    88                 */ 
    8987                 
    9088                _analog("dualsaw",      "Dual saw",      0, 1, 1, 0, 8); 
     
    622620        private function _percuss(key:String, name:String, ws:int, ar:int, rr:int, sw:int, cut:int=128, res:int=0) : void { 
    623621            var voice:SiONVoice = new SiONVoice(5, ws, ar, rr); 
    624             voice.quantRatio = 0; 
     622            voice.gateTime = 0; 
    625623            voice.releaseSweep = sw; 
    626624            voice.setLPFEnvelop(cut, res); 
  • as3/SiOPM/trunk/src/org/si/sound/Note.as

    r3450 r3480  
    1010    public class Note 
    1111    { 
    12         /** Note number[0-127], -1 sets playing with sequencers default note, -2 sets rest. */ 
     12        /** Note number[-1-127], -1 sets playing with sequencers default note. */ 
    1313        public var note:int = 0; 
    14         /** Velocity[0-128], 0 sets playing with sequencers default velocity. */ 
     14        /** Velocity[-1-128], -1 sets playing with sequencers default velocity, 0 sets no note (rest). */ 
    1515        public var velocity:int = 0; 
    16         /** Length in tick count[1920 for whole tone], 0 sets playing with sequencers default length. */ 
    17         public var tickLength:int = 0; 
     16        /** Length in 16th beat [16 for whole tone], Number.NaN sets playing with sequencers default length. */ 
     17        public var length:Number = 0; 
    1818         
    1919         
    2020        /** constructor 
    21          *  @param note Note number[0-127], -1 sets playing with sequencers default note and -2 sets as rest
    22          *  @param velocity Velocity[0-128], 0 sets playing with sequencers default velocity
    23          *  @param length Length in tick count[1920 for whole tone], 0 sets playing with sequencers default length. 
     21         *  @param note Note number[-1-127], -1 sets playing with sequencer's default note
     22         *  @param velocity Velocity[-1-128], -1 sets playing with sequencer's default velocity, 0 sets no note (rest)
     23         *  @param length Length in 16th beat [16 for whole tone], Number.NaN sets playing with sequencers default length. 
    2424         */ 
    25         function Note(note:int=-2, velocity:int=0, tickLength:int=0
     25        function Note(note:int=-1, velocity:int=0, length:Number=Number.NaN
    2626        { 
    27             setNote(note, velocity, tickLength); 
     27            setNote(note, velocity, length); 
    2828        } 
    2929 
    3030         
    3131        /** Set note. 
    32          *  @param note Note number[0-127], -1 sets playing with sequencers default note and -2 sets as rest
    33          *  @param velocity Velocity[0-128], 0 sets playing with sequencers default velocity
    34          *  @param length Length in tick count[1920 for whole tone], 0 sets playing with sequencers default length. 
     32         *  @param note Note number[-1-127], -1 sets playing with sequencer's default note
     33         *  @param velocity Velocity[-1-128], -1 sets playing with sequencer's default velocity, 0 sets no note (rest)
     34         *  @param length Length in 16th beat [16 for whole tone], Number.NaN sets playing with sequencers default length. 
    3535         *  @return this instance. 
    3636         */ 
    37         public function setNote(note:int=-1, velocity:int=0, tickLength:int=0) : Note 
     37        public function setNote(note:int=-1, velocity:int=-1, length:Number=Number.NaN) : Note 
    3838        { 
    3939            this.note = note; 
    4040            this.velocity = velocity; 
    41             this.tickLength = tickLength; 
     41            this.length = length; 
    4242            return this; 
    4343        } 
     
    4747        public function setRest() : Note 
    4848        { 
    49             note = -2
     49            velocity = 0
    5050            return this; 
    5151        } 
  • as3/SiOPM/trunk/src/org/si/sound/PatternSequencer.as

    r3450 r3480  
    1111    import org.si.sion.sequencer.SiMMLTrack; 
    1212    import org.si.sound.base.*; 
     13    import org.si.sound.synthesizer._synthesizer_internal; 
    1314     
    1415     
     
    2021        /** callback on first beat of every seguments */ 
    2122        public var onEnterSegument:Function = null; 
     23        /** callback on every notes */ 
     24        public var onNoteOn:Function = null; 
    2225        /** note pattern */ 
    2326        public var pattern:Vector.<Note>; 
    24          
    2527         
    2628        /** portament */ 
     
    3032        /** Sequence for interruption. */ 
    3133        protected var _sequence:MMLSequence; 
    32         /** MMLEvent.INTERNAL_CALL. */ 
    33         protected var _interruptEvent:MMLEvent; 
    3434        /** MMLEvent.REST. */ 
    3535        protected var _restEvent:MMLEvent; 
     36         
    3637        /** division */ 
    3738        protected var _division:int; 
     
    6768         
    6869        /** note. */ 
    69         override public function set note(n:int) : void { 
    70             _note = n; 
    71         } 
    7270        override public function get note() : int { 
    7371            if (_currentNote==null || _currentNote.note==-1) return _note; 
    7472            return _currentNote.note; 
    7573        } 
     74        override public function set note(n:int) : void { 
     75            _note = n; 
     76        } 
    7677         
    7778         
    7879        /** velocity. */ 
     80        public function get velocity() : int { 
     81            if (_currentNote==null || _currentNote.velocity==-1) return _velocity; 
     82            return _currentNote.velocity; 
     83        } 
    7984        public function set velocity(v:int) : void { 
    8085            _velocity = v; 
    8186        } 
    82         public function get velocity() : int { 
    83             if (_currentNote==null || _currentNote.velocity==0) return _velocity; 
    84             return _currentNote.velocity; 
    85         } 
    8687         
    8788         
    8889        /** length in 16th beat counts. */ 
     90        override public function get length() : Number { 
     91            if (_currentNote==null || isNaN(_currentNote.length)) return _length; 
     92            return _currentNote.length; 
     93        } 
    8994        override public function set length(l:Number) : void { 
    9095            _length = l; 
    91         } 
    92         override public function get length() : Number { 
    93             if (_currentNote==null || _currentNote.tickLength==0) return _length; 
    94             return _currentNote.tickLength / 120; 
    9596        } 
    9697         
     
    107108         *  @param frameStep sequence step in beat number, 16 sets stepped in every 16th beats. 
    108109         */ 
    109         function PatternSequencer(division:int=16
     110        function PatternSequencer(division:int=16, defaultNote:int=60, defaultVelocity:int=128, defaultLength:Number=0
    110111        { 
    111112            super("Pattern sequencer"); 
    112             var len:int = 1920/division; 
    113113            pattern = null; 
     114            onEnterSegument = null; 
     115            _data = new SiONData(); 
     116             
     117            _data.clear(); 
     118            _sequence = _data.appendNewSequence(); 
     119            _sequence.initialize(); 
     120            _sequence.appendNewEvent(MMLEvent.REPEAT_ALL, 0); 
     121            _sequence.appendNewCallback(_onBeat, 0); 
     122            _restEvent = _sequence.appendNewEvent(MMLEvent.REST, 0, 0); 
     123             
    114124            _pointer = 0; 
    115             _data = new SiONData(); 
    116             _sequence = _data.appendNewSequence().initialize(); 
    117             _sequence.appendNewEvent(MMLEvent.REPEAT_ALL, 0); 
    118             _interruptEvent = _sequence.appendNewCallback(_onBeat, 0); 
    119             _restEvent      = _sequence.appendNewEvent(MMLEvent.REST, 0, len); 
    120             _division = division; 
    121             _nextSegumentDivision = division; 
    122125            _frameCount = 0; 
    123             _velocity = 128; 
     126            _note     = defaultNote; 
     127            _velocity = defaultVelocity; 
     128            _length   = defaultLength; 
    124129            _currentNote = null; 
     130            quantize = 16; 
     131             
     132            this.division = division; 
     133            _onEnterSegument(); 
    125134        } 
    126135         
     
    134143        { 
    135144            _frameCount = 0; 
    136             var list:Vector.<SiMMLTrack> = _sequenceOn(_data, false); 
     145            var list:Vector.<SiMMLTrack> = _sequenceOn(_data, false, false); 
    137146            if (list.length >= 1) { 
    138147                _track = list[0]; 
    139148                _track.setPortament(_portament); 
    140149                _pointer = 0; 
    141                 _currentNote = (pattern && pattern.length>0) ? pattern[0] : null
     150                _currentNote = pattern[0]
    142151            } 
    143152        } 
     
    160169    //---------------------------------------- 
    161170        // callback on every beat 
    162         private function _onBeat(data:int) : MMLEvent 
     171        private function _onBeat(trackNumber:int) : MMLEvent 
    163172        { 
    164173            if (_frameCount == 0) _onEnterSegument(); 
     
    166175                if (_pointer >= pattern.length) _pointer = 0; 
    167176                _currentNote = pattern[_pointer]; 
    168                 if (_currentNote && _currentNote.note != -2) { 
    169                     _track.setNote(note, driver.sequencer.calcSampleLength(length), (_portament>0)); 
     177                if (_currentNote && _currentNote.velocity > 0) { 
     178                    var sampleLength:int = driver.sequencer.calcSampleLength(length); 
     179                    _track.setNote(note, sampleLength, (_portament>0)); 
    170180                    _track.velocity = velocity; 
     181                    if (onNoteOn != null) onNoteOn(); 
     182                    if (_synthesizer._synthesizer_internal::_requireVoiceUpdate) { 
     183                        _synthesizer.setTrackVoice(_track); 
     184                    } 
    171185                } 
    172186                _pointer++; 
  • as3/SiOPM/trunk/src/org/si/sound/RhythmBox.as

    r3450 r3480  
    1515     
    1616    /** Sound object playng rhythm tracks */ 
    17     public class RhythmBox extends MMLSoundObject 
     17    public class RhythmBox extends SoundObjectContainer 
    1818    { 
    1919    // variables 
    2020    //---------------------------------------- 
    21         /** voices for all tracks */ 
    22         protected var _voices:Vector.<SiONVoice>; 
    23          
    24         /** notes for all tracks */ 
    25         protected var _notes:Vector.<int>; 
    26          
    27         /** volumes for all tracks */ 
    28         protected var _trackVolumes:Vector.<int>; 
    29          
    30         /** phrases */ 
    31         protected var _phrases:Vector.<Vector.<Number>>; 
    32          
    3321        /** interruption step */ 
    3422        protected var _interruptStep:int; 
     23         
     24        /** bass drum pattern sequencer */ 
     25        public var bass:PatternSequencer; 
     26        /** snare drum pattern sequencer */ 
     27        public var snare:PatternSequencer; 
     28        /** hi-hat cymbal pattern sequencer */ 
     29        public var hihat:PatternSequencer; 
     30         
     31        protected var _closeHHPattern:Vector.<int>; 
     32        protected var _openHHPattern:Vector.<int>; 
     33        protected var _hhVoiceIndex:Vector.<int>; 
     34        protected var _hhVoices:Vector.<SiONVoice>; 
     35        protected var _currentHHIndex:int; 
     36         
    3537         
    3638         
     
    3840    // properties 
    3941    //---------------------------------------- 
    40         /** track count. this must be grater than 4. */ 
    41         public function set trackCount(count:int) : void { 
    42             if (count < 4) count = 4; 
    43             _voices.length  = count; 
    44             _trackVolumes.length = count; 
    45             _phrases.length = count; 
     42        /** bass drum velocity pattern */ 
     43        public function set bassPattern(pat:Array) : void 
     44        { 
     45            var i:int, len:int = pat.length; 
     46            for (i=0; i<16; i++) { 
     47                bass.pattern[i].velocity = pat[i % len]; 
     48            } 
    4649        } 
    47         public function get trackCount() : int { return _voices.length; } 
     50         
     51         
     52        /** snare drum velocity pattern */ 
     53        public function set snarePattern(pat:Array) : void 
     54        { 
     55            var i:int, len:int = pat.length; 
     56            for (i=0; i<16; i++) { 
     57                snare.pattern[i].velocity = pat[i % len]; 
     58            } 
     59        } 
     60         
     61         
     62        /** close hi-hat cymbal velocity pattern */ 
     63        public function set closeHHPattern(pat:Array) : void 
     64        { 
     65            var i:int, len:int = pat.length; 
     66            for (i=0; i<16; i++) _closeHHPattern[i] = pat[i % len]; 
     67            _updateHHPatterns(); 
     68        } 
     69         
     70         
     71        /** open hi-hat cymbal velocity pattern */ 
     72        public function set openHHPattern(pat:Array) : void 
     73        { 
     74            var i:int, len:int = pat.length; 
     75            for (i=0; i<16; i++) _openHHPattern[i] = pat[i % len]; 
     76            _updateHHPatterns(); 
     77        } 
     78         
     79         
     80        /** close hi-hat cymbal voice */ 
     81        public function set closeHHVoice(v:SiONVoice) : void 
     82        { 
     83            _hhVoices[0] = v; 
     84            hihat.voice = v; 
     85        } 
     86         
     87 
     88        /** open hi-hat cymbal voice */ 
     89        public function set openHHVoice(v:SiONVoice) : void 
     90        { 
     91            _hhVoices[1] = v; 
     92        } 
    4893         
    4994         
     
    5398    //---------------------------------------- 
    5499        /** constructor */ 
    55         function RhythmBox(trackCount:int = 4
     100        function RhythmBox(
    56101        { 
    57             _voices       = new Vector.<SiONVoice>(trackCount); 
    58             _trackVolumes = new Vector.<int>(trackCount); 
    59             _phrases      = new Vector.<Vector.<int>>(trackCount); 
    60             super(null); 
    61             name = "RhythmBox"; 
    62             _phrases[0] = Vector.<int>([]); 
    63             _phrases[1] = Vector.<int>([]); 
    64             _phrases[2] = Vector.<int>([]); 
    65             _phrases[3] = Vector.<int>([]); 
     102            super("RhythmBox"); 
    66103            _interruptStep = 120; 
     104            _closeHHPattern = new Vector.<int>(16, true); 
     105            _openHHPattern  = new Vector.<int>(16, true); 
     106            _hhVoiceIndex   = new Vector.<int>(16, true); 
     107            _hhVoices       = new Vector.<SiONVoice>(2, true); 
     108            addChild(bass  = new PatternSequencer(16, 36, 255, 1)); 
     109            addChild(snare = new PatternSequencer(16, 68, 128, 1)); 
     110            addChild(hihat = new PatternSequencer(16, 68, 64,  1)); 
     111            bass.pattern = new Vector.<Note>(); 
     112            snare.pattern = new Vector.<Note>(); 
     113            hihat.pattern = new Vector.<Note>(); 
     114            hihat.onNoteOn = _onNoteOnHH; 
     115            for (var i:int=0; i<16; i++) { 
     116                bass.pattern[i]  = new Note(); 
     117                snare.pattern[i] = new Note(); 
     118                hihat.pattern[i] = new Note(); 
     119                _hhVoiceIndex[i] = 0; 
     120            } 
    67121        } 
    68122         
     
    72126    // settings 
    73127    //---------------------------------------- 
    74         /** Get volume */ 
    75         public function getVolume(trackIndex:int) : Number { 
    76             return _trackVolumes[trackIndex]*0.0078125
     128        /** Get track volume */ 
     129        public function getTrackVolume(trackIndex:int) : Number { 
     130            return _soundList[trackIndex].volume
    77131        } 
    78132         
    79133         
    80         /** Set volume */ 
    81         public function setVolume(trackIndex:int, v:Number) : void { 
    82             if (v < 0) v = 0; 
    83             else if (v > 1) v = 1; 
    84             _trackVolumes[trackIndex] = v*128; 
    85             if (_tracks) _tracks[trackIndex].expression = _trackVolumes[trackIndex]; 
     134        /** Set track volume */ 
     135        public function setTrackVolume(trackIndex:int, v:Number) : void { 
     136            _soundList[trackIndex].volume = v; 
    86137        } 
    87138         
    88139         
    89         /** Get voice */ 
    90         public function getVoice(trackIndex:int) : SiONVoice { 
    91             return _voices[trackIndex]
     140        /** Get track voice */ 
     141        public function getTrackVoice(trackIndex:int) : SiONVoice { 
     142            return _soundList[trackIndex].voice
    92143        } 
    93144         
    94145         
    95         /** Set voice */ 
    96         public function setVoice(trackIndex:int, v:SiONVoice) : void { 
    97             _voices[trackIndex] = v; 
    98             if (_tracks) v.setTrackVoice(_tracks[trackIndex]); 
     146        /** Set track voice */ 
     147        public function setTrackVoice(trackIndex:int, v:SiONVoice) : void { 
     148            _soundList[trackIndex].voice = v; 
    99149        } 
    100150         
     
    104154    // operations 
    105155    //---------------------------------------- 
     156        /** @inhriteDoc */ 
     157        override public function play() : void { 
     158            _currentHHIndex = 0; 
     159            super.play(); 
     160        } 
    106161         
    107162         
     
    110165    // internal 
    111166    //---------------------------------------- 
    112         private function _constructData() : void  
    113         { 
    114             var seq:SiMMLSequence, i:int = 0, imax:int = _phrases.length; 
    115             _data.clear(); 
    116             for (i=0; i<imax; i++) { 
    117                 seq = _data.appendSequence().initialize(); 
    118                 seq.appendNewEvent(MMLEvent.REPEAT_ALL); 
    119                 seq.appendNewCallback(_onTrackInterruption, i); 
    120                 seq.appendNewEvent(MMLEvent.REST, 0, _interruptStep); 
     167        /** call after updating hi-hat patterns */ 
     168        protected function _updateHHPatterns() : void { 
     169            var i:int, vel:int; 
     170            for (i=0; i<16; i++) { 
     171                if (_openHHPattern[i] > 0) { 
     172                    vel = _openHHPattern[i]; 
     173                    _hhVoiceIndex[i] = 2; 
     174                } else { 
     175                    vel = _closeHHPattern[i]; 
     176                    _hhVoiceIndex[i] = (vel==0) ? 0 : 1; 
     177                } 
     178                hihat.pattern[i].velocity = vel; 
    121179            } 
    122180        } 
    123181         
    124         private function _onTrackInterruption(data:int) : MMLEvent 
    125         { 
    126             var track:SiMMLTrack = _tracks[data]; 
    127             track.keyOn(0, ); 
    128             return null; 
     182         
     183        /** handler for hi-hat note on */ 
     184        private function _onNoteOnHH() : void { 
     185            var voiceIndex:int = _hhVoiceIndex[hihat.frameCount]; 
     186            if (voiceIndex != 0 && voiceIndex != _currentHHIndex) { 
     187                hihat.voice = _hhVoices[voiceIndex-1]; 
     188                _currentHHIndex = voiceIndex; 
     189            } 
    129190        } 
    130191    } 
  • as3/SiOPM/trunk/src/org/si/sound/base/MMLSoundObject.as

    r3450 r3480  
    66 
    77 
    8 package org.si.sound
     8package org.si.sound.base
    99    import org.si.sion.*; 
    10     import org.si.sound.base.*; 
    1110    import org.si.sion.sequencer.SiMMLTrack; 
    1211    import org.si.sion.sequencer.SiMMLSequencer; 
     
    5251         
    5352        /** @private */ 
    54         override public function set channelMute(m:Boolean) : void {  
    55             super.channelMute = m; 
    56             if (_tracks) { 
    57                 var i:int, f:uint, imax:int = _tracks.length; 
    58                 for (i=0, f=_trackFilter; i<imax; i++, f>>=1) { 
    59                     if (f&1) _tracks[i].channel.mute = _totalMute; 
    60                 } 
    61             } 
    62         } 
    63          
    64         /** @private */ 
    65         override public function set channelVolume(v:Number) : void { 
    66             super.channelVolume = v; 
    67             if (_tracks) { 
    68                 var i:int, f:uint, imax:int = _tracks.length; 
    69                 for (i=0, f=_trackFilter; i<imax; i++, f>>=1) { 
    70                     if (f&1) _tracks[i].channel.masterVolume = _totalVolume*128; 
    71                 } 
    72             } 
    73         } 
    74          
    75         /** @private */ 
    76         override public function set channelPan(p:Number) : void { 
    77             super.channelPan = p; 
    78             if (_tracks) { 
    79                 var i:int, f:uint, imax:int = _tracks.length; 
    80                 for (i=0, f=_trackFilter; i<imax; i++, f>>=1) { 
    81                     if (f&1) _tracks[i].channel.pan = _totalPan; 
    82                 } 
    83             } 
    84         } 
    85          
    86         /** @private */ 
    87         public function set channelEffectSend1(v:Number) : void { 
    88             super.channelEffectSend1 = v; 
    89             v = _volume[1] * 0.0078125; 
     53        override public function set coarseTune(n:int) : void { 
     54            super.coarseTune = n; 
     55            if (_tracks) { 
     56                var i:int, f:uint, imax:int = _tracks.length; 
     57                for (i=0, f=_trackFilter; i<imax; i++, f>>=1) { 
     58                    if (f&1) _tracks[i].noteShift = _noteShift; 
     59                } 
     60            } 
     61        } 
     62         
     63        /** @private */ 
     64        override public function set fineTune(p:Number) : void { 
     65            super.fineTune = p; 
     66            if (_tracks) { 
     67                var i:int, f:uint, imax:int = _tracks.length, ps:int = _pitchShift*64; 
     68                for (i=0, f=_trackFilter; i<imax; i++, f>>=1) { 
     69                    if (f&1) _tracks[i].pitchShift = ps; 
     70                } 
     71            } 
     72        } 
     73         
     74        /** @private */ 
     75        override public function set gateTime(g:Number) : void { 
     76            super.gateTime = g; 
     77            if (_tracks) { 
     78                var i:int, f:uint, imax:int = _tracks.length; 
     79                for (i=0, f=_trackFilter; i<imax; i++, f>>=1) { 
     80                    if (f&1) _tracks[i].quantRatio = _gateTime; 
     81                } 
     82            } 
     83        } 
     84         
     85        /** @private */ 
     86        override public function set eventMask(m:int) : void { 
     87            super.eventMask = m; 
     88            if (_tracks) { 
     89                var i:int, f:uint, imax:int = _tracks.length; 
     90                for (i=0, f=_trackFilter; i<imax; i++, f>>=1) { 
     91                    if (f&1) _tracks[i].eventMask = _eventMask; 
     92                } 
     93            } 
     94        } 
     95         
     96        /** @private */ 
     97        override public function set mute(m:Boolean) : void {  
     98            super.mute = m; 
     99            if (_tracks) { 
     100                var i:int, f:uint, imax:int = _tracks.length; 
     101                for (i=0, f=_trackFilter; i<imax; i++, f>>=1) { 
     102                    if (f&1) _tracks[i].channel.mute = _mute; 
     103                } 
     104            } 
     105        } 
     106         
     107        /** @private */ 
     108        override public function set volume(v:Number) : void { 
     109            super.volume = v; 
     110            if (_tracks) { 
     111                var i:int, f:uint, imax:int = _tracks.length; 
     112                for (i=0, f=_trackFilter; i<imax; i++, f>>=1) { 
     113                    if (f&1) _tracks[i].channel.masterVolume = _volumes[0]; 
     114                } 
     115            } 
     116        } 
     117         
     118        /** @private */ 
     119        override public function set pan(p:Number) : void { 
     120            super.pan = p; 
     121            if (_tracks) { 
     122                var i:int, f:uint, imax:int = _tracks.length; 
     123                for (i=0, f=_trackFilter; i<imax; i++, f>>=1) { 
     124                    if (f&1) _tracks[i].channel.pan = _pan; 
     125                } 
     126            } 
     127        } 
     128         
     129        /** @private */ 
     130        override public function set effectSend1(v:Number) : void { 
     131            super.effectSend1 = v; 
     132            v = _volumes[1] * 0.0078125; 
    90133            if (_tracks) { 
    91134                var i:int, f:uint, imax:int = _tracks.length; 
     
    97140         
    98141        /** @private */ 
    99         public function set channelEffectSend2(v:Number) : void { 
    100             super.channelEffectSend2 = v; 
    101             v = _volume[2] * 0.0078125; 
     142        override public function set effectSend2(v:Number) : void { 
     143            super.effectSend2 = v; 
     144            v = _volumes[2] * 0.0078125; 
    102145            if (_tracks) { 
    103146                var i:int, f:uint, imax:int = _tracks.length; 
     
    109152         
    110153        /** @private */ 
    111         public function set channelEffectSend3(v:Number) : void { 
    112             super.channelEffectSend3 = v; 
    113             v = _volume[3] * 0.0078125; 
     154        override public function set effectSend3(v:Number) : void { 
     155            super.effectSend3 = v; 
     156            v = _volumes[3] * 0.0078125; 
    114157            if (_tracks) { 
    115158                var i:int, f:uint, imax:int = _tracks.length; 
     
    121164         
    122165        /** @private */ 
    123         public function set channelEffectSend4(v:Number) : void { 
    124             super.channelEffectSend4 = v; 
    125             v = _volume[4] * 0.0078125; 
     166        override public function set effectSend4(v:Number) : void { 
     167            super.effectSend4 = v; 
     168            v = _volumes[4] * 0.0078125; 
    126169            if (_tracks) { 
    127170                var i:int, f:uint, imax:int = _tracks.length; 
     
    133176         
    134177        /** @private */ 
    135         public function set channelPitchBend(p:Number) : void { 
    136             super.channelPitchBend = p; 
     178        override public function set pitchBend(p:Number) : void { 
     179            super.pitchBend = p; 
    137180            if (_tracks) { 
    138181                var i:int, f:uint, pb:int = p*64, imax:int = _tracks.length; 
     
    163206    // operations 
    164207    //---------------------------------------- 
     208        /** Reset */ 
     209        override public function reset() : void  
     210        { 
     211        } 
     212         
     213         
    165214        /** Play sound. */ 
    166215        override public function play() : void {  
    167216            if (!_compiled) _compile(); 
    168217            if (_tracks) { 
    169                 for each (var t:SiMMLTrack in _tracks) t.setDisposal(); 
     218                for each (var t:SiMMLTrack in _tracks) t.setDisposable(); 
    170219                _tracks = null; 
    171220            } 
     
    177226        override public function stop() : void { 
    178227            if (_tracks) { 
    179                 for each (var t:SiMMLTrack in _tracks) t.setDisposal(); 
     228                for each (var t:SiMMLTrack in _tracks) t.setDisposable(); 
    180229                _tracks = null; 
    181230            } 
  • as3/SiOPM/trunk/src/org/si/sound/base/ScaledSoundObject.as

    r3450 r3480  
    6060         *  @see org.si.sion.utils.Scale 
    6161         */ 
    62         function ScaledSoundObject(scaleInstance:Scale=null) { 
     62        function ScaledSoundObject(scaleInstance:Scale=null)  
     63        { 
    6364            super((scaleInstance) ? scaleInstance.scaleName : ""); 
    6465            _scale = scaleInstance || _defaultScale; 
     
    7172    // operations 
    7273    //---------------------------------------- 
     74        /** @inheritDoc */ 
     75        override public function reset() : void 
     76        { 
     77            super.reset(); 
     78            _scaleIndex = 0; 
     79        } 
    7380    } 
    7481} 
  • as3/SiOPM/trunk/src/org/si/sound/base/SoundObject.as

    r3450 r3480  
    1010    import org.si.sion.module.SiOPMModule; 
    1111    import org.si.sion.sequencer.SiMMLTrack; 
     12    import org.si.sound.synthesizer.SynthesizerBase; 
     13    import org.si.sound.synthesizer._synthesizer_internal; 
    1214     
    1315     
     
    1618    public class SoundObject 
    1719    { 
     20    // namespace 
     21    //---------------------------------------- 
     22        use namespace _synthesizer_internal; 
     23         
     24         
     25         
     26         
    1827    // valiables 
    1928    //---------------------------------------- 
     
    2332        /** Base note of this sound */ 
    2433        protected var _note:int; 
    25         /** Voice data to play */ 
    26         protected var _voice:SiONVoice; 
     34        /** Synthesizer instance */ 
     35        protected var _synthesizer:SynthesizerBase; 
     36        /** Synthesizer instance to use SiONVoice  */ 
     37        protected var _defaultSynthesizer:SynthesizerBase; 
    2738        /** track for noteOn() */ 
    2839        protected var _track:SiMMLTrack; 
     
    4354        /** gate ratio (value of 'q' command * 0.125) */ 
    4455        protected var _gateTime:Number; 
     56        /** Event mask (value of '@mask' command) */ 
     57        protected var _eventMask:Number; 
    4558        /** Event trigger ID */ 
    4659        protected var _eventTriggerID:int; 
     
    91104         
    92105        /** Voice data to play */ 
    93         public function get voice() : SiONVoice { return _voice || ((_parent) ? _parent.voice : null); } 
    94         public function set voice(v:SiONVoice) : void { _voice = v; } 
     106        public function get voice() : SiONVoice { return _synthesizer.voice || ((_parent) ? _parent.voice : null); } 
     107        public function set voice(v:SiONVoice) : void {  
     108            _defaultSynthesizer.voice = v; 
     109            _synthesizer = _defaultSynthesizer; 
     110        } 
     111 
     112        /** Synthesizer to generate sound */ 
     113        public function get synthesizer() : SynthesizerBase { return _synthesizer; } 
     114        public function set synthesizer(s:SynthesizerBase) : void { 
     115            _synthesizer = s || _defaultSynthesizer; 
     116            _synthesizer._synthesizer_internal::_owner = this; 
     117        } 
    95118         
    96119        /** Sound length in 16th beat, 0 sets inifinity length. @default 0. */ 
     
    124147            _gateTime = (g<0) ? 0 : (g>1) ? 1 : g; 
    125148            if (_track) _track.quantRatio = _gateTime; 
     149        } 
     150        /** Track event mask. (value of '@mask' command) */ 
     151        public function get eventMask() : int { return _eventMask; } 
     152        public function set eventMask(m:int) : void { 
     153            _eventMask = m; 
     154            if (_track) _track.eventMask = _eventMask; 
    126155        } 
    127156        /** Track id */ 
     
    158187            if (_track) _track.channel.pan = _pan; 
    159188        } 
     189         
     190         
    160191        /** Channel effect send level for slot 1 (0:Minimum - 1:Maximum), this property can control track after play(). */ 
    161192        public function get effectSend1() : Number { return _volumes[1] * 0.0078125; } 
     
    203234    //---------------------------------------- 
    204235        /** constructor. */ 
    205         function SoundObject(name:String = null
     236        function SoundObject(name:String = null, synthesizer:SynthesizerBase = null
    206237        { 
    207238            this.name = name || ""; 
    208239            _parent = null; 
    209             _voice = null; 
     240            _synthesizer = _defaultSynthesizer = new SynthesizerBase(); 
     241            _synthesizer._synthesizer_internal::_owner = this; 
    210242            _track = null; 
    211243            _tracks = null; 
     244            _volumes = new Vector.<int>(SiOPMModule.STREAM_SEND_SIZE); 
    212245             
    213246            _note = 60; 
     
    216249            _quantize = 1; 
    217250             
    218             _volumes = new Vector.<int>(SiOPMModule.STREAM_SIZE_MAX); 
    219251            _volumes[0] = 64; 
    220             for (var i:int=1; i<SiOPMModule.STREAM_SIZE_MAX; i++) _volumes[i] = 0; 
     252            for (var i:int=1; i<SiOPMModule.STREAM_SEND_SIZE; i++) _volumes[i] = 0; 
    221253            _pan = 0; 
    222254            _mute = false; 
     255            _pitchBend = 0; 
    223256             
    224257            _gateTime = 0.75; 
    225258            _noteShift = 0; 
    226259            _pitchShift = 0; 
    227             _pitchBend = 0; 
     260            _eventMask = 0; 
    228261            _eventTriggerID = 0; 
    229262            _noteOnTrigger = 0; 
     
    243276    // settings 
    244277    //---------------------------------------- 
     278        /** Reset */ 
     279        public function reset() : void  
     280        { 
     281            stop(); 
     282             
     283            _note = 60; 
     284            _length = 0; 
     285            _delay = 0; 
     286            _quantize = 1; 
     287             
     288            _volumes[0] = 64; 
     289            for (var i:int=1; i<SiOPMModule.STREAM_SEND_SIZE; i++) _volumes[i] = 0; 
     290            _pan = 0; 
     291            _mute = false; 
     292            _pitchBend = 0; 
     293             
     294            _gateTime = 0.75; 
     295            _noteShift = 0; 
     296            _pitchShift = 0; 
     297            _eventMask = 0; 
     298            _eventTriggerID = 0; 
     299            _noteOnTrigger = 0; 
     300            _noteOffTrigger = 0; 
     301             
     302            _thisVolume = 0.5; 
     303            _thisPan = 0; 
     304            _thisMute = false; 
     305        } 
     306         
     307         
    245308        /** Set event trigger. 
    246309         *  @param id Event trigger ID of this track. This value can be refered from SiONTrackEvent.eventTriggerID. 
     
    299362        /** driver.noteOn. 
    300363         *  @param note playing note 
    301          *  @param isDisposal disposal flag. 
     364         *  @param isDisposable disposable flag. 
    302365         *  @return playing track 
    303366         */ 
    304         protected function _noteOn(note:int, isDisposal:Boolean) : SiMMLTrack 
     367        protected function _noteOn(note:int, isDisposable:Boolean) : SiMMLTrack 
    305368        { 
    306369            if (!driver) return null; 
    307             var t:SiMMLTrack = driver.noteOn(note, voice, _length, _delay, _quantize, _trackID, isDisposal); 
     370            var v:SiONVoice = voice, 
     371                t:SiMMLTrack = driver.noteOn(note, v, _length, _delay, _quantize, _trackID, isDisposable); 
    308372            t.channel.setAllStreamSendLevels(_volumes); 
    309373            t.channel.pan       = _pan; 
    310374            t.channel.mute      = _mute; 
    311375            t.channel.pitchBend = _pitchBend * 64; 
    312             t.quantRatio = _gateTime; 
    313376            t.noteShift  = _noteShift; 
    314377            t.pitchShift = _pitchShift * 64; 
    315378            t.setEventTrigger(_eventTriggerID, _noteOnTrigger, _noteOffTrigger); 
     379            if (isNaN(v.gateTime)) t.quantRatio = _gateTime; 
    316380            return t; 
    317381        } 
     
    331395        /** driver.sequenceOn() 
    332396         *  @param data sequence data 
    333          *  @param isDisposal disposal flag 
     397         *  @param isDisposable disposable flag 
     398         *  @param applyLength 
    334399         *  @return vector of playing tracks 
    335400         */ 
    336         protected function _sequenceOn(data:SiONData, isDisposal:Boolean) : Vector.<SiMMLTrack> 
     401        protected function _sequenceOn(data:SiONData, isDisposable:Boolean, applyLength:Boolean=true) : Vector.<SiMMLTrack> 
    337402        { 
    338403            if (!driver) return null; 
    339             var list:Vector.<SiMMLTrack> = driver.sequenceOn(data, voice, _length, _delay, _quantize, _trackID, isDisposal), 
     404            var len:Number = (applyLength) ? _length : 0; 
     405            var v:SiONVoice = voice, 
     406                list:Vector.<SiMMLTrack> = driver.sequenceOn(data, v, len, _delay, _quantize, _trackID, isDisposable), 
    340407                t:SiMMLTrack, ps:int = _pitchShift * 64, pb:int = _pitchBend * 64; 
    341408            for each (t in list) { 
     
    344411                t.channel.mute      = _mute; 
    345412                t.channel.pitchBend = pb; 
    346                 t.quantRatio = _gateTime; 
    347413                t.noteShift  = _noteShift; 
    348414                t.pitchShift = ps; 
    349415                t.setEventTrigger(_eventTriggerID, _noteOnTrigger, _noteOffTrigger); 
     416                if (isNaN(v.gateTime)) t.quantRatio = _gateTime; 
    350417            } 
    351418            return list; 
  • as3/SiOPM/trunk/src/org/si/sound/base/SoundObjectContainer.as

    r3450 r3480  
    6161         
    6262        /** @private */ 
     63        override public function set eventMask(m:int) : void { 
     64            _eventMask = m; 
     65            for each (var sound:SoundObject in _soundList) sound.eventMask = m; 
     66        } 
     67        /** @private */ 
    6368        override public function set coarseTune(n:int) : void { 
    6469            _noteShift = n; 
     
    121126    // operations 
    122127    //---------------------------------------- 
     128        /** @inheritDoc */ 
     129        override public function reset() : void 
     130        { 
     131            super.reset(); 
     132            _thisVolume = 1; 
     133            for each (var sound:SoundObject in _soundList) sound.reset(); 
     134        } 
     135         
     136         
    123137        /** Set all children's volume by index. 
    124138         *  @param slot streaming slot number. 
     
    130144            for each (var sound:SoundObject in _soundList) sound.setVolume(slot, _volumes[slot]); 
    131145        } 
    132          
    133          
    134146         
    135147         
  • as3/SiOPM/trunk/src/org/si/sound/smf/SMFData.as

    r3450 r3480  
    1212 
    1313 
    14 package org.si.sound
     14package org.si.sound.smf
    1515    import flash.utils.ByteArray; 
    1616    import org.si.sound.smf.*; 
  • as3/SiOPM/trunk/src/org/si/sound/smf/SMFTrack.as

    r3450 r3480  
    1414package org.si.sound.smf { 
    1515    import flash.utils.ByteArray; 
    16     import org.si.sound.SMFData; 
    1716     
    1817