チェンジセット 3480
- コミット日時:
- 2010/03/04 01:54:56 (2 年前)
- ファイル:
-
- as3/SiOPM/trunk/src/org/si/license.txt (更新) (1 diff)
- as3/SiOPM/trunk/src/org/si/sion/SiONDriver.as (更新) (7 diffs)
- as3/SiOPM/trunk/src/org/si/sion/effector/SiEffectBase.as (更新) (1 diff)
- as3/SiOPM/trunk/src/org/si/sion/effector/SiEffectCompressor.as (更新) (6 diffs)
- as3/SiOPM/trunk/src/org/si/sion/effector/SiEffectConnector.as (削除)
- as3/SiOPM/trunk/src/org/si/sion/effector/SiEffectModule.as (更新) (9 diffs)
- as3/SiOPM/trunk/src/org/si/sion/effector/SiEffectStream.as (追加)
- as3/SiOPM/trunk/src/org/si/sion/module/SiOPMChannelParam.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sion/module/SiOPMModule.as (更新) (8 diffs)
- as3/SiOPM/trunk/src/org/si/sion/module/SiOPMStream.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMChannelBase.as (更新) (9 diffs)
- as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMChannelFM.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMChannelKS.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMChannelSampler.as (更新) (6 diffs)
- as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMOperator.as (更新) (1 diff)
- as3/SiOPM/trunk/src/org/si/sion/sequencer/SiMMLSequencer.as (更新) (7 diffs)
- as3/SiOPM/trunk/src/org/si/sion/sequencer/SiMMLVoice.as (更新) (4 diffs)
- as3/SiOPM/trunk/src/org/si/sion/sequencer/base/MMLSequencer.as (更新) (2 diffs)
- as3/SiOPM/trunk/src/org/si/sion/utils/SiONPresetVoice.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sound/Note.as (更新) (2 diffs)
- as3/SiOPM/trunk/src/org/si/sound/PatternSequencer.as (更新) (8 diffs)
- as3/SiOPM/trunk/src/org/si/sound/RhythmBox.as (更新) (6 diffs)
- as3/SiOPM/trunk/src/org/si/sound/base/MMLSoundObject.as (更新) (8 diffs)
- as3/SiOPM/trunk/src/org/si/sound/base/ScaledSoundObject.as (更新) (2 diffs)
- as3/SiOPM/trunk/src/org/si/sound/base/SoundObject.as (更新) (13 diffs)
- as3/SiOPM/trunk/src/org/si/sound/base/SoundObjectContainer.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sound/smf/SMFData.as (更新) (1 diff)
- as3/SiOPM/trunk/src/org/si/sound/smf/SMFTrack.as (更新) (1 diff)
- as3/SiOPM/trunk/src/org/si/sound/synthesizer (追加)
- as3/SiOPM/trunk/src/org/si/sound/synthesizer/SynthesizerBase.as (追加)
- as3/SiOPM/trunk/src/org/si/sound/synthesizer/_synthesizer_internal.as (追加)
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
as3/SiOPM/trunk/src/org/si/license.txt
r3165 r3480 1 1 License 2 2 ------- 3 Copyright (c) 200 9Kei Mesuda (keim) All rights reserved.3 Copyright (c) 2008-2010 Kei Mesuda (keim) All rights reserved. 4 4 5 5 Redistribution and use in source and binary forms, as3/SiOPM/trunk/src/org/si/sion/SiONDriver.as
r3450 r3480 35 35 import org.si.sion.utils.Fader; 36 36 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")] 37 72 38 73 … … 568 603 _soundChannel = _sound.play(); 569 604 _soundChannel.soundTransform = _soundTransform; 605 _process_addAllEventListners(); 570 606 } 571 607 } catch(e:Error) { … … 1223 1259 1224 1260 // 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(); 1228 1266 1229 1267 // limit rendering length … … 1276 1314 module.initialize(_channelCount, _bufferLength); 1277 1315 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()). 1279 1317 if (_data) _parseSystemCommand(_data.systemCommands); // parse #EFFECT (initialize effector inside) 1280 1318 effector._prepareProcess(); // set stream number inside … … 1302 1340 _prevFrameTime = t; 1303 1341 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 } 1316 1359 } 1317 1360 } … … 1333 1376 _inStreaming = true; 1334 1377 1335 if (_is FirstStreaming) _firstStream(e.data); // first streaming1336 else if (_isPaused) _fillzero(e.data); // paused1337 else {1378 if (_isPaused || _isFirstStreaming) { 1379 _fillzero(e.data); 1380 } else { 1338 1381 var t:int = getTimer(); 1382 1339 1383 // 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(); 1343 1389 1344 1390 // calculate the average of processing time … … 1397 1443 1398 1444 // first streaming 1399 private function _firstStream( buffer:ByteArray) : void {1445 private function _firstStream() : void { 1400 1446 _isFirstStreaming = false; 1401 1447 1402 // start enter frame event1403 _process_addAllEventListners();1404 1405 1448 // 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); 1407 1450 dispatchEvent(event); 1408 1451 if (event.isDefaultPrevented()) stop(); // canceled 1409 1410 _fillzero(buffer);1411 1452 } 1412 1453 as3/SiOPM/trunk/src/org/si/sion/effector/SiEffectBase.as
r3196 r3480 50 50 51 51 /** 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. Th is 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 x2because its a stereo stream.55 * @param length length to apply effect. You CANNOT use this length to the stream buffer directly. Should be x2because 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. 56 56 * @return output channels count. 57 57 */ as3/SiOPM/trunk/src/org/si/sion/effector/SiEffectCompressor.as
r2625 r3480 18 18 private var _windowRMSTotal:Number; 19 19 private var _windwoRMSAveraging:Number; 20 private var _thres:Number; // threshold 21 private var _slope:Number; // slope angle 20 private var _threshold2:Number; // threshold^2 22 21 private var _attRate:Number; // attack rate (per sample decay) 23 22 private var _relRate:Number; // release rate (per sample decay) 23 private var _maxGain:Number; // max gain 24 private var _gain:Number; // gain 24 25 25 26 … … 38 39 /** set parameters. 39 40 * @param thres threshold(0-1). 40 * @param slope slope(0-1).41 41 * @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]. 44 45 */ 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; 48 48 _windowSamples = int(wndTime * 44.1); 49 49 _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); 52 53 } 53 54 … … 67 68 override public function mmlCallback(args:Vector.<Number>) : void 68 69 { 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); 74 75 } 75 76 … … 81 82 _windowRMSList = SLLNumber.allocRing(_windowSamples); 82 83 _windowRMSTotal = 0; 84 _gain = 2; 83 85 return 2; 84 86 } … … 92 94 93 95 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; 97 97 for (i=startIndex; i<imax; i+=2) { 98 98 l = buffer[i]; … … 102 102 _windowRMSList.n = l * l + r * r; 103 103 _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; 105 107 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; 113 110 l = (l>1) ? 1 : (l<-1) ? -1 : l; 114 111 r = (r>1) ? 1 : (r<-1) ? -1 : r; as3/SiOPM/trunk/src/org/si/sion/effector/SiEffectModule.as
r3196 r3480 14 14 public class SiEffectModule 15 15 { 16 // constant 17 //-------------------------------------------------------------------------------- 18 19 20 16 21 // valiables 17 22 //-------------------------------------------------------------------------------- 18 23 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; 21 29 static private var _effectorInstances:* = {}; 22 30 … … 30 38 { 31 39 _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); 37 44 38 45 // initialize table … … 48 55 register("ds", SiEffectDownSampler); 49 56 register("speaker", SiEffectSpeakerSimulator); 50 register("comp", SiEffectCompressor); // bugful!!57 register("comp", SiEffectCompressor); 51 58 52 59 register("lf", SiFilterLowPass); … … 67 74 //-------------------------------------------------------------------------------- 68 75 /** 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. 70 77 */ 71 78 public function initialize() : void 72 79 { 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 { 76 91 } 77 92 … … 80 95 _sion_internal function _prepareProcess() : void 81 96 { 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 95 138 } 96 139 97 140 98 141 /** @private [sion internal] processing. */ 99 _sion_internal function _ process() : void100 { 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>, 102 145 bufferLength:int = _module.bufferLength, 103 146 output:Vector.<Number> = _module.output, 104 147 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); 111 158 for (i=0; i<imax; i++) output[i] += buffer[i]; 112 159 } 113 160 } 114 // master effect115 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); 117 164 } 118 165 … … 166 213 public function clear(slot:int) : void 167 214 { 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 } 169 221 } 170 222 … … 176 228 public function connect(slot:int, effector:SiEffectBase) : void 177 229 { 178 _effectConnectors[slot].connect(effector); 230 if (_globalEffects[slot] == null) _globalEffects[slot] = _allocStream(); 231 _globalEffects[slot].connect(effector); 179 232 } 180 233 … … 187 240 public function parseMML(slot:int, mml:String, postfix:String) : void 188 241 { 189 _effectConnectors[slot].parseMML(mml, postfix); 242 if (_globalEffects[slot] == null) _globalEffects[slot] = _allocStream(); 243 _globalEffects[slot].parseMML(mml, postfix); 190 244 } 191 245 … … 198 252 public function getEffector(slot:int, index:int) : SiEffectBase 199 253 { 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; 201 286 } 202 287 } as3/SiOPM/trunk/src/org/si/sion/module/SiOPMChannelParam.as
r3450 r3480 84 84 { 85 85 initSequence = new MMLSequence(); 86 volumes = new Vector.<Number>(SiOPMModule.STREAM_S IZE_MAX, true);86 volumes = new Vector.<Number>(SiOPMModule.STREAM_SEND_SIZE, true); 87 87 88 88 operatorParam = new Vector.<SiOPMOperatorParam>(4); … … 110 110 pmd = 0; 111 111 fratio = 100; 112 for (i=1; i<SiOPMModule.STREAM_S IZE_MAX; i++) { volumes[i] = 0; }112 for (i=1; i<SiOPMModule.STREAM_SEND_SIZE; i++) { volumes[i] = 0; } 113 113 volumes[0] = 0.5; 114 114 pan = 64; … … 148 148 pmd = org.pmd; 149 149 fratio = org.fratio; 150 for (i=0; i<SiOPMModule.STREAM_S IZE_MAX; i++) { volumes[i] = org.volumes[i]; }150 for (i=0; i<SiOPMModule.STREAM_SEND_SIZE; i++) { volumes[i] = org.volumes[i]; } 151 151 pan = org.pan; 152 152 as3/SiOPM/trunk/src/org/si/sion/module/SiOPMModule.as
r3450 r3480 1 1 //---------------------------------------------------------------------------------------------------- 2 // FM sound module based on OPM emulator and TSS algorism.2 // SiOPM sound module 3 3 // Copyright (c) 2008 keim All rights reserved. 4 4 // Distributed under BSD-style license (see org.si.license.txt). … … 9 9 import org.si.utils.SLLint; 10 10 import org.si.sion.module.channels.*; 11 import org.si.sion.namespaces._sion_internal; 11 12 12 13 13 /** FM sound module based on OPM emulator and TSS algorism.*/14 /** SiOPM sound module */ 14 15 public class SiOPMModule 15 16 { 16 17 // constants 17 18 //-------------------------------------------------- 18 /** maximum value of stream buffer size*/19 static public const STREAM_S IZE_MAX:int = 8;19 /** size of stream send */ 20 static public const STREAM_SEND_SIZE:int = 8; 20 21 /** pipe size */ 21 22 static public const PIPE_SIZE:int = 5; … … 30 31 /** zero buffer */ 31 32 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>; 34 37 35 38 // buffer length … … 44 47 //-------------------------------------------------- 45 48 /** Buffer count */ 46 public function get output() : Vector.<Number> { return streamBuffer[0].buffer; }49 public function get output() : Vector.<Number> { return outputStream.buffer; } 47 50 /** Buffer channel count */ 48 public function get channelCount() : int { return streamBuffer[0].channels; }51 public function get channelCount() : int { return outputStream.channels; } 49 52 /** Buffer length */ 50 53 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 streams58 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; }72 54 73 55 … … 88 70 89 71 // stream buffer 90 streamBuffer = new Vector.<SiOPMStream>();91 stream Count = 1;72 outputStream = new SiOPMStream(); 73 streamSlot = new Vector.<SiOPMStream>(STREAM_SEND_SIZE, true); 92 74 93 75 // zero buffer gives always 0 … … 114 96 public function initialize(channelCount:int, bufferLength:int) : void 115 97 { 116 var i:int, stream:SiOPMStream , bufferLength2:int = bufferLength<<1;98 var i:int, stream:SiOPMStream; 117 99 100 // reset stream slot 101 for (i=0; i<STREAM_SEND_SIZE; i++) streamSlot[i] = null; 102 streamSlot[0] = outputStream; 103 118 104 // reallocate buffer 119 105 if (_bufferLength != bufferLength) { 120 106 _bufferLength = bufferLength; 121 for each (stream in streamBuffer) { 122 stream.buffer.length = bufferLength2; 123 } 107 outputStream.buffer.length = bufferLength<<1; 124 108 for (i=0; i<PIPE_SIZE; i++) { 125 109 SLLint.freeRing(_pipeBuffer[i]); … … 128 112 } 129 113 } 130 131 // set standard outputs channel count132 streamBuffer[0].channels = channelCount;133 114 134 115 // initialize all channels … … 145 126 146 127 147 /** Clear allbuffer. */148 public function clearAllBuffers() : void128 /** @private [sion internal] Clear output buffer. */ 129 _sion_internal function _beginProcess() : void 149 130 { 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(); 156 132 } 157 133 158 134 159 /** Limit output level in the ranged of-1 ~ 1.*/160 public function limitLevel() : void135 /** @private [sion internal] Limit output level in the ranged between -1 ~ 1.*/ 136 _sion_internal function _endProcess() : void 161 137 { 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(); 169 139 } 170 140 as3/SiOPM/trunk/src/org/si/sion/module/SiOPMStream.as
r3450 r3480 19 19 public var buffer:Vector.<Number> = new Vector.<Number>(); 20 20 21 / ** coefficient of volume/panning */22 pr otectedvar _panTable:Vector.<Number>;23 pr otectedvar _i2n:Number;21 // coefficient of volume/panning 22 private var _panTable:Vector.<Number>; 23 private var _i2n:Number; 24 24 25 25 … … 40 40 // operation 41 41 //-------------------------------------------------- 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 42 64 /** write buffer by org.si.utils.SLLint */ 43 65 public function write(pointer:SLLint, start:int, len:int, vol:Number, pan:int) : void … … 140 162 bytes.position = initPosition; 141 163 } 142 143 144 145 146 // factory147 //--------------------------------------------------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) : SiOPMStream153 {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) : void164 {165 freeBuffers.push(stream);166 }167 164 } 168 165 } as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMChannelBase.as
r3450 r3480 59 59 /** out pipe */ protected var _outPipe :SLLint; 60 60 61 // Volume 61 // volume and stream 62 /** stream */ protected var _streams:Vector.<SiOPMStream>; 63 /** volume */ protected var _volumes:Vector.<Number>; 62 64 /** idling flag */ protected var _isIdling:Boolean; 63 /** volume */ protected var _volume:Vector.<Number>;64 65 /** pan */ protected var _pan:int; 65 66 /** effect send flag */ protected var _hasEffectSend:Boolean; … … 102 103 _isFree = true; 103 104 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); 105 107 _filter_eg_time = new Vector.<int>(6, true); 106 108 _filter_eg_cutoff = new Vector.<int>(6, true); … … 135 137 136 138 /** Master volume (0-128) */ 137 public function get masterVolume() : int { return _volume [0]*128; }139 public function get masterVolume() : int { return _volumes[0]*128; } 138 140 public function set masterVolume(v:int) : void { 139 141 v = (v<0) ? 0 : (v>128) ? 128 : v; 140 _volume [0] = v * 0.0078125; // 0.0078125 = 1/128142 _volumes[0] = v * 0.0078125; // 0.0078125 = 1/128 141 143 } 142 144 … … 194 196 // volume control 195 197 //-------------------------------------------------- 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 */ 197 201 public function setAllStreamSendLevels(param:Vector.<int>) : void 198 202 { 199 var i:int, imax:int = SiOPMModule.STREAM_S IZE_MAX, v:int;203 var i:int, imax:int = SiOPMModule.STREAM_SEND_SIZE, v:int; 200 204 for (i=0; i<imax; i++) { 201 205 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; 203 207 } 204 208 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; 207 221 } 208 222 … … 214 228 public function setStreamSend(streamNum:int, volume:Number) : void 215 229 { 216 _volume [streamNum] = volume;230 _volumes[streamNum] = volume; 217 231 if (streamNum == 0) return; 218 232 if (volume > 0) _hasEffectSend = true; 219 233 else { 220 var i:int, imax:int = SiOPMModule.STREAM_S IZE_MAX;234 var i:int, imax:int = SiOPMModule.STREAM_SEND_SIZE; 221 235 for (_hasEffectSend=false, i=1; i<imax; i++) { 222 if (_volume [i] > 0) _hasEffectSend = true;236 if (_volumes[i] > 0) _hasEffectSend = true; 223 237 } 224 238 } 225 239 } 240 226 241 227 242 /** get stream send. … … 231 246 public function getStreamSend(streamNum:int) : Number 232 247 { 233 return _volume [streamNum];248 return _volumes[streamNum]; 234 249 } 235 250 … … 420 435 { 421 436 // volume 422 var i:int, imax:int = SiOPMModule.STREAM_S IZE_MAX;437 var i:int, imax:int = SiOPMModule.STREAM_SEND_SIZE; 423 438 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 } 425 443 _pan = prev._pan; 426 444 _hasEffectSend = prev._hasEffectSend; 427 445 _mute = prev._mute; 428 446 } 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 } 431 453 _pan = 64; 432 454 _hasEffectSend = false; … … 516 538 public function buffer(len:int) : void 517 539 { 540 var i:int, stream:SiOPMStream; 541 518 542 if (_isIdling) { 519 543 // idling process … … 533 557 if (_outputMode == OUTPUT_STANDARD && !_mute) { 534 558 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 } 538 564 } 539 565 } 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); 541 568 } 542 569 } as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMChannelFM.as
r3450 r3480 90 90 str += String(_operatorCount) + "\n"; 91 91 $("fb ", _inputLevel-6); 92 $2("vol", _volume [0], "pan", _pan-64);92 $2("vol", _volumes[0], "pan", _pan-64); 93 93 if (operator[0]) str += String(operator[0]) + "\n"; 94 94 if (operator[1]) str += String(operator[1]) + "\n"; … … 219 219 220 220 if (withVolume) { 221 var imax:int = SiOPMModule.STREAM_S IZE_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; 224 224 _pan = param.pan; 225 225 } … … 244 244 override public function getSiOPMChannelParam(param:SiOPMChannelParam) : void 245 245 { 246 var i:int, imax:int = SiOPMModule.STREAM_S IZE_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]; 248 248 param.pan = _pan; 249 249 param.fratio = _freq_ratio; as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMChannelKS.as
r3450 r3480 55 55 str += String(_operatorCount) + "\n"; 56 56 $("fb ", _inputLevel-6); 57 $2("vol", _volume [0], "pan", _pan-64);57 $2("vol", _volumes[0], "pan", _pan-64); 58 58 if (operator[0]) str += String(operator[0]) + "\n"; 59 59 if (operator[1]) str += String(operator[1]) + "\n"; … … 277 277 override public function buffer(len:int) : void 278 278 { 279 var i:int, stream:SiOPMStream; 280 279 281 if (_isIdling) { 280 282 // idling process … … 299 301 if (_outputMode == OUTPUT_STANDARD && !_mute) { 300 302 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 } 304 308 } 305 309 } 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); 307 312 } 308 313 } as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMChannelSampler.as
r3450 r3480 39 39 { 40 40 var str:String = "SiOPMChannelSampler : "; 41 $2("vol", _volume [0]*_expression, "pan", _pan-64);41 $2("vol", _volumes[0]*_expression, "pan", _pan-64); 42 42 return str; 43 43 function $2(p:String, i:*, q:String, j:*) : void { str += " " + p + "=" + String(i) + " / " + q + "=" + String(j) + "\n"; } … … 72 72 73 73 if (withVolume) { 74 var imax:int = SiOPMModule.STREAM_S IZE_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; 77 77 _pan = param.pan; 78 78 } … … 85 85 override public function getSiOPMChannelParam(param:SiOPMChannelParam) : void 86 86 { 87 var i:int, imax:int = SiOPMModule.STREAM_S IZE_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]; 89 89 param.pan = _pan; 90 90 } … … 202 202 override public function buffer(len:int) : void 203 203 { 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; 205 205 if (_isIdling || _sampleData == null || _mute) { 206 206 //_nop(len); … … 208 208 if (_sampleData.isExtracted) { 209 209 // stream extracted data 210 for (residue=len, i=0 , imax=0; residue>0;) {210 for (residue=len, i=0; residue>0;) { 211 211 // copy to buffer 212 212 processed = (_sampleIndex + residue < _sampleData.endPoint) ? residue : (_sampleData.endPoint - _sampleIndex); 213 213 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 } 218 222 } 219 223 } 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); 222 227 } 223 228 _sampleIndex += processed; … … 255 260 // copy to buffer 256 261 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 } 261 270 } 262 271 } 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); 265 275 } 266 276 } as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMOperator.as
r3450 r3480 501 501 // fixed pitch 502 502 if (param.fixedPitch == 0) { 503 _pitchIndex = 3840;504 _updateKC(_table.nnToKC[(_pitchIndex>>6)&127]);503 //_pitchIndex = 3840; 504 //_updateKC(_table.nnToKC[(_pitchIndex>>6)&127]); 505 505 _pitchFixed = false; 506 506 } else { as3/SiOPM/trunk/src/org/si/sion/sequencer/SiMMLSequencer.as
r3450 r3480 8 8 import flash.system.System; 9 9 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; 12 21 import org.si.sion.utils.Translator; 13 22 import org.si.sion.namespaces._sion_internal; 14 import org.si.sion.sequencer.base._sion_sequencer_internal;15 23 16 24 … … 357 365 // process 358 366 //-------------------------------------------------- 359 /** Prepare to process audio.367 /** @private [sion internal] Prepare to process audio. 360 368 * @param bufferLength Buffering length of processing samples at once. 361 369 * @param resetParams Reset all channel parameters. 362 370 */ 363 override public function prepareProcess(data:MMLData, sampleRate:int, bufferLength:int) : void371 override public function _prepareProcess(data:MMLData, sampleRate:int, bufferLength:int) : void 364 372 { 365 373 // initialize all channels … … 369 377 370 378 // call super function (set mmlData/grobalSequence/defaultBPM inside) 371 super. prepareProcess(data, sampleRate, bufferLength);379 super._prepareProcess(data, sampleRate, bufferLength); 372 380 373 381 if (mmlData) { … … 393 401 394 402 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 427 405 { 428 406 var bufferingLength:int, len:int, trk:SiMMLTrack, data:SiMMLData, finished:Boolean; … … 450 428 _processedSampleCount += _module.bufferLength; 451 429 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(); 453 450 } 454 451 … … 1092 1089 { 1093 1090 if (_currentTrack.eventMask & SiMMLTrack.MASK_QUANTIZE) return e.next; // check mask 1094 _currentTrack.quantRatio = e.data / setting.maxQuantRatio; // quantize ratio1091 _currentTrack.quantRatio = e.data / setting.maxQuantRatio; // quantize ratio 1095 1092 return e.next; 1096 1093 } … … 1365 1362 private function _onMasterVolume(e:MMLEvent) : MMLEvent 1366 1363 { 1367 e = e.getParameters(_p, SiOPMModule.STREAM_S IZE_MAX);1364 e = e.getParameters(_p, SiOPMModule.STREAM_SEND_SIZE); 1368 1365 if (_currentTrack.eventMask & SiMMLTrack.MASK_VOLUME) return e.next; // check mask 1369 1366 _currentTrack.channel.setAllStreamSendLevels(_p); // master volume as3/SiOPM/trunk/src/org/si/sion/sequencer/SiMMLVoice.as
r3450 r3480 39 39 public var psmTension:int; 40 40 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; 43 43 /** track pitch shift (same as "k" command). @default 0 */ 44 44 public var pitchShift:int; … … 192 192 193 193 // track settings 194 if ( quantRatio!=-1) track.quantRatio = quantRatio*0.125;194 if (!isNaN(gateTime)) track.quantRatio = gateTime; 195 195 track.pitchShift = pitchShift; 196 196 track.setPortament(portament); … … 230 230 psmTension = 8; 231 231 232 quantRatio = -1;232 gateTime = Number.NaN; 233 233 pitchShift = 0; 234 234 portament = 0; … … 279 279 psmTension = src.psmTension; 280 280 281 quantRatio = src.quantRatio;281 gateTime = src.gateTime; 282 282 pitchShift = src.pitchShift; 283 283 portament = src.portament; as3/SiOPM/trunk/src/org/si/sion/sequencer/base/MMLSequencer.as
r3450 r3480 235 235 // process 236 236 //-------------------------------------------------- 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. 238 238 * @param bufferLength Sample count to buffer samples at once. 239 239 * @param sampleRate Sampling rate. 44100 or 22050 is available. 240 240 * @param resetParams Reset all channel parameters. 241 241 */ 242 public function prepareProcess(data:MMLData, sampleRate:int, bufferLength:int) : void242 public function _prepareProcess(data:MMLData, sampleRate:int, bufferLength:int) : void 243 243 { 244 244 if (sampleRate!=22050 && sampleRate!=44100) throw new Error ("MMLSequencer error: Only 22050 or 44100 sampling rate is available."); … … 259 259 260 260 261 /** Process all tracks. override this function.261 /** @private [sion internal] Process all tracks. override this function. 262 262 * @return Returns true when all processes are finished. 263 263 */ 264 public function process() : void264 public function _process() : void 265 265 { 266 266 // DO NOTHING !! as3/SiOPM/trunk/src/org/si/sion/utils/SiONPresetVoice.as
r3450 r3480 80 80 _new("ramp", "Ramp wave sample", new SiONVoice(5,160)); 81 81 82 /*83 82 _percuss("bassdrum", "Simple bass drum", 0, 63, 28, -128); 84 83 _percuss("snare", "Simple snare drum", 17, 63, 32, 0, 64, 1); … … 86 85 _percuss("openedhh", "Simple opened hi-hat", 19, 63, 28, 0); 87 86 _percuss("symbal", "Simple symbal", 16, 48, 24, 0); 88 */89 87 90 88 _analog("dualsaw", "Dual saw", 0, 1, 1, 0, 8); … … 622 620 private function _percuss(key:String, name:String, ws:int, ar:int, rr:int, sw:int, cut:int=128, res:int=0) : void { 623 621 var voice:SiONVoice = new SiONVoice(5, ws, ar, rr); 624 voice. quantRatio= 0;622 voice.gateTime = 0; 625 623 voice.releaseSweep = sw; 626 624 voice.setLPFEnvelop(cut, res); as3/SiOPM/trunk/src/org/si/sound/Note.as
r3450 r3480 10 10 public class Note 11 11 { 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. */ 13 13 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). */ 15 15 public var velocity:int = 0; 16 /** Length in tick count[1920 for whole tone], 0sets 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; 18 18 19 19 20 20 /** 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], 0sets 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. 24 24 */ 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) 26 26 { 27 setNote(note, velocity, tickLength);27 setNote(note, velocity, length); 28 28 } 29 29 30 30 31 31 /** 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], 0sets 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. 35 35 * @return this instance. 36 36 */ 37 public function setNote(note:int=-1, velocity:int= 0, tickLength:int=0) : Note37 public function setNote(note:int=-1, velocity:int=-1, length:Number=Number.NaN) : Note 38 38 { 39 39 this.note = note; 40 40 this.velocity = velocity; 41 this. tickLength = tickLength;41 this.length = length; 42 42 return this; 43 43 } … … 47 47 public function setRest() : Note 48 48 { 49 note = -2;49 velocity = 0; 50 50 return this; 51 51 } as3/SiOPM/trunk/src/org/si/sound/PatternSequencer.as
r3450 r3480 11 11 import org.si.sion.sequencer.SiMMLTrack; 12 12 import org.si.sound.base.*; 13 import org.si.sound.synthesizer._synthesizer_internal; 13 14 14 15 … … 20 21 /** callback on first beat of every seguments */ 21 22 public var onEnterSegument:Function = null; 23 /** callback on every notes */ 24 public var onNoteOn:Function = null; 22 25 /** note pattern */ 23 26 public var pattern:Vector.<Note>; 24 25 27 26 28 /** portament */ … … 30 32 /** Sequence for interruption. */ 31 33 protected var _sequence:MMLSequence; 32 /** MMLEvent.INTERNAL_CALL. */33 protected var _interruptEvent:MMLEvent;34 34 /** MMLEvent.REST. */ 35 35 protected var _restEvent:MMLEvent; 36 36 37 /** division */ 37 38 protected var _division:int; … … 67 68 68 69 /** note. */ 69 override public function set note(n:int) : void {70 _note = n;71 }72 70 override public function get note() : int { 73 71 if (_currentNote==null || _currentNote.note==-1) return _note; 74 72 return _currentNote.note; 75 73 } 74 override public function set note(n:int) : void { 75 _note = n; 76 } 76 77 77 78 78 79 /** velocity. */ 80 public function get velocity() : int { 81 if (_currentNote==null || _currentNote.velocity==-1) return _velocity; 82 return _currentNote.velocity; 83 } 79 84 public function set velocity(v:int) : void { 80 85 _velocity = v; 81 86 } 82 public function get velocity() : int {83 if (_currentNote==null || _currentNote.velocity==0) return _velocity;84 return _currentNote.velocity;85 }86 87 87 88 88 89 /** 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 } 89 94 override public function set length(l:Number) : void { 90 95 _length = l; 91 }92 override public function get length() : Number {93 if (_currentNote==null || _currentNote.tickLength==0) return _length;94 return _currentNote.tickLength / 120;95 96 } 96 97 … … 107 108 * @param frameStep sequence step in beat number, 16 sets stepped in every 16th beats. 108 109 */ 109 function PatternSequencer(division:int=16 )110 function PatternSequencer(division:int=16, defaultNote:int=60, defaultVelocity:int=128, defaultLength:Number=0) 110 111 { 111 112 super("Pattern sequencer"); 112 var len:int = 1920/division;113 113 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 114 124 _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;122 125 _frameCount = 0; 123 _velocity = 128; 126 _note = defaultNote; 127 _velocity = defaultVelocity; 128 _length = defaultLength; 124 129 _currentNote = null; 130 quantize = 16; 131 132 this.division = division; 133 _onEnterSegument(); 125 134 } 126 135 … … 134 143 { 135 144 _frameCount = 0; 136 var list:Vector.<SiMMLTrack> = _sequenceOn(_data, false );145 var list:Vector.<SiMMLTrack> = _sequenceOn(_data, false, false); 137 146 if (list.length >= 1) { 138 147 _track = list[0]; 139 148 _track.setPortament(_portament); 140 149 _pointer = 0; 141 _currentNote = (pattern && pattern.length>0) ? pattern[0] : null;150 _currentNote = pattern[0]; 142 151 } 143 152 } … … 160 169 //---------------------------------------- 161 170 // callback on every beat 162 private function _onBeat( data:int) : MMLEvent171 private function _onBeat(trackNumber:int) : MMLEvent 163 172 { 164 173 if (_frameCount == 0) _onEnterSegument(); … … 166 175 if (_pointer >= pattern.length) _pointer = 0; 167 176 _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)); 170 180 _track.velocity = velocity; 181 if (onNoteOn != null) onNoteOn(); 182 if (_synthesizer._synthesizer_internal::_requireVoiceUpdate) { 183 _synthesizer.setTrackVoice(_track); 184 } 171 185 } 172 186 _pointer++; as3/SiOPM/trunk/src/org/si/sound/RhythmBox.as
r3450 r3480 15 15 16 16 /** Sound object playng rhythm tracks */ 17 public class RhythmBox extends MMLSoundObject17 public class RhythmBox extends SoundObjectContainer 18 18 { 19 19 // variables 20 20 //---------------------------------------- 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 33 21 /** interruption step */ 34 22 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 35 37 36 38 … … 38 40 // properties 39 41 //---------------------------------------- 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 } 46 49 } 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 } 48 93 49 94 … … 53 98 //---------------------------------------- 54 99 /** constructor */ 55 function RhythmBox( trackCount:int = 4)100 function RhythmBox() 56 101 { 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"); 66 103 _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 } 67 121 } 68 122 … … 72 126 // settings 73 127 //---------------------------------------- 74 /** Get volume */75 public function get Volume(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; 77 131 } 78 132 79 133 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; 86 137 } 87 138 88 139 89 /** Get voice */90 public function get Voice(trackIndex:int) : SiONVoice {91 return _ voices[trackIndex];140 /** Get track voice */ 141 public function getTrackVoice(trackIndex:int) : SiONVoice { 142 return _soundList[trackIndex].voice; 92 143 } 93 144 94 145 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; 99 149 } 100 150 … … 104 154 // operations 105 155 //---------------------------------------- 156 /** @inhriteDoc */ 157 override public function play() : void { 158 _currentHHIndex = 0; 159 super.play(); 160 } 106 161 107 162 … … 110 165 // internal 111 166 //---------------------------------------- 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; 121 179 } 122 180 } 123 181 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 } 129 190 } 130 191 } as3/SiOPM/trunk/src/org/si/sound/base/MMLSoundObject.as
r3450 r3480 6 6 7 7 8 package org.si.sound {8 package org.si.sound.base { 9 9 import org.si.sion.*; 10 import org.si.sound.base.*;11 10 import org.si.sion.sequencer.SiMMLTrack; 12 11 import org.si.sion.sequencer.SiMMLSequencer; … … 52 51 53 52 /** @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; 90 133 if (_tracks) { 91 134 var i:int, f:uint, imax:int = _tracks.length; … … 97 140 98 141 /** @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; 102 145 if (_tracks) { 103 146 var i:int, f:uint, imax:int = _tracks.length; … … 109 152 110 153 /** @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; 114 157 if (_tracks) { 115 158 var i:int, f:uint, imax:int = _tracks.length; … … 121 164 122 165 /** @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; 126 169 if (_tracks) { 127 170 var i:int, f:uint, imax:int = _tracks.length; … … 133 176 134 177 /** @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; 137 180 if (_tracks) { 138 181 var i:int, f:uint, pb:int = p*64, imax:int = _tracks.length; … … 163 206 // operations 164 207 //---------------------------------------- 208 /** Reset */ 209 override public function reset() : void 210 { 211 } 212 213 165 214 /** Play sound. */ 166 215 override public function play() : void { 167 216 if (!_compiled) _compile(); 168 217 if (_tracks) { 169 for each (var t:SiMMLTrack in _tracks) t.setDisposa l();218 for each (var t:SiMMLTrack in _tracks) t.setDisposable(); 170 219 _tracks = null; 171 220 } … … 177 226 override public function stop() : void { 178 227 if (_tracks) { 179 for each (var t:SiMMLTrack in _tracks) t.setDisposa l();228 for each (var t:SiMMLTrack in _tracks) t.setDisposable(); 180 229 _tracks = null; 181 230 } as3/SiOPM/trunk/src/org/si/sound/base/ScaledSoundObject.as
r3450 r3480 60 60 * @see org.si.sion.utils.Scale 61 61 */ 62 function ScaledSoundObject(scaleInstance:Scale=null) { 62 function ScaledSoundObject(scaleInstance:Scale=null) 63 { 63 64 super((scaleInstance) ? scaleInstance.scaleName : ""); 64 65 _scale = scaleInstance || _defaultScale; … … 71 72 // operations 72 73 //---------------------------------------- 74 /** @inheritDoc */ 75 override public function reset() : void 76 { 77 super.reset(); 78 _scaleIndex = 0; 79 } 73 80 } 74 81 } as3/SiOPM/trunk/src/org/si/sound/base/SoundObject.as
r3450 r3480 10 10 import org.si.sion.module.SiOPMModule; 11 11 import org.si.sion.sequencer.SiMMLTrack; 12 import org.si.sound.synthesizer.SynthesizerBase; 13 import org.si.sound.synthesizer._synthesizer_internal; 12 14 13 15 … … 16 18 public class SoundObject 17 19 { 20 // namespace 21 //---------------------------------------- 22 use namespace _synthesizer_internal; 23 24 25 26 18 27 // valiables 19 28 //---------------------------------------- … … 23 32 /** Base note of this sound */ 24 33 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; 27 38 /** track for noteOn() */ 28 39 protected var _track:SiMMLTrack; … … 43 54 /** gate ratio (value of 'q' command * 0.125) */ 44 55 protected var _gateTime:Number; 56 /** Event mask (value of '@mask' command) */ 57 protected var _eventMask:Number; 45 58 /** Event trigger ID */ 46 59 protected var _eventTriggerID:int; … … 91 104 92 105 /** 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 } 95 118 96 119 /** Sound length in 16th beat, 0 sets inifinity length. @default 0. */ … … 124 147 _gateTime = (g<0) ? 0 : (g>1) ? 1 : g; 125 148 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; 126 155 } 127 156 /** Track id */ … … 158 187 if (_track) _track.channel.pan = _pan; 159 188 } 189 190 160 191 /** Channel effect send level for slot 1 (0:Minimum - 1:Maximum), this property can control track after play(). */ 161 192 public function get effectSend1() : Number { return _volumes[1] * 0.0078125; } … … 203 234 //---------------------------------------- 204 235 /** constructor. */ 205 function SoundObject(name:String = null )236 function SoundObject(name:String = null, synthesizer:SynthesizerBase = null) 206 237 { 207 238 this.name = name || ""; 208 239 _parent = null; 209 _voice = null; 240 _synthesizer = _defaultSynthesizer = new SynthesizerBase(); 241 _synthesizer._synthesizer_internal::_owner = this; 210 242 _track = null; 211 243 _tracks = null; 244 _volumes = new Vector.<int>(SiOPMModule.STREAM_SEND_SIZE); 212 245 213 246 _note = 60; … … 216 249 _quantize = 1; 217 250 218 _volumes = new Vector.<int>(SiOPMModule.STREAM_SIZE_MAX);219 251 _volumes[0] = 64; 220 for (var i:int=1; i<SiOPMModule.STREAM_S IZE_MAX; i++) _volumes[i] = 0;252 for (var i:int=1; i<SiOPMModule.STREAM_SEND_SIZE; i++) _volumes[i] = 0; 221 253 _pan = 0; 222 254 _mute = false; 255 _pitchBend = 0; 223 256 224 257 _gateTime = 0.75; 225 258 _noteShift = 0; 226 259 _pitchShift = 0; 227 _ pitchBend= 0;260 _eventMask = 0; 228 261 _eventTriggerID = 0; 229 262 _noteOnTrigger = 0; … … 243 276 // settings 244 277 //---------------------------------------- 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 245 308 /** Set event trigger. 246 309 * @param id Event trigger ID of this track. This value can be refered from SiONTrackEvent.eventTriggerID. … … 299 362 /** driver.noteOn. 300 363 * @param note playing note 301 * @param isDisposa l disposalflag.364 * @param isDisposable disposable flag. 302 365 * @return playing track 303 366 */ 304 protected function _noteOn(note:int, isDisposa l:Boolean) : SiMMLTrack367 protected function _noteOn(note:int, isDisposable:Boolean) : SiMMLTrack 305 368 { 306 369 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); 308 372 t.channel.setAllStreamSendLevels(_volumes); 309 373 t.channel.pan = _pan; 310 374 t.channel.mute = _mute; 311 375 t.channel.pitchBend = _pitchBend * 64; 312 t.quantRatio = _gateTime;313 376 t.noteShift = _noteShift; 314 377 t.pitchShift = _pitchShift * 64; 315 378 t.setEventTrigger(_eventTriggerID, _noteOnTrigger, _noteOffTrigger); 379 if (isNaN(v.gateTime)) t.quantRatio = _gateTime; 316 380 return t; 317 381 } … … 331 395 /** driver.sequenceOn() 332 396 * @param data sequence data 333 * @param isDisposal disposal flag 397 * @param isDisposable disposable flag 398 * @param applyLength 334 399 * @return vector of playing tracks 335 400 */ 336 protected function _sequenceOn(data:SiONData, isDisposa l:Boolean) : Vector.<SiMMLTrack>401 protected function _sequenceOn(data:SiONData, isDisposable:Boolean, applyLength:Boolean=true) : Vector.<SiMMLTrack> 337 402 { 338 403 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), 340 407 t:SiMMLTrack, ps:int = _pitchShift * 64, pb:int = _pitchBend * 64; 341 408 for each (t in list) { … … 344 411 t.channel.mute = _mute; 345 412 t.channel.pitchBend = pb; 346 t.quantRatio = _gateTime;347 413 t.noteShift = _noteShift; 348 414 t.pitchShift = ps; 349 415 t.setEventTrigger(_eventTriggerID, _noteOnTrigger, _noteOffTrigger); 416 if (isNaN(v.gateTime)) t.quantRatio = _gateTime; 350 417 } 351 418 return list; as3/SiOPM/trunk/src/org/si/sound/base/SoundObjectContainer.as
r3450 r3480 61 61 62 62 /** @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 */ 63 68 override public function set coarseTune(n:int) : void { 64 69 _noteShift = n; … … 121 126 // operations 122 127 //---------------------------------------- 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 123 137 /** Set all children's volume by index. 124 138 * @param slot streaming slot number. … … 130 144 for each (var sound:SoundObject in _soundList) sound.setVolume(slot, _volumes[slot]); 131 145 } 132 133 134 146 135 147 as3/SiOPM/trunk/src/org/si/sound/smf/SMFData.as
r3450 r3480 12 12 13 13 14 package org.si.sound {14 package org.si.sound.smf { 15 15 import flash.utils.ByteArray; 16 16 import org.si.sound.smf.*; as3/SiOPM/trunk/src/org/si/sound/smf/SMFTrack.as
r3450 r3480 14 14 package org.si.sound.smf { 15 15 import flash.utils.ByteArray; 16 import org.si.sound.SMFData;17 16 18 17

