チェンジセット 2607
- コミット日時:
- 2009/05/09 01:58:03 (3 年前)
- ファイル:
-
- as3/SiOPM/trunk/doc/mml_reference/siopm.js (追加)
- as3/SiOPM/trunk/doc/mml_reference/siopm_mml_ref.js (追加)
- as3/SiOPM/trunk/doc/mml_reference/siopm_mml_ref_05.html (追加)
- as3/SiOPM/trunk/doc/mml_reference/siopm_mml_ref_050.html (削除)
- as3/SiOPM/trunk/doc/mml_reference/siopm_mml_ref_050_e.html (削除)
- as3/SiOPM/trunk/doc/mml_reference/siopm_mml_ref_05_e.html (追加)
- as3/SiOPM/trunk/doc/mml_reference/siopm_sf.swf (追加)
- as3/SiOPM/trunk/samples/HelloWorld (追加)
- as3/SiOPM/trunk/samples/HelloWorld/TheABCSong.as (追加)
- as3/SiOPM/trunk/samples/SiOPMJavaScriptBridge/SiOPMJavaScriptBridge.as (更新) (5 diffs)
- as3/SiOPM/trunk/samples/SiOPMJavaScriptBridge/siopm.swf (更新) (変更前)
- as3/SiOPM/trunk/samples/SiOPMJavaScriptBridge/siopm_js.html (更新) (3 diffs)
- as3/SiOPM/trunk/samples/SiOPMKeyboard/KeyDisplay.as (更新) (3 diffs)
- as3/SiOPM/trunk/samples/SiOPMKeyboard/app.swf (更新) (変更前)
- as3/SiOPM/trunk/samples/SiOPMKeyboard/main.mxml (更新) (9 diffs)
- as3/SiOPM/trunk/src/org/si/sound/SiONData.as (更新) (1 diff)
- as3/SiOPM/trunk/src/org/si/sound/SiONDriver.as (更新) (21 diffs)
- as3/SiOPM/trunk/src/org/si/sound/SiONEvent.as (削除)
- as3/SiOPM/trunk/src/org/si/sound/SiONToneSetting.as (追加)
- as3/SiOPM/trunk/src/org/si/sound/SiONUtil.as (更新) (5 diffs)
- as3/SiOPM/trunk/src/org/si/sound/bytecode/SoundClass.as (更新) (2 diffs)
- as3/SiOPM/trunk/src/org/si/sound/driver (削除)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiCtrlFilterBase.as (更新) (8 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiCtrlFilterHighPass.as (更新) (1 diff)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiCtrlFilterLowPass.as (更新) (1 diff)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectAutoPan.as (更新) (1 diff)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectBase.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectCompressor.as (更新) (6 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectEqualiser.as (更新) (6 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectModule.as (更新) (12 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectStereoChorus.as (更新) (9 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectStereoDelay.as (更新) (7 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectTable.as (更新) (2 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectWaveShaper.as (更新) (5 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterAllPass.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterBandPass.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterBase.as (更新) (4 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterHighPass.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterLowPass.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterNotch.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterPeak.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sound/events (追加)
- as3/SiOPM/trunk/src/org/si/sound/events/SiONEvent.as (追加)
- as3/SiOPM/trunk/src/org/si/sound/events/SiONTrackEvent.as (追加)
- as3/SiOPM/trunk/src/org/si/sound/midi (追加)
- as3/SiOPM/trunk/src/org/si/sound/midi/SiMIDIModule.as (追加)
- as3/SiOPM/trunk/src/org/si/sound/midi/SiMIDITrack.as (追加)
- as3/SiOPM/trunk/src/org/si/sound/mml/MMLData.as (削除)
- as3/SiOPM/trunk/src/org/si/sound/mml/MMLEvent.as (削除)
- as3/SiOPM/trunk/src/org/si/sound/mml/MMLExecutor.as (削除)
- as3/SiOPM/trunk/src/org/si/sound/mml/MMLExecutorConnector.as (削除)
- as3/SiOPM/trunk/src/org/si/sound/mml/MMLParser.as (削除)
- as3/SiOPM/trunk/src/org/si/sound/mml/MMLParserSetting.as (削除)
- as3/SiOPM/trunk/src/org/si/sound/mml/MMLSequence.as (削除)
- as3/SiOPM/trunk/src/org/si/sound/mml/MMLSequenceGroup.as (削除)
- as3/SiOPM/trunk/src/org/si/sound/mml/MMLSequencer.as (削除)
- as3/SiOPM/trunk/src/org/si/sound/mml/SiMMLChannelSetting.as (追加)
- as3/SiOPM/trunk/src/org/si/sound/mml/SiMMLData.as (追加)
- as3/SiOPM/trunk/src/org/si/sound/mml/SiMMLEnvelopTable.as (追加)
- as3/SiOPM/trunk/src/org/si/sound/mml/SiMMLSequencer.as (追加)
- as3/SiOPM/trunk/src/org/si/sound/mml/SiMMLTable.as (追加)
- as3/SiOPM/trunk/src/org/si/sound/mml/SiMMLTrack.as (追加)
- as3/SiOPM/trunk/src/org/si/sound/mml/Translator.as (追加)
- as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelBase.as (更新) (12 diffs)
- as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelEffectDelay.as (削除)
- as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelFM.as (更新) (9 diffs)
- as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelManager.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelParam.as (更新) (6 diffs)
- as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelSampler.as (更新) (9 diffs)
- as3/SiOPM/trunk/src/org/si/sound/module/SiOPMModule.as (更新) (4 diffs)
- as3/SiOPM/trunk/src/org/si/sound/module/SiOPMOperator.as (更新) (6 diffs)
- as3/SiOPM/trunk/src/org/si/sound/module/SiOPMOperatorParam.as (更新) (5 diffs)
- as3/SiOPM/trunk/src/org/si/sound/module/SiOPMTable.as (更新) (3 diffs)
- as3/SiOPM/trunk/src/org/si/sound/mx/SiOPMPlayer.as (更新) (3 diffs)
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
as3/SiOPM/trunk/samples/SiOPMJavaScriptBridge/SiOPMJavaScriptBridge.as
r2526 r2607 6 6 7 7 import org.si.sound.*; 8 import org.si.sound.driver.Translator; 8 import org.si.sound.events.*; 9 import org.si.sound.mml.Translator; 9 10 10 11 … … 43 44 44 45 // register handlers 45 driver.addEventListener(SiONEvent. COMPILE_PROGRESS, _onCompileProgress);46 driver.addEventListener(SiONEvent. COMPILE_COMPLETE, _onCompileComplete);47 driver.addEventListener(ErrorEvent.ERROR, _onError);48 driver.addEventListener(SiONEvent.STREAM, _onStream);49 driver.addEventListener(SiONEvent.STREAM_START, _onStreamStart);50 driver.addEventListener(SiONEvent.STREAM_STOP, _onStreamStop);46 driver.addEventListener(SiONEvent.QUEUE_PROGRESS, _onCompileProgress); 47 driver.addEventListener(SiONEvent.QUEUE_COMPLETE, _onCompileComplete); 48 driver.addEventListener(ErrorEvent.ERROR, _onError); 49 driver.addEventListener(SiONEvent.STREAM, _onStream); 50 driver.addEventListener(SiONEvent.STREAM_START, _onStreamStart); 51 driver.addEventListener(SiONEvent.STREAM_STOP, _onStreamStop); 51 52 52 53 // callback onLoad … … 59 60 // event handlers 60 61 //-------------------------------------------------- 61 private function _onCompileProgress(e:SiONEvent) : void { ExternalInterface.call('SIOPM._internal_onCompileProgress', driver. compileProgress); }62 private function _onCompileProgress(e:SiONEvent) : void { ExternalInterface.call('SIOPM._internal_onCompileProgress', driver.jobProgress); } 62 63 private function _onError(e:ErrorEvent) : void { ExternalInterface.call('SIOPM._internal_onError', e.text); } 63 64 private function _onStream(e:SiONEvent) : void { ExternalInterface.call('SIOPM._internal_onStream'); } … … 74 75 { 75 76 if (mml) { 76 driver.compile(mml, 200, data); 77 driver.compileQueue(mml, data); 78 driver.startQueue(200); 77 79 return true; 78 80 } … … 124 126 import org.si.sound.*; 125 127 class pcmExample { 126 [Embed(source="hit.mp3")] var hit_mp3:Class;127 [Embed(source="kick.mp3")] var kick_mp3:Class;128 [Embed(source="sdw.mp3")] var sdw_mp3:Class;129 [Embed(source="sds.mp3")] var sds_mp3:Class;130 [Embed(source="toml.mp3")] var toml_mp3:Class;131 [Embed(source="tomh.mp3")] var tomh_mp3:Class;132 [Embed(source="hatc.mp3")] var hatc_mp3:Class;133 [Embed(source="hath.mp3")] var hath_mp3:Class;134 [Embed(source="hato.mp3")] var hato_mp3:Class;135 [Embed(source="crash.mp3")] var crash_mp3:Class;136 [Embed(source="bell.mp3")] var bell_mp3:Class;128 [Embed(source="hit.mp3")] private var hit_mp3:Class; 129 [Embed(source="kick.mp3")] private var kick_mp3:Class; 130 [Embed(source="sdw.mp3")] private var sdw_mp3:Class; 131 [Embed(source="sds.mp3")] private var sds_mp3:Class; 132 [Embed(source="toml.mp3")] private var toml_mp3:Class; 133 [Embed(source="tomh.mp3")] private var tomh_mp3:Class; 134 [Embed(source="hatc.mp3")] private var hatc_mp3:Class; 135 [Embed(source="hath.mp3")] private var hath_mp3:Class; 136 [Embed(source="hato.mp3")] private var hato_mp3:Class; 137 [Embed(source="crash.mp3")] private var crash_mp3:Class; 138 [Embed(source="bell.mp3")] private var bell_mp3:Class; 137 139 138 140 139 141 function pcmExample(driver:SiONDriver) 140 142 { 141 driver.setPCMData (0, SiONUtil.serializeSound(new hit_mp3()));142 driver.setWaveData(60, SiONUtil.getRawData(new kick_mp3())); //o5c143 driver.setWaveData(62, SiONUtil.getRawData(new sdw_mp3())); //o5d144 driver.setWaveData(64, SiONUtil.getRawData(new sds_mp3())); //o5e145 driver.setWaveData(65, SiONUtil.getRawData(new toml_mp3())); //o5f146 driver.setWaveData(67, SiONUtil.getRawData(new tomh_mp3())); //o5g147 driver.setWaveData(48, SiONUtil.getRawData(new hatc_mp3())); //o4c148 driver.setWaveData(50, SiONUtil.getRawData(new hath_mp3())); //o4d149 driver.setWaveData(52, SiONUtil.getRawData(new hato_mp3())); //o4e150 driver.setWaveData(53, SiONUtil.getRawData(new crash_mp3())); //o4f151 driver.setWaveData(55, SiONUtil.getRawData(new bell_mp3())); //o4g143 driver.setPCMData(0, new hit_mp3()); 144 driver.setWaveData(60, new kick_mp3()); //o5c 145 driver.setWaveData(62, new sdw_mp3()); //o5d 146 driver.setWaveData(64, new sds_mp3()); //o5e 147 driver.setWaveData(65, new toml_mp3()); //o5f 148 driver.setWaveData(67, new tomh_mp3()); //o5g 149 driver.setWaveData(48, new hatc_mp3()); //o4c 150 driver.setWaveData(50, new hath_mp3()); //o4d 151 driver.setWaveData(52, new hato_mp3()); //o4e 152 driver.setWaveData(53, new crash_mp3()); //o4f 153 driver.setWaveData(55, new bell_mp3()); //o4g 152 154 } 153 155 } 154 156 */ 157 as3/SiOPM/trunk/samples/SiOPMJavaScriptBridge/siopm_js.html
r2526 r2607 3 3 <meta http-equiv='content-type' content='text/html;charset=utf-8'> 4 4 <title>SiOPM on javascript</title> 5 <script type= "text/javascript" src="jquery.js"></script>6 <script type= "text/javascript" src="siopm.js"></script>5 <script type='text/javascript' src='../script/jquery.js'></script> 6 <script type='text/javascript' src='../script/siopm.js'></script> 7 7 <script type="text/javascript"><!-- 8 8 function translate() { … … 41 41 }); 42 42 //--></script> 43 <script type="text/javascript"> 44 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); 45 document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); 46 </script> 47 <script type="text/javascript"> 48 try { 49 var pageTracker = _gat._getTracker("UA-4060125-4"); 50 pageTracker._trackPageview(); 51 } catch(err) {}</script> 43 52 44 53 </head> … … 47 56 <input type="button" onClick="translate();" disabled="true" value="tss"/> 48 57 <span id="msg">Please Enable the JavaScript.</span><br/> 49 <a href=" siopm_mml_ref_050.html" target="_blank">MML reference</a><br/>50 <textarea id="ta" style="height: 90%; width:100%; font-size:12px; font-family:MS Gothic, monospace;">58 <a href="http://mmltalks.appspot.com/document/siopm_mml_ref_05.html" target="_blank">MML reference</a><br/> 59 <textarea id="ta" style="height:80%; width:100%; font-size:12px; font-family:MS Gothic, monospace;"> 51 60 #TITLE{Penetration SCC version (From TSSCP thread STG3 930-932 by ID:A7Ri5mEU)}; 52 61 #WAVB0{36454d4b41362f303639332309efd9cc362f220df2d9c8c3c6cbccc6bab0aeb7}; as3/SiOPM/trunk/samples/SiOPMKeyboard/KeyDisplay.as
r2526 r2607 10 10 private var tf0:TextField = setTextField.constant(new TextField(), {text:"<q", color:0, font:'_sans', bold:true, x:0}); 11 11 private var tf1:TextField = setTextField.constant(new TextField(), {text:"w>", color:0, font:'_sans', bold:true, x:220}); 12 private var keys:Vector.<Sprite> = new Vector.<Sprite>(17, true); 12 private var keys :Vector.<Sprite> = new Vector.<Sprite>(17, true); 13 private var keyOn:Vector.<Shape> = new Vector.<Shape>(17, true); 13 14 14 15 function KeyDisplay() … … 21 22 } 22 23 23 public function noteOn( ) : void24 public function noteOn(key:int) : void 24 25 { 25 26 while (key<0) key += 12; 27 while (key>16) key -= 12; 28 keyOn[key].visible = true; 26 29 } 27 30 28 public function noteOff( ) : void31 public function noteOff(key:int) : void 29 32 { 30 33 while (key<0) key += 12; 34 while (key>16) key -= 12; 35 keyOn[key].visible = false; 31 36 } 32 37 … … 41 46 pk = wk[k]; 42 47 keys[k] = new Sprite(); 48 keyOn[k] = new Shape(); 43 49 if (wk[k]==0) { // white 44 50 keys[k].graphics.beginFill(0xffffff); 51 keyOn[k].graphics.beginFill(0x000080, 0.5); 45 52 tf = setTextField.constant(new TextField(), {text:kt[k], color:0, font:'_sans', bold:true, x:5, y:80}); 46 53 } else { // black 47 54 keys[k].graphics.beginFill(0x404040); 55 keyOn[k].graphics.beginFill(0x8080ff, 0.5); 48 56 tf = setTextField.constant(new TextField(), {text:kt[k], color:0xffffff, font:'_sans', bold:true, x:5, y:50}); 49 57 } 58 keyOn[k].graphics.drawPath(cmd, vts[wk[k]]); 59 keyOn[k].graphics.endFill(); 60 keyOn[k].visible = false; 50 61 keys[k].graphics.lineStyle(3, 0x000000); 51 62 keys[k].graphics.drawPath(cmd, vts[wk[k]]); 52 63 keys[k].graphics.endFill(); 53 64 keys[k].addChild(tf); 65 keys[k].addChild(keyOn[k]); 54 66 keys[k].x = x; 55 67 if (wk[k]==0) addChild(keys[k]); as3/SiOPM/trunk/samples/SiOPMKeyboard/main.mxml
r2526 r2607 17 17 import org.si.utils.SiOPMChannelParamModify; 18 18 import org.si.sound.*; 19 import org.si.sound.events.*; 19 20 import org.si.sound.module.SiOPMChannelParam; 20 import org.si.sound. driver.SiMMLSequencerTrack;21 import org.si.sound.mml.SiMMLTrack; 21 22 import org.si.sound.effect.SiEffectStereoDelay; 22 23 import org.si.sound.effect.SiEffectStereoChorus; … … 25 26 // variables 26 27 //------------------------------ 27 static public var _p:SiOPMChannelParam;28 28 static private var _fileSystem:TextFileSystem = new TextFileSystem(); 29 29 static private var _dataManager:DataManager; 30 30 static private var _driver:SiONDriver; 31 32 static private var _toneSetting:SiONToneSetting; 31 33 static private var _keyFlag:uint; 32 34 static private var _keyTable:Vector.<int>; … … 37 39 38 40 39 // handlers41 // initializer 40 42 //------------------------------ 41 43 private function _onCreate() : void 42 44 { 45 // initialize instances 43 46 _fileSystem = new TextFileSystem(); 44 47 _dataManager = new DataManager(_fileSystem, "/bin/DataManager/data"); 45 _driver = new SiONDriver(2, 44100, 16, 2048, true); 46 _driver.addEventListener(SiONEvent.STREAM_START, _onStreamStart); 47 // _driver.addEventListener(SiONEvent.STREAM, _onStream); 48 _driver = new SiONDriver(); 49 _driver.debugMode = true; 50 _delaySend = 0.25; 51 _chorusSend = 0; 52 48 53 _driver.addEventListener(ErrorEvent.ERROR, _onError); 49 50 // set effectors 54 _driver.addEventListener(SiONTrackEvent.NOTE_ON_FRAME, _onNoteOnFrame); 55 _driver.addEventListener(SiONTrackEvent.NOTE_OFF_FRAME, _onNoteOffFrame); 56 57 // tone setting 58 _toneSetting = new SiONToneSetting(); 59 60 // effector setting 51 61 var dly:SiEffectStereoDelay = new SiEffectStereoDelay(); 52 var cho:SiEffectStereoChorus = new SiEffectStereoChorus();53 62 dly.initialize(); 54 63 dly.setParameters(200,0.2,false); 64 var cho:SiEffectStereoChorus = new SiEffectStereoChorus(); 55 65 cho.initialize(); 56 66 cho.setParameters(20,0.2,4,20); 67 68 // connect effectors 57 69 _driver.effector.initialize(); 58 70 _driver.effector.connect(1, dly); 59 71 _driver.effector.connect(2, cho); 60 _delaySend = 0.25;61 _chorusSend = 0;62 72 63 73 // keyboard listener … … 84 94 _onFileSelectorChange(); 85 95 86 // start stream without data (null) and effectors reset(false).96 // start stream without data 87 97 _driver.play(null, false); 88 98 } 89 99 100 90 101 // operations 91 102 //------------------------------ 92 103 private function _allNoteOff() : void 93 104 { 94 for (var i:int=0; i<32; i++) { 95 _driver.noteOff(i+_baseNote); 96 } 105 for (var i:int=0; i<32; i++) _driver.noteOff(i+_baseNote); 97 106 } 98 107 … … 106 115 // driver events 107 116 //------------------------------ 108 private function _onStreamStart(e:SiONEvent) : void 109 { 110 } 111 112 private function _onStream(e:SiONEvent) : void 113 { 117 private function _onNoteOnFrame(e:SiONTrackEvent) : void 118 { 119 keyboard.noteOn(e.note-_baseNote); 120 } 121 122 private function _onNoteOffFrame(e:SiONTrackEvent) : void 123 { 124 keyboard.noteOff(e.note-_baseNote); 114 125 } 115 126 … … 129 140 if ((_keyFlag & flag) == 0) { 130 141 _keyFlag |= flag; 131 var trk:SiMML SequencerTrack = _driver.noteOn(i+_baseNote, _p);142 var trk:SiMMLTrack = _driver.noteOn(i+_baseNote, _toneSetting, 0, 0, 0, 0, 0, 1, 1); 132 143 trk.channel.setStreamSend(1, _delaySend); 133 144 trk.channel.setStreamSend(2, _chorusSend); … … 147 158 _allNoteOff(); 148 159 _baseNote -= 12; 149 if (_baseNote< 36) _baseNote = 36;160 if (_baseNote<24) _baseNote = 24; 150 161 break; 151 162 } 152 163 } 153 164 } 154 155 165 156 166 private function _onKeyUp(e:KeyboardEvent) : void 157 167 { … … 178 188 } 179 189 180 181 190 private function _onChannelSelectorChange() : void 182 191 { 183 192 if (chSelect.selectedItem == null) return; 184 193 var idx:int = chSelect.selectedItem.index; 185 _ p= _dataManager.getParameter(idx);186 } 187 194 _toneSetting.channelParam = _dataManager.getParameter(idx); 195 } 196 188 197 private function _onChannelSelectorClose() : void 189 198 { 190 199 stage.focus = keyboard; 191 200 } 192 193 private function dragDelay(e:SliderEvent) : void 194 { 195 _delaySend = e.value*0.01; 196 var i:int, imax:int = _driver.trackCount; 197 for (i=0; i<imax; i++) _driver.getTrack(i).channel.setStreamSend(1, _delaySend); 198 } 199 200 private function dragChorus(e:SliderEvent) : void 201 { 202 _chorusSend = e.value*0.01; 203 var i:int, imax:int = _driver.trackCount; 204 for (i=0; i<imax; i++) _driver.getTrack(i).channel.setStreamSend(2, _chorusSend); 201 202 private function changeEffectSend() : void 203 { 204 _delaySend = delaySend.value * 0.01; 205 _chorusSend = chorusSend.value * 0.01; 206 for each (var trk:SiMMLTrack in _driver.sequencer.tracks) { 207 trk.channel.setStreamSend(1, _delaySend); 208 trk.channel.setStreamSend(2, _chorusSend); 209 } 205 210 } 206 211 ]]> … … 217 222 close ="_onChannelSelectorClose();"/> 218 223 <mx:HBox height="16" horizontalGap="0"> 219 <mx:HSlider id="delaySend" width="120" height="16" maximum="100" tickInterval="10" snapInterval="5" value="25" toolTip="Delay send" thumbDrag="dragDelay(event);"/>220 <mx:HSlider id="chorusSend" width="120" height="16" maximum="100" tickInterval="10" snapInterval="5" value="0" toolTip="Chorus send" thumbDrag="dragChorus(event);"/>224 <mx:HSlider id="delaySend" width="120" height="16" maximum="100" tickInterval="10" snapInterval="5" value="25" toolTip="Delay send" change="changeEffectSend();"/> 225 <mx:HSlider id="chorusSend" width="120" height="16" maximum="100" tickInterval="10" snapInterval="5" value="0" toolTip="Chorus send" change="changeEffectSend();"/> 221 226 </mx:HBox> 222 227 <my:KeyDisplay id="keyboard" addedToStage="stage.focus = this;"/> as3/SiOPM/trunk/src/org/si/sound/SiONData.as
r2526 r2607 11 11 import flash.media.*; 12 12 import flash.utils.ByteArray; 13 import org.si.sound. driver.SiMMLData;13 import org.si.sound.mml.SiMMLData; 14 14 import org.si.sound.module.SiOPMTable; 15 15 import org.si.utils.SLLint; as3/SiOPM/trunk/src/org/si/sound/SiONDriver.as
r2526 r2607 14 14 import flash.media.SoundChannel; 15 15 import flash.media.SoundTransform; 16 import flash.display. Sprite;16 import flash.display.*; 17 17 import flash.utils.getTimer; 18 18 import flash.utils.ByteArray; … … 20 20 import org.si.utils.SLLint; 21 21 import org.si.utils.SLLNumber; 22 import org.si.sound.driver.SiMMLSequencer; 23 import org.si.sound.driver.SiMMLSequencerTrack; 22 import org.si.sound.mml.SiMMLSequencer; 23 import org.si.sound.mml.SiMMLTrack; 24 import org.si.sound.mml.SiMMLEnvelopTable; 25 import org.si.sound.mml.SiMMLTable; 24 26 import org.si.sound.module.SiOPMTable; 25 27 import org.si.sound.module.SiOPMModule; 26 28 import org.si.sound.module.SiOPMChannelParam; 27 29 import org.si.sound.effect.SiEffectModule; 30 import org.si.sound.events.*; 28 31 29 32 … … 31 34 32 35 /** SiON driver class.<br/> 33 * -- BASIC USAGE --<br/> 34 * 1) Create new SiONDriver.<br/> 35 * 2) addChild the instance of SiONDriver onto the stage or stage's descendant.<br/> 36 * 3) addEventListner(SiONEvent.COMPILE_COMPLETE) to catch the finished timing of compile, and call compile("mmlString").<br/> 37 * 4) After the compiling (lets say, in the callback of the SiONEvent.COMPILE_COMPLETE event), call play() to start playing sound.<br/> 38 * 5) Call stop() to stop the sound.<br/> 36 * @see SiONData 37 * @see SiONToneSetting 38 * @see org.si.sound.events.SiONEvent 39 * @see org.si.sound.events.SiONTrackEvent 40 * @see org.si.sound.module.SiOPMModule 41 * @see org.si.sound.mml.SiMMLSequencer 42 * @see org.si.sound.effect.SiEffectModule 43 @example 1) The simplest sample. Create new instance and call play with MML string.<br/> 44 <listing version="3.0"> 45 // create driver instance. 46 public var driver = new SiONDriver(); 47 ... 48 // call play() with mml string whenever you want to play sound. 49 driver.play("t100 l8 [ ccggaag4 ffeeddc4 | [ggffeed4]2 ]2"); 50 </listing> 39 51 */ 40 52 public class SiONDriver extends Sprite … … 43 55 //---------------------------------------- 44 56 /** version number */ 45 static public const VERSION:String = "0.5.0"; 57 static public const VERSION:String = "0.5.1"; 58 46 59 47 60 // event listener type 48 61 private const NO_LISTEN:int = 0; 49 private const LISTEN_ COMPILE:int = 1;62 private const LISTEN_QUEUE:int = 1; 50 63 private const LISTEN_PROCESS:int = 2; 51 64 … … 58 71 // valiables 59 72 //---------------------------------------- 60 /** sound module. */73 /** SiOPM sound module. */ 61 74 public var module:SiOPMModule; 62 75 63 /** effector . */76 /** effector module. */ 64 77 public var effector:SiEffectModule; 65 78 66 /** mml sequencer . */79 /** mml sequencer module. */ 67 80 public var sequencer:SiMMLSequencer; 68 81 69 // protected: 70 protected var _data:SiONData; // data to compile or process 71 protected var _mmlString:String; // mml string of previous compiling 72 protected var _sound:Sound; // sound stream instance 73 protected var _soundChannel:SoundChannel; // sound channel instance 74 protected var _soundTransform:SoundTransform; // sound transform 75 76 protected var _channelCount:int; // module output channels (1 or 2) 77 protected var _sampleRate:int; // module output frequency ratio (44100 or 22050) 78 protected var _bitRate:int; // module output bitrate (0 or 8 or 16) 79 protected var _bufferLength:int; // module and streaming buffer size (8192, 4096 or 2048) 80 protected var _throwErrorEvent:Boolean; // true; throw ErrorEvent, false; throw Error 81 82 protected var _compileInterval:int // interrupting interval in compile 83 protected var _compileProgress:Number; // progression of compile on this que 84 protected var _isPaused:Boolean; // flag to pause 85 protected var _position:Number; // start position [ms] 86 87 protected var _timeCompile:int; // total compile time. 88 protected var _timeProcess:int; // averge time process in 1sec. 89 protected var _timeProcessTotal:int; // total processing time in last 8 bufferings. 90 protected var _timeProcessData:SLLint; // processing time data of last 8 bufferings. 91 protected var _timeProcessAveRatio:Number;// number to averaging _timeProcessTotal 92 protected var _timePrevStream:int; // previous streaming time. 93 protected var _latency:Number; // streaming latency [ms] 94 95 protected var _listenEvent:int; // current lintening event 96 97 static protected var _compileQue:Vector.<SiONCompileQue> = null; // compiling que 82 83 // private: 84 private var _data:SiONData; // data to compile or process 85 private var _mmlString:String; // mml string of previous compiling 86 private var _sound:Sound; // sound stream instance 87 private var _soundChannel:SoundChannel; // sound channel instance 88 private var _soundTransform:SoundTransform; // sound transform 89 90 private var _channelCount:int; // module output channels (1 or 2) 91 private var _sampleRate:int; // module output frequency ratio (44100 or 22050) 92 private var _bitRate:int; // module output bitrate (0 or 8 or 16) 93 private var _bufferLength:int; // module and streaming buffer size (8192, 4096 or 2048) 94 private var _debugMode:Boolean; // true; throw Error, false; throw ErrorEvent 95 private var _dispatchStreamEvent:Boolean; // dispatch steam event 96 private var _cannotChangeBPM:Boolean; // internal flag not to change bpm 97 98 private var _queueInterval:int; // interupting interval to execute queued jobs 99 private var _queueLength:int; // queue length to execute 100 private var _jobProgress:Number; // progression of current job 101 private var _currentJob:int; // current job 0=no job, 1=compile, 2=render 102 103 104 private var _isPaused:Boolean; // flag to pause 105 private var _position:Number; // start position [ms] 106 107 private var _triggerEventQueue:Vector.<SiONTrackEvent>; 108 109 private var _renderBuffer:Vector.<Number>; // rendering buffer 110 private var _renderBufferIndex:int; // rendering buffer writing index 111 private var _renderBufferSizeMax:int; // maximum value of rendering buffer size 112 113 private var _timeCompile:int; // previous compiling time. 114 private var _timeRender:int; // previous rendering time. 115 private var _timeProcess:int; // averge processing time in 1sec. 116 private var _timeProcessTotal:int; // total processing time in last 8 bufferings. 117 private var _timeProcessData:SLLint; // processing time data of last 8 bufferings. 118 private var _timeProcessAveRatio:Number;// number to averaging _timeProcessTotal 119 private var _timePrevStream:int; // previous streaming time. 120 private var _latency:Number; // streaming latency [ms] 121 private var _prevFrameTime:int; // previous frame time 122 private var _frameRate:int; // frame rate 123 124 private var _eventListenerPrior:int; // event listeners priority 125 private var _listenEvent:int; // current lintening event 126 127 static private var _jobQueue:Vector.<SiONDriverJob> = null; // compiling/rendering jobs queue 98 128 99 129 … … 103 133 //---------------------------------------- 104 134 // data 105 /** MML string . This property is only available during compile. */135 /** MML string (this property is only available during compile). */ 106 136 public function get mmlString() : String { return _mmlString; } 107 137 108 /** Data to compile and process. */138 /** Data to compile, render and process. */ 109 139 public function get data() : SiONData { return _data; } 110 140 … … 117 147 118 148 // paramteters 119 /** Track count. This value is only available after play(). */ 120 public function get trackCount() : int { return sequencer.trackCount; } 149 /** Track count, this value is only available after play(). */ 150 public function get trackCount() : int { return sequencer.tracks.length; } 151 152 /** Streaming buffer length. */ 153 public function get bufferLength() : int { return _bufferLength; } 121 154 122 155 /** Sound volume. */ … … 130 163 public function get pan() : Number { return _soundTransform.pan; } 131 164 public function set pan(p:Number) : void { 132 _soundTransform.pan = p; 165 _soundTransform.pan = p; 133 166 if (_soundChannel) _soundChannel.soundTransform = _soundTransform; 134 167 } … … 136 169 137 170 // measured time 138 /** total compiling time. [ms]*/171 /** previous compiling time [ms]. */ 139 172 public function get compileTime() : int { return _timeCompile; } 140 173 141 /** average processing time per 1sec. [ms] */ 174 /** previous rendering time [ms]. */ 175 public function get renderTime() : int { return _timeRender; } 176 177 /** average processing time in 1sec [ms]. */ 142 178 public function get processTime() : int { return _timeProcess; } 143 179 144 /** compiling progression in one que. 0=start -> 1=finish. */ 145 public function get compileProgress() : Number { return _compileProgress; } 146 147 /** compiling que length. */ 148 public function get compileQueLength() : int { return _compileQue.length; } 149 150 /** streaming latency */ 180 /** progression of current compiling/rendering (0=start -> 1=finish). */ 181 public function get jobProgress() : Number { return _jobProgress; } 182 183 /** progression of all queued jobs (0=start -> 1=finish). */ 184 public function get jobQueueProgress() : Number { 185 if (_queueLength == 0) return 1; 186 return (_queueLength - _jobQueue.length - 1 + _jobProgress) / _queueLength; 187 } 188 189 /** compiling/rendering jobs queue length. */ 190 public function get jobQueueLength() : int { return _jobQueue.length; } 191 192 /** streaming latency [ms]. */ 151 193 public function get latency() : Number { return _latency; } 152 194 153 195 154 // flag 155 /** Is compiling ? */156 public function get is Compiling() : Boolean { return (_compileProgress>0 && _compileProgress<1); }196 // flags 197 /** Is job executing ? */ 198 public function get isJobExecuting() : Boolean { return (_jobProgress>0 && _jobProgress<1); } 157 199 158 200 /** Is playing sound ? */ … … 173 215 } 174 216 217 /** Beat par minute. */ 218 public function get bpm() : Number { 219 return (sequencer.isReadyToProcess) ? sequencer.bpm : sequencer.setting.defaultBPM; 220 } 221 public function set bpm(t:Number) : void { 222 if (sequencer.isReadyToProcess) { 223 if (_cannotChangeBPM) throw errorCannotChangeBPM(); 224 sequencer.bpm = t; 225 } else { 226 sequencer.setting.defaultBPM = t; 227 } 228 } 229 230 /** Debug mode, true; throw Error / false; throw ErrorEvent when error appears. */ 231 public function get debugMode() : Boolean { return _debugMode; } 232 public function set debugMode(mode:Boolean) : void { _debugMode = mode; } 233 175 234 176 235 … … 178 237 // constructor 179 238 //---------------------------------------- 180 /** Create driver to manage the SiOPM module, compiler and sequencer. 239 /** Create driver to manage the sound module, sequencer and effectors. 240 * @param bufferLength Buffer size of sound stream. 8192, 4096 or 2048 is available, but no check. 181 241 * @param channel Channel count. 1 or 2 is available. 182 242 * @param sampleRate Sampling ratio of wave. 22050 or 44100 is available. 183 243 * @param bitRate Bit ratio of wave. 0, 8 or 16 is available. 0 means float value [-1 to 1]. 184 * @param bufferLength Buffer size of sound stream. 8192, 4096 or 2048 is available, but no check. 185 * @param throwErrorEvent true; throw ErrorEvent when it errors. false; throw Error when it errors. 186 */ 187 function SiONDriver(channelCount:int=2, sampleRate:int=44100, bitRate:int=0, bufferLength:int=8192, throwErrorEvent:Boolean=true) 188 { 189 if (!_compileQue) _compileQue = new Vector.<SiONCompileQue>(); 244 * @param frameRate frame rate of stage. 245 */ 246 function SiONDriver(bufferLength:int=2048, channelCount:int=2, sampleRate:int=44100, bitRate:int=0) 247 { 248 if (!_jobQueue) _jobQueue = new Vector.<SiONDriverJob>(); 190 249 191 250 module = new SiOPMModule(); 192 251 effector = new SiEffectModule(module); 193 sequencer = new SiMMLSequencer(module );252 sequencer = new SiMMLSequencer(module, _callbackEventTriggerOn, _callbackEventTriggerOff); 194 253 _sound = new Sound(); 195 254 _soundTransform = new SoundTransform(); 196 255 197 256 // initialize 198 _throwErrorEvent = throwErrorEvent;199 200 257 _channelCount = channelCount; 201 258 _sampleRate = 44100; // sampleRate; 44100 is only available now. … … 203 260 _bufferLength = bufferLength; 204 261 _listenEvent = NO_LISTEN; 262 _dispatchStreamEvent = false; 263 _cannotChangeBPM = false; 264 _debugMode = false; 205 265 206 266 _soundTransform.volume = 1; … … 208 268 _position = 0; 209 269 210 _compileInterval = 0; 211 _compileProgress = 0; 270 _eventListenerPrior = 1; 271 _triggerEventQueue = new Vector.<SiONTrackEvent>(); 272 273 _queueInterval = 500; 274 _jobProgress = 0; 275 _currentJob = 0; 276 _queueLength = 0; 212 277 213 278 _timeCompile = 0; … … 217 282 _timePrevStream = 0; 218 283 _latency = 0; 284 _prevFrameTime = 0; 285 _frameRate = 1; 219 286 220 287 _mmlString = null; … … 229 296 230 297 231 // operations for data 232 //---------------------------------------- 233 /** Compile the MML string. 234 * After calling this function, the SiONEvent.COMPILE_PROGRESS, SiONEvent.COMPILE_COMPLETE and ErrorEvent.ERROR events will be dispatched.<br/> 235 * The SiONEvent.COMPILE_PROGRESS is dispatched when it's compiling in the interval of the argument "interval".<br/> 236 * The SiONEvent.COMPILE_COMPLETE is dispatched when the compile is finished successfully.<br/> 298 // interfaces for data preparation 299 //---------------------------------------- 300 /** Compile MML string immeriately. 301 * @param mml MML string to compile. 302 * @param data SiONData to compile. The SiONDriver creates new SiONData instance when this argument is null. 303 * @return Compiled data. 304 */ 305 public function compile(mml:String, data:SiONData=null) : SiONData 306 { 307 try { 308 // stop sound 309 stop(); 310 311 // compile immediately 312 var t:int = getTimer(); 313 _prepareCompile(mml, data); 314 _jobProgress = sequencer.compile(0); 315 _timeCompile = getTimer() - t; 316 _mmlString = null; 317 } catch(e:Error) { 318 // error 319 if (_debugMode) throw e; 320 else dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 321 } 322 323 return _data; 324 } 325 326 327 /** Push queue job to compile MML string. Start compiling after calling startQueue.<br/> 328 * @param mml MML string to compile. 329 * @param data SiONData to compile. 330 * @return Queue length. 331 * @see #startQueue() 332 */ 333 public function compileQueue(mml:String, data:SiONData) : int 334 { 335 if (mml == null || data == null) return _jobQueue.length; 336 return _jobQueue.push(new SiONDriverJob(mml, null, data)); 337 } 338 339 340 341 342 // interfaces for sound rendering 343 //---------------------------------------- 344 /** Render sound immeriately. 345 * @param data SiONData or mml String to play. 346 * @param renderBuffer Rendering target. null to create new buffer. The length of renderBuffer limits rendering length except for 0. 347 * @param resetEffector reset all effectors before play data. 348 * @return rendered data. 349 */ 350 public function render(data:*, renderBuffer:Vector.<Number>=null, resetEffector:Boolean=true) : Vector.<Number> 351 { 352 try { 353 // stop sound 354 stop(); 355 356 // rendering immediately 357 var t:int = getTimer(); 358 if (resetEffector) effector.initialize(); 359 _prepareRender(data, renderBuffer); 360 while(true) { if (_rendering()) break; } 361 _timeRender = getTimer() - t; 362 } catch (e:Error) { 363 // error 364 _removeAllEventListners(); 365 if (_debugMode) throw e; 366 else dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 367 } 368 369 return _renderBuffer; 370 } 371 372 373 /** Push queue job to render sound. Start rendering after calling startQueue.<br/> 374 * @param data SiONData or mml String to render. 375 * @param renderBuffer Rendering target. The length of renderBuffer limits rendering length except for 0. 376 * @return Queue length. 377 * @see #startQueue() 378 */ 379 public function renderQueue(data:*, renderBuffer:Vector.<Number>) : int 380 { 381 if (data == null || renderBuffer == null) return _jobQueue.length; 382 383 if (data is String) { 384 var compiled:SiONData = new SiONData(); 385 _jobQueue.push(new SiONDriverJob(data as String, null, compiled)); 386 return _jobQueue.push(new SiONDriverJob(null, renderBuffer, compiled)); 387 } else 388 if (data is SiONData) { 389 return _jobQueue.push(new SiONDriverJob(null, renderBuffer, data as SiONData)); 390 } 391 392 var e:Error = errorDataIncorrect(); 393 if (_debugMode) throw e; 394 else dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 395 return _jobQueue.length; 396 } 397 398 399 400 401 // interfaces for jobs queue 402 //---------------------------------------- 403 /** Execute all elements of queue pushed by compileQueue and renderQueue. 404 * After calling this function, the SiONEvent.QUEUE_PROGRESS, SiONEvent.QUEUE_COMPLETE and ErrorEvent.ERROR events will be dispatched.<br/> 405 * The SiONEvent.QUEUE_PROGRESS is dispatched when it's executing queued job.<br/> 406 * The SiONEvent.QUEUE_COMPLETE is dispatched when finish all queued jobs.<br/> 237 407 * The ErrorEvent.ERROR is dispatched when some error appears during the compile.<br/> 238 * @param mml MML string to compile. 239 * @param interavl Interval to interrupt compiling [ms]. The value of 0 sets no interruption and returns SiONData immediately. 240 * @param data SiONData to compile. The SiONDriver creates new SiONData instance when this argument is null. 241 * @return This function returns compiled data only when the argument "interval" set to 0, and returns null in other cases. 242 */ 243 public function compile(mml:String, interval:int=0, data:SiONData=null) : SiONData 244 { 245 // stop sound 408 * @param interval Interupting interval 409 * @return Queue length. 410 * @see #compileQueue() 411 * @see #renderQueue() 412 */ 413 public function startQueue(interval:int=500) : int 414 { 246 415 stop(); 247 416 _queueLength = _jobQueue.length; 417 if (_jobQueue.length > 0) { 418 _queueInterval = interval; 419 _executeNextJob(); 420 _queue_addAllEventListners(); 421 } 422 return _queueLength; 423 } 424 425 426 427 428 // interfaces for sound streaming 429 //---------------------------------------- 430 /** Play sound. 431 * @param data SiONData or mml String to play. You can pass null when resume after pause or streaming without any data. 432 * @param resetEffector reset all effectors before play data. 433 * @return SoundChannel instance to play data. This instance is same as soundChannel property. 434 * @see #soundChannel 435 */ 436 public function play(data:*=null, resetEffector:Boolean=true) : SoundChannel 437 { 248 438 try { 249 if (interval > 0) { 250 // push compile que 251 _pushCompileQue(mml, interval, data); 252 _compile_addAllEventListners(); 439 if (_isPaused) { 440 _isPaused = false; 253 441 } else { 254 // compile immediately 255 var t:int = getTimer(); 256 _prepareCompile(mml, 0, data); 257 _compileProgress = sequencer.compile(0); 258 _timeCompile += getTimer() - t; 259 return _data; 442 // stop sound 443 stop(); 444 445 // preparation 446 if (resetEffector) effector.initialize(); 447 _prepareProcess(data); 448 449 // dispatch streaming start event 450 var event:SiONEvent = new SiONEvent(SiONEvent.STREAM_START, this, null, true); 451 dispatchEvent(event); 452 if (event.isDefaultPrevented()) return null; // canceled 453 454 // set position 455 if (_data && _position > 0) { sequencer.dummyProcess(_position * _sampleRate * 0.001); } 456 457 // start stream 458 _process_addAllEventListners(); 459 _soundChannel = _sound.play(); 460 _soundChannel.soundTransform = _soundTransform; 461 462 // initialize 463 _timeProcessTotal = 0; 464 for (var i:int=0; i<TIME_AVARAGING_COUNT; i++) { 465 _timeProcessData.i = 0; 466 _timeProcessData = _timeProcessData.next; 467 } 468 _isPaused = false; 260 469 } 261 470 } catch(e:Error) { 262 471 // error 263 if (_throwErrorEvent) dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 264 else throw e; 265 } 266 267 return null; 268 } 269 270 271 272 273 // operations for sound 274 //---------------------------------------- 275 /** Play sound. 276 * @param data Data to play. You can pass null when resume after pause. 277 * @param resetEffector Reset effector before play data. 278 */ 279 public function play(data:SiONData=null, resetEffector:Boolean=true) : void 280 { 281 if (_isPaused) { 282 _isPaused = false; 283 } else { 284 _data = data; 285 286 // stop sound 287 stop(); 288 289 // preparation 290 if (resetEffector) effector.initialize(); 291 module.initialize(_channelCount, _bufferLength); 292 sequencer.prepareProcess(_data, _sampleRate, _bufferLength); // set tables inside 293 if (_data) _parseSystemCommand(_data.systemCommands); // parse #EFFECT 294 effector.prepareProcess(); // set stream number inside 295 module.reset(); 296 297 // set position 298 if (_data && _position > 0) { sequencer.dummyProcess(_position * _sampleRate * 0.001); } 299 300 // dispatch streaming start event 301 dispatchEvent(new SiONEvent(SiONEvent.STREAM_START, this)); 302 303 // start stream 304 _process_addAllEventListners(); 305 _soundChannel = _sound.play(); 306 _soundChannel.soundTransform = _soundTransform; 307 308 // initialize 309 _timeProcessTotal = 0; 310 for (var i:int=0; i<TIME_AVARAGING_COUNT; i++) { 311 _timeProcessData.i = 0; 312 _timeProcessData = _timeProcessData.next; 313 } 314 _isPaused = false; 315 } 472 if (_debugMode) throw e; 473 else dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 474 } 475 476 return _soundChannel; 316 477 } 317 478 … … 325 486 _soundChannel = null; 326 487 _latency = 0; 488 327 489 // dispatch streaming stop event 328 490 dispatchEvent(new SiONEvent(SiONEvent.STREAM_STOP, this)); … … 338 500 339 501 340 /** Get track instance. This function only is available after play(). 341 * Most common timing to call is in the event listener of SiONEvent.STREAM_START. 342 * @param trackIndex Track index. This must be less than SiMMLDriver.trackCount. 343 * @return Track instance. When the trackIndex is out of range, returns null. 344 */ 345 public function getTrack(trackIndex:int) : SiMMLSequencerTrack 346 { 347 return sequencer.getTrack(trackIndex); 348 } 349 350 502 503 504 // Interface for data register 505 //---------------------------------------- 506 /** Set wave table data refered by %4. 507 * @param index wave table number. 508 * @param table wave shape vector ranges in -1 to 1. 509 */ 510 public function setWaveTable(index:int, table:Vector.<Number>) : void 511 { 512 var len:int, bits:int=-1; 513 for (len=table.length; len>0; len>>=1) bits++; 514 if (bits<2) return; 515 var serialized:Vector.<int> = SiONUtil.serializeVectorPCM(table, new Vector.<int>()); 516 serialized.length = 1<<bits; 517 SiOPMTable.registerWaveTable(index, serialized, bits); 518 } 519 520 521 /** Set PCM data rederd from %7. 522 * @param index PCM data number. 523 * @param sound Sound instance to set. 524 * @param samplingOctave Sampling frequency. The value of 5 means that "o5a" is original frequency. 525 */ 526 public function setPCMData(index:int, sound:Sound, samplingOctave:int=5) : void 527 { 528 var data:Vector.<int> = SiONUtil.serialize(sound); 529 SiOPMTable.registerPCMData(index, data, samplingOctave); 530 } 531 532 533 /** Set wave data refered by %10. 534 * @param index note number. 128-255 for bank1. 535 * @param sound Sound instance to set. 536 * @param isOneShot True to set "one shot" sound. The "one shot" sound ignores note off. 537 * @param isStereo True to set as stereo data. 538 */ 539 public function setWaveData(index:int, sound:Sound, isOneShot:Boolean=true, isStereo:Boolean=false) : void 540 { 541 var data:Vector.<int> = SiONUtil.getRawData(sound); 542 SiOPMTable.registerSample(index, data, ((isOneShot) ? 2 : 0) + ((isStereo) ? 1 : 0)); 543 } 544 545 546 547 548 // Interface for intaractivity 549 //---------------------------------------- 550 /** Note on. This function only is available after play(). The NOTE_ON_STREAM event is dispatched inside. 551 * @param note note number [0-127]. 552 * @param setting tone setting. 553 * @param length note length in 16th beat. 0 sets no note off, this means you should call noteOff(). 554 * @param delay note on delay units in 16th beat. 555 * @param quant quantize in 16th beat. 0 sets no quantization. 4 sets quantization by 4th beat. 556 * @param trackID new tracks id. 557 * @param eventTriggerID Event trigger id. 558 * @param noteOnTrigger note on trigger type. 559 * @param noteOffTrigger note off trigger type. 560 * @return SiMMLTrack to play the note. 561 */ 562 public function noteOn(note:int, setting:SiONToneSetting, 563 length:Number=0, delay:Number=0, quant:int=0, trackID:int=0, 564 eventTriggerID:int=0, noteOnTrigger:int=0, noteOffTrigger:int=0) : SiMMLTrack 565 { 566 trackID = (trackID & SiMMLTrack.TRACK_ID_FILTER) | SiMMLTrack.DRIVER_TRACK_ID_OFFSET; 567 var mmlTrack:SiMMLTrack = sequencer.getFreeControlableTrack(trackID) || sequencer.newControlableTrack(trackID); 568 var delaySamples:int = sequencer.calcSampleDelay(0, delay, quant); 569 if (mmlTrack) { 570 if (setting) setting.setTrackTone(mmlTrack); 571 mmlTrack.setEventTrigger(eventTriggerID, noteOnTrigger, noteOffTrigger); 572 mmlTrack.keyOn(note, sequencer.calcSampleLength(length), delaySamples); 573 } 574 return mmlTrack; 575 } 576 577 578 /** Note off. This function only is available after play(). The NOTE_OFF_STREAM event is dispatched inside. 579 * @param note note number [0-127]. 580 * @param trackID track id to note off. 581 * @return The SiMMLTrack switched key off. Returns null when tracks are overflowed. 582 */ 583 public function noteOff(note:int, trackID:int=0) : SiMMLTrack 584 { 585 trackID = (trackID & SiMMLTrack.TRACK_ID_FILTER) | SiMMLTrack.DRIVER_TRACK_ID_OFFSET; 586 var mmlTrack:SiMMLTrack = sequencer.findControlableTrack(trackID, note); 587 if (mmlTrack) mmlTrack.keyOff(); 588 return mmlTrack; 589 } 590 591 592 593 594 //==================================================================================================== 595 // Internal uses 596 //==================================================================================================== 597 // callback for event trigger 598 //---------------------------------------- 599 // call back when sound streaming 600 private function _callbackEventTriggerOn(track:SiMMLTrack, pitch:int) : Boolean 601 { 602 return _publishEventTrigger(track, track.eventTriggerTypeOn, SiONTrackEvent.NOTE_ON_FRAME, SiONTrackEvent.NOTE_ON_STREAM); 603 } 604 605 // call back when sound streaming 606 private function _callbackEventTriggerOff(track:SiMMLTrack) : Boolean 607 { 608 return _publishEventTrigger(track, track.eventTriggerTypeOff, SiONTrackEvent.NOTE_OFF_FRAME, SiONTrackEvent.NOTE_OFF_STREAM); 609 } 610 611 // publish event trigger 612 private function _publishEventTrigger(track:SiMMLTrack, type:int, frameEvent:String, streamEvent:String) : Boolean 613 { 614 var event:SiONTrackEvent; 615 if (type & 1) { // frame event. dispatch later 616 event = new SiONTrackEvent(frameEvent, this, track); 617 _triggerEventQueue.push(event); 618 } 619 if (type & 2) { // sound event. dispatch immediately 620 event = new SiONTrackEvent(streamEvent, this, track); 621 dispatchEvent(event); 622 return !(event.isDefaultPrevented()); 623 } 624 return true; 625 } 626 627 628 // operate event listener 629 //---------------------------------------- 630 // add all event listners 631 private function _queue_addAllEventListners() : void 632 { 633 if (_listenEvent != NO_LISTEN) throw errorDriverBusy(LISTEN_QUEUE); 634 addEventListener(Event.ENTER_FRAME, _queue_onEnterFrame, false, _eventListenerPrior); 635 _listenEvent = LISTEN_QUEUE; 636 } 637 638 639 // add all event listners 640 private function _process_addAllEventListners() : void 641 { 642 if (_listenEvent != NO_LISTEN) throw errorDriverBusy(LISTEN_PROCESS); 643 addEventListener(Event.ENTER_FRAME, _process_onEnterFrame, false, _eventListenerPrior); 644 _dispatchStreamEvent = (hasEventListener(SiONEvent.STREAM)); 645 _prevFrameTime = getTimer(); 646 _listenEvent = LISTEN_PROCESS; 647 } 648 649 650 // remove all event listners 651 private function _removeAllEventListners() : void 652 { 653 switch (_listenEvent) { 654 case LISTEN_QUEUE: 655 removeEventListener(Event.ENTER_FRAME, _queue_onEnterFrame); 656 break; 657 case LISTEN_PROCESS: 658 removeEventListener(Event.ENTER_FRAME, _process_onEnterFrame); 659 _dispatchStreamEvent = false; 660 break; 661 } 662 _listenEvent = NO_LISTEN; 663 } 664 665 666 667 668 // parse 669 //---------------------------------------- 351 670 // parse system command on SiONDriver 352 private function _parseSystemCommand(systemCommands:Array) : void353 { 354 var id:int ;671 private function _parseSystemCommand(systemCommands:Array) : Boolean 672 { 673 var id:int, effectSet:Boolean = false; 355 674 for each (var cmd:* in systemCommands) { 356 675 switch(cmd.command){ 357 676 case "#EFFECT": 677 if (!effectSet) effector.initialize(); // initialize effect 678 effectSet = true; 358 679 effector.parseMML(cmd.number, cmd.content); 359 680 break; 360 681 } 361 682 } 362 } 363 364 365 366 367 // Data register 368 //---------------------------------------- 369 /** Set wave table data */ 370 public function setWaveTable(index:int, table:Vector.<Number>, bits:int) : void 371 { 372 //SiOPMTable.registerWaveTable(index, table, bits); 373 } 374 375 376 /** Set PCM data */ 377 public function setPCMData(index:int, serialized:Vector.<int>, samplingOctave:int=5) : void 378 { 379 SiOPMTable.registerPCMData(index, serialized, samplingOctave); 380 } 381 382 383 /** Set wave data */ 384 public function setWaveData(index:int, rawData:Vector.<int>, channelCount:int=1) : void 385 { 386 SiOPMTable.registerSample(index, rawData, channelCount); 387 } 388 389 390 391 392 // MIDI interface (still in a planning stage) 393 //---------------------------------------- 394 /** Note on. This function only is available after play(). 395 * @param channel Channel to switch key on. 396 * @param note Note number to switch key on. 397 * @return The track switched key key on. Returns null when tracks are overflowed. 398 */ 399 public function noteOn(note:int, param:SiOPMChannelParam=null) : SiMMLSequencerTrack 400 { 401 var trk:SiMMLSequencerTrack = sequencer.getFreeControlableTrack() || sequencer.newControlableTrack(); 402 if (trk) { 403 if (param) trk.channel.setSiOPMChannelParam(param, false); 404 trk.keyOnDelay = (_timePrevStream - getTimer()) * 44.1; 405 trk.keyOn(note); 406 } 407 return trk; 408 } 409 410 411 /** Note off. This function only is available after play(). 412 * @param channel Channel to switch key off. 413 * @param note Note number to switch key off. 414 * @return The track switched key off. Returns null when no tracks run specifyed note. 415 */ 416 public function noteOff(note:int) : SiMMLSequencerTrack 417 { 418 var trk:SiMMLSequencerTrack = sequencer.findControlableTrack(note); 419 if (trk) trk.keyOff(); 420 return trk; 421 } 422 423 424 425 426 // operate event listener 427 //---------------------------------------- 428 // add all event listners 429 private function _compile_addAllEventListners() : void 430 { 431 addEventListener(Event.ENTER_FRAME, _compile_onEnterFrame); 432 _listenEvent = LISTEN_COMPILE; 433 } 434 435 436 // add all event listners 437 private function _process_addAllEventListners() : void 438 { 439 addEventListener(Event.ENTER_FRAME, _process_onEnterFrame); 440 _listenEvent = LISTEN_PROCESS; 441 } 442 443 444 // remove all event listners 445 private function _removeAllEventListners() : void 446 { 447 switch (_listenEvent) { 448 case LISTEN_COMPILE: 449 removeEventListener(Event.ENTER_FRAME, _compile_onEnterFrame); 450 break; 451 case LISTEN_PROCESS: 452 removeEventListener(Event.ENTER_FRAME, _process_onEnterFrame); 453 break; 454 } 455 _listenEvent = NO_LISTEN; 456 } 457 458 459 460 461 // compile 462 //---------------------------------------- 463 // Stac que 464 private function _pushCompileQue(mml:String, interval:int, data:SiONData) : void 683 return effectSet; 684 } 685 686 687 688 689 // jobs queue 690 //---------------------------------------- 691 // cancel 692 private function _cancelAllJobs() : void 693 { 694 _data = null; 695 _mmlString = null; 696 _currentJob = 0; 697 _jobQueue.length = 0; 698 _queueLength = 0; 699 _removeAllEventListners(); 700 dispatchEvent(new SiONEvent(SiONEvent.QUEUE_CANCEL, this, null)); 701 } 702 703 704 // next job 705 private function _executeNextJob() : Boolean 706 { 707 _data = null; 708 _mmlString = null; 709 _currentJob = 0; 710 if (_jobQueue.length == 0) { 711 _queueLength = 0; 712 _removeAllEventListners(); 713 dispatchEvent(new SiONEvent(SiONEvent.QUEUE_COMPLETE, this, null)); 714 return true; 715 } 716 717 var queue:SiONDriverJob = _jobQueue.shift(); 718 if (queue.mml) _prepareCompile(queue.mml, queue.data); 719 else _prepareRender(queue.data, queue.buffer); 720 return false; 721 } 722 723 724 // on enterFrame 725 private function _queue_onEnterFrame(e:Event) : void 465 726 { 466 727 try { 467 if (isCompiling) { 468 _compileQue.push(new SiONCompileQue(mml, interval, data)); 469 } else { 470 _prepareCompile(mml, interval, data); 728 var event:SiONEvent, t:int = getTimer(); 729 730 switch (_currentJob) { 731 case 1: // compile 732 _jobProgress = sequencer.compile(_queueInterval); 733 _timeCompile += getTimer() - t; 734 break; 735 case 2: // render 736 _jobProgress += (1 - _jobProgress) * 0.5; 737 while (getTimer() - t <= _queueInterval) { 738 if (_rendering()) { 739 _jobProgress = 1; 740 break; 741 } 742 } 743 _timeRender += getTimer() - t; 744 break; 471 745 } 472 } catch(e:Error) {473 // error474 if (_throwErrorEvent) dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message));475 else throw e;476 }477 }478 479 480 // Compile staced que481 private function _execCompileQue() : Boolean482 {483 if (_compileQue.length == 0) return false;484 var que:SiONCompileQue = _compileQue.shift();485 _prepareCompile(que.mml, que.interval, que.data);486 return true;487 }488 489 490 // prepare to compile491 private function _prepareCompile(mml:String, interval:int, data:SiONData) : void492 {493 _data = data || new SiONData();494 _mmlString = mml;495 _compileInterval = interval;496 sequencer.prepareCompile(_data, _mmlString);497 _compileProgress = 0.01;498 }499 500 501 // on enterFrame502 private function _compile_onEnterFrame(e:Event) : void503 {504 try {505 // compile506 var t:int = getTimer();507 _compileProgress = sequencer.compile(_compileInterval);508 _timeCompile += getTimer() - t;509 746 510 if (_compileProgress == 1) { 511 // complete 512 dispatchEvent(new SiONEvent(SiONEvent.COMPILE_COMPLETE, this)); 513 // execute next que 514 if (!_execCompileQue()) { 515 // finished 516 _removeAllEventListners(); 517 _data = null; 518 _mmlString = null; 519 } 520 } else { 521 // progress 522 dispatchEvent(new SiONEvent(SiONEvent.COMPILE_PROGRESS, this)); 747 // finish job 748 if (_jobProgress == 1) { 749 // finish all jobs 750 if (_executeNextJob()) return; 523 751 } 752 753 // progress 754 event = new SiONEvent(SiONEvent.QUEUE_PROGRESS, this, null, true); 755 dispatchEvent(event); 756 if (event.isDefaultPrevented()) _cancelAllJobs(); // canceled 524 757 } catch (e:Error) { 525 758 // error 526 759 _removeAllEventListners(); 527 if (_throwErrorEvent) dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 528 else throw e; 529 } 760 if (_debugMode) throw e; 761 else dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 762 } 763 } 764 765 766 767 // compile 768 //---------------------------------------- 769 // prepare to compile 770 private function _prepareCompile(mml:String, data:SiONData) : void 771 { 772 _data = data || new SiONData(); 773 _mmlString = mml; 774 sequencer.prepareCompile(_data, _mmlString); 775 _jobProgress = 0.01; 776 _timeCompile = 0; 777 _currentJob = 1; 778 } 779 780 781 782 783 // render 784 //---------------------------------------- 785 // prepare for rendering 786 private function _prepareRender(data:*, renderBuffer:Vector.<Number>) : void 787 { 788 _prepareProcess(data); 789 _renderBuffer = renderBuffer || new Vector.<Number>(); 790 _renderBufferSizeMax = _renderBuffer.length; 791 _renderBufferIndex = 0; 792 _jobProgress = 0.01; 793 _timeRender = 0; 794 _currentJob = 2; 795 } 796 797 798 // rendering @return true when finished rendering. 799 private function _rendering() : Boolean 800 { 801 var i:int, j:int, imax:int, 802 output:Vector.<Number> = module.output, 803 finished:Boolean = false; 804 805 // processing 806 sequencer.process(); 807 effector.process(); 808 809 // limit rendering length 810 imax = _bufferLength<<1; 811 if (_renderBufferSizeMax != 0 && _renderBufferSizeMax < _renderBufferIndex+imax) { 812 imax = _renderBufferSizeMax - _renderBufferIndex; 813 finished = true; 814 } 815 816 // extend buffer 817 if (_renderBuffer.length < _renderBufferIndex+imax) { 818 _renderBuffer.length = _renderBufferIndex+imax; 819 } 820 821 // copy output 822 for (i=0, j=_renderBufferIndex; i<imax; i++, j++) { 823 _renderBuffer[j] = output[i]; 824 } 825 826 // incerement index 827 _renderBufferIndex += imax; 828 829 return (finished || (_renderBufferSizeMax==0 && sequencer.isFinished)); 530 830 } 531 831 … … 535 835 // process 536 836 //---------------------------------------- 837 // prepare for processing 838 private function _prepareProcess(data:*) : void 839 { 840 if (data is String) { 841 _data = compile(data as String); 842 } else { 843 if (!(data == null || data is SiONData)) throw errorDataIncorrect(); 844 _data = data; 845 } 846 module.initialize(_channelCount, _bufferLength); 847 module.reset(); // reset channels 848 sequencer.prepareProcess(_data, _sampleRate, _bufferLength); // set track channels (this must be called after module.reset(). 849 if (_data) _parseSystemCommand(_data.systemCommands); // parse #EFFECT (initialize effector inside) 850 effector.prepareProcess(); // set stream number inside 851 } 852 853 537 854 // on enterFrame 538 855 private function _process_onEnterFrame(e:Event) : void 539 856 { 857 // frame rate 858 var t:int = getTimer(); 859 _frameRate = t - _prevFrameTime; 860 _prevFrameTime = t; 861 862 // frame trigger 863 if (_triggerEventQueue.length > 0) { 864 _triggerEventQueue = _triggerEventQueue.filter(function(e:SiONTrackEvent, i:int, v:Vector.<SiONTrackEvent>) : Boolean { 865 if (e._decrementTimer(_frameRate)) { 866 dispatchEvent(e); 867 return false; 868 } 869 return true; 870 }); 871 } 540 872 } 541 873 … … 561 893 } 562 894 } else { 895 var t:int = getTimer(); 563 896 // processing 564 var t:int = getTimer();897 _cannotChangeBPM = true; 565 898 sequencer.process(); 566 899 effector.process(); 900 _cannotChangeBPM = false; 567 901 568 902 // calculate the average of processing time … … 579 913 580 914 // dispatch streaming event 581 dispatchEvent(new SiONEvent(SiONEvent.STREAM, this, buffer)); 915 if (_dispatchStreamEvent) { 916 var event:SiONEvent = new SiONEvent(SiONEvent.STREAM, this, buffer, true); 917 dispatchEvent(event); 918 if (event.isDefaultPrevented()) stop(); // canceled 919 } 582 920 } 583 921 } catch (e:Error) { 584 922 // error 585 923 _removeAllEventListners(); 586 if (_throwErrorEvent) dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 587 else throw e; 588 } 924 if (_debugMode) throw e; 925 else dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); 926 } 927 } 928 929 930 931 932 // error 933 //---------------------------------------- 934 private function errorDataIncorrect() : Error { 935 return new Error("SiONDriver error; data incorrect in play() or render()."); 936 } 937 938 939 private function errorDriverBusy(execID:int) : Error { 940 var states:Array = ["compiling", "streaming", "rendering"]; 941 return new Error("SiONDriver error: Driver busy. Call " + states[execID] + " while " + states[_listenEvent] + "."); 942 } 943 944 945 private function errorCannotChangeBPM() : Error { 946 return new Error("SiONDriver error: Cannot change bpm while rendering (SiONTrackEvent.NOTE_*_STREAM)."); 589 947 } 590 948 } … … 596 954 import org.si.sound.SiONData; 597 955 598 class SiON CompileQue956 class SiONDriverJob 599 957 { 600 958 public var mml:String; 601 public var interval:int;959 public var buffer:Vector.<Number>; 602 960 public var data:SiONData; 603 961 604 function SiON CompileQue(mml_:String, interval_:int, data_:SiONData)962 function SiONDriverJob(mml_:String, buffer_:Vector.<Number>, data_:SiONData) 605 963 { 606 964 mml = mml_; 607 interval = interval_;965 buffer = buffer_; 608 966 data = data_ || new SiONData(); 609 967 } as3/SiOPM/trunk/src/org/si/sound/SiONUtil.as
r2526 r2607 16 16 17 17 18 /** Utilities for SiON */ 18 19 public class SiONUtil { 19 20 20 // PCM data serialization 21 // PCM data serialization (for PCM Data) 21 22 //-------------------------------------------------- 22 23 /** Serialize Sound wave */ 23 static public function serialize Sound(data:Sound, sampleMax:int=1048576) : Vector.<int>24 static public function serialize(data:Sound, sampleMax:int=1048576) : Vector.<int> 24 25 { 25 26 var wave:ByteArray = new ByteArray(); … … 58 59 59 60 60 // raw wave data 61 // raw wave data (for Sampler Data) 61 62 //-------------------------------------------------- 62 63 /** get raw data from Sound */ … … 65 66 var wave:ByteArray = new ByteArray(); 66 67 var samples:int = data.extract(wave, sampleMax); 67 return rawdataByteArrayPCM(wave, new Vector.<int>, channels);68 return getRawDataByteArrayPCM(wave, new Vector.<int>, channels); 68 69 } 69 70 70 71 71 72 /** get raw data from Vector.<Number> wave */ 72 static public function rawdataVectorPCM(src:Vector.<Number>, dst:Vector.<int>, channels:int=1) : Vector.<int>73 static public function getRawDataVectorPCM(src:Vector.<Number>, dst:Vector.<int>, channels:int=1) : Vector.<int> 73 74 { 74 75 var i:int, j0:int, j1:int, imax:int=src.length>>1; … … 91 92 92 93 /** get raw data from ByteArray wave */ 93 static public function rawdataByteArrayPCM(src:ByteArray, dst:Vector.<int>, channels:int=1) : Vector.<int>94 static public function getRawDataByteArrayPCM(src:ByteArray, dst:Vector.<int>, channels:int=1) : Vector.<int> 94 95 { 95 96 var i:int, imax:int=src.length>>3; … … 108 109 return dst; 109 110 } 110 111 112 // Wave shaper113 //--------------------------------------------------114 /** wave shaper for Vector.<Number> */115 static public function waveShapeVector(src:Vector.<Number>, distortion:Number) : void116 {117 var coef:Number = 2 * distortion / (1-distortion),118 c1:Number = 1 + coef;119 var i:int, imax:int=src.length, n:Number;120 for (i=0; i<imax; i++) {121 n = src[i];122 src[i] = c1 * n / (1 + coef * ((n<0) ? -n : n));123 }124 }125 126 127 /** wave shaper for ByteArray */128 static public function waveShapeByteArray(src:ByteArray, distortion:Number) : void129 {130 var coef:Number = 2 * distortion / (1-distortion),131 c1:Number = 1 + coef;132 var i:int, imax:int=src.length>>3, n:Number;133 for (i=0; i<imax; i++) {134 src.position = i;135 n = src.readFloat();136 src.position = i;137 src.writeFloat(c1 * n / (1 + coef * ((n<0) ? -n : n)));138 }139 }140 141 142 /** wave shaper for raw data */143 static public function waveShapeRawData(src:Vector.<int>, channels:int, distortion:Number) : void144 {145 var coef:Number = 2 * distortion / (1-distortion),146 c1:Number = (1 + coef) * 32768;147 var i:int, imax:int=src.length, n:Number;148 if (channels == 2) {149 for (i=0; i<imax; i++) {150 n = (src[i] & 65535) * 0.000030517578125 - 1;151 src[i] = int(c1 * n / (1 + coef * ((n<0) ? -n : n))) + 32768;152 n = (src[i] >> 16) * 0.000030517578125 - 1;153 src[i] += (int(c1 * n / (1 + coef * ((n<0) ? -n : n))) + 32768)<<16;154 }155 } else {156 for (i=0; i<imax; i++) {157 n = src[i] * 0.000030517578125;158 src[i] = int(c1 * n / (1 + coef * ((n<0) ? -n : n)));159 }160 }161 }162 163 164 111 } 165 112 } as3/SiOPM/trunk/src/org/si/sound/bytecode/SoundClass.as
r2526 r2607 4 4 import flash.events.Event; 5 5 import flash.utils.ByteArray; 6 import flash.media.Sound; 6 7 7 8 … … 49 50 loader.loadBytes(bytes); 50 51 51 function _write(vu:Vector.<uint>) : ByteArray { 52 for (var ui:uint in vu) { bytes.writeUnsignedInt(ui); } 53 return ba; 54 } 52 function _write(vu:Vector.<uint>) : void { for each (var ui:uint in vu) { bytes.writeUnsignedInt(ui); } } 55 53 56 54 function _onComplete(e:Event) : void { as3/SiOPM/trunk/src/org/si/sound/effect/SiCtrlFilterBase.as
r2526 r2607 10 10 package org.si.sound.effect { 11 11 import org.si.sound.module.SiOPMTable; 12 import org.si.sound. driver.SiMMLTable;12 import org.si.sound.mml.SiMMLTable; 13 13 import org.si.utils.SLLint; 14 14 … … 19 19 public class SiCtrlFilterBase extends SiEffectBase 20 20 { 21 // variables 22 //------------------------------------------------------------ 21 23 protected var _p0r:Number, _p1r:Number, _p0l:Number, _p1l:Number; 22 24 protected var _cutIndex:int, _res:Number, _table:SiOPMTable; … … 27 29 28 30 31 32 33 // constructor 34 //------------------------------------------------------------ 35 /** constructor */ 36 function SiCtrlFilterBase() {} 37 38 39 40 41 // operation 42 //------------------------------------------------------------ 29 43 /** set parameters 30 44 * @param cut table index for cutoff(0-255). 255 to set no tables. … … 59 73 60 74 61 // overrided funcitons 62 //------------------------------------------------------------ 75 // overrided funcitons 76 //------------------------------------------------------------ 77 /** @private */ 63 78 override public function initialize() : void 64 79 { … … 69 84 70 85 86 /** @private */ 71 87 override public function mmlCallback(args:Vector.<Number>) : void 72 88 { … … 77 93 78 94 95 /** @private */ 79 96 override public function prepareProcess() : int 80 97 { … … 83 100 84 101 102 /** @private */ 85 103 override public function process(channels:int, buffer:Vector.<Number>, startIndex:int, length:int) : int 86 104 { … … 104 122 105 123 106 public function processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 124 /** @private */ 125 protected function processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 107 126 { 108 127 } as3/SiOPM/trunk/src/org/si/sound/effect/SiCtrlFilterHighPass.as
r2526 r2607 12 12 public class SiCtrlFilterHighPass extends SiCtrlFilterBase 13 13 { 14 override public function processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 14 /** @private */ 15 override protected function processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 15 16 { 16 17 var i:int, n:Number, imax:int = startIndex + length, as3/SiOPM/trunk/src/org/si/sound/effect/SiCtrlFilterLowPass.as
r2526 r2607 12 12 public class SiCtrlFilterLowPass extends SiCtrlFilterBase 13 13 { 14 override public function processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 14 /** @private */ 15 override protected function processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 15 16 { 16 17 var i:int, n:Number, imax:int = startIndex + length, as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectAutoPan.as
r2526 r2607 15 15 public class SiEffectAutoPan extends SiEffectBase 16 16 { 17 // variables 18 //------------------------------------------------------------ 17 19 private var _stereo:Boolean; 18 20 as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectBase.as
r2526 r2607 9 9 10 10 package org.si.sound.effect { 11 /** Effector basic class */11 /** Effector basic class. */ 12 12 public class SiEffectBase 13 13 { 14 // variables 15 //------------------------------------------------------------ 14 16 /** @private [internal use] used by manager */ 15 17 public var _isFree:Boolean = true; 16 18 17 19 18 /** initializer. */ 20 21 22 // constructor 23 //------------------------------------------------------------ 24 /** Constructor. do nothing. */ 25 function SiEffectBase() {} 26 27 28 29 30 // callback functions 31 //------------------------------------------------------------ 32 /** Initializer. The system calls this when the instance is created. */ 19 33 public function initialize() : void 20 34 { 21 35 } 22 36 23 /** parameter setting by mml arguments 37 38 /** Parameter setting by mml arguments. The sequencer calls this when "#EFFECT" appears. 24 39 * @param args The arguments refer from mml. The value of Number.NaN is put when its abbriviated. 25 40 */ … … 27 42 { 28 43 } 29 30 /** prepare processing. 44 45 46 /** Prepare processing. The system calls this before processing. 31 47 * @return requesting channels count. 32 48 */ … … 36 52 } 37 53 38 /** process effect to stream buffer 54 55 /** Process effect to stream buffer. The system calls this to process. 39 56 * @param channels Stream channel count. 1=monoral(same data on buffer[i] ans buffer[i+1]). 2=stereo. 40 57 * @param buffer Stream buffer to apply effect. This is standard stereo stream buffer like [L0,R0,L1,R1,L2,R2 ... ]. as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectCompressor.as
r2526 r2607 11 11 import org.si.utils.SLLNumber; 12 12 13 14 13 15 /** Compressor. */ 14 16 public class SiEffectCompressor extends SiEffectBase 15 17 { 18 // variables 19 //------------------------------------------------------------ 16 20 private var _windowRMSList:SLLNumber = null; 17 21 private var _windowSamples:int; … … 24 28 25 29 26 /** constructor */27 function SiEffectCompressor()28 {29 }30 30 31 31 32 /** constructor 32 // constructor 33 //------------------------------------------------------------ 34 /** constructor */ 35 function SiEffectCompressor() {} 36 37 38 39 40 // operation 41 //------------------------------------------------------------ 42 /** set parameters. 33 43 * @param thres threshold(0-1). 34 44 * @param slope slope(0-1). … … 47 57 48 58 49 // overrided funcitons 50 //------------------------------------------------------------ 59 60 61 // overrided funcitons 62 //------------------------------------------------------------ 63 /** @private */ 51 64 override public function initialize() : void 52 65 { … … 55 68 56 69 70 /** @private */ 57 71 override public function mmlCallback(args:Vector.<Number>) : void 58 72 { … … 65 79 66 80 81 /** @private */ 67 82 override public function prepareProcess() : int 68 83 { … … 74 89 75 90 91 /** @private */ 76 92 override public function process(channels:int, buffer:Vector.<Number>, startIndex:int, length:int) : int 77 93 { as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectEqualiser.as
r2526 r2607 12 12 public class SiEffectEqualiser extends SiEffectBase 13 13 { 14 // variables 15 //------------------------------------------------------------ 14 16 // filter pipes 15 17 private var f1p0L:Number, f1p1L:Number, f1p2L:Number, f1p3L:Number; … … 25 27 26 28 27 /** constructor */28 function SiEffectEqualiser()29 {30 }31 29 32 30 33 /** constructor 31 // constructor 32 //------------------------------------------------------------ 33 /** constructor */ 34 function SiEffectEqualiser() {} 35 36 37 38 39 // operation 40 //------------------------------------------------------------ 41 /** set parameters 34 42 * @param lowGain low gain(0-1-..). 35 43 * @param midGain middle gain(0-1-..). … … 48 56 49 57 50 // overrided funcitons 51 //------------------------------------------------------------ 58 59 60 // overrided funcitons 61 //------------------------------------------------------------ 62 /** @private */ 52 63 override public function initialize() : void 53 64 { … … 56 67 57 68 69 /** @private */ 58 70 override public function mmlCallback(args:Vector.<Number>) : void 59 71 { … … 66 78 67 79 80 /** @private */ 68 81 override public function prepareProcess() : int 69 82 { … … 74 87 75 88 89 /** @private */ 76 90 override public function process(channels:int, buffer:Vector.<Number>, startIndex:int, length:int) : int 77 91 { as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectModule.as
r2526 r2607 15 15 16 16 17 /** Effect Module */17 /** Effect Module. */ 18 18 public class SiEffectModule 19 19 { … … 30 30 // constructor 31 31 //-------------------------------------------------------------------------------- 32 /** constructor. */33 function SiEffectModule(module:SiOPMModule , userEffector:*=undefined)32 /** Constructor. */ 33 function SiEffectModule(module:SiOPMModule) 34 34 { 35 35 _module = module; … … 54 54 register("hf", SiFilterHighPass); 55 55 register("bf", SiFilterBandPass); 56 register("af", SiFilterAllPass);57 56 register("nf", SiFilterNotch); 58 57 register("pf", SiFilterPeak); 58 register("af", SiFilterAllPass); 59 59 60 60 register("nlf", SiCtrlFilterLowPass); … … 67 67 // operations 68 68 //-------------------------------------------------------------------------------- 69 /** initialize all effectors. */69 /** @parivate [internal use] initialize all effectors. */ 70 70 public function initialize() : void 71 71 { … … 74 74 75 75 76 /** prepare for processing. */76 /** @parivate [internal use] prepare for processing. */ 77 77 public function prepareProcess() : void 78 78 { … … 100 100 101 101 102 /** processing. */102 /** @parivate [internal use] processing. */ 103 103 public function process() : void 104 104 { … … 123 123 // effector instance manager 124 124 //-------------------------------------------------------------------------------- 125 /** register effector class */ 125 /** Register effector class 126 * @param name Effector name. 127 * @param cls SiEffectBase based class. 128 */ 126 129 public function register(name:String, cls:Class) : void 127 130 { … … 130 133 131 134 132 /** get effector instance by name */ 135 /** Get effector instance by name 136 * @param name Effector name. 137 */ 133 138 public function getInstance(name:String) : SiEffectBase 134 139 { … … 145 150 // effector connection 146 151 //-------------------------------------------------------------------------------- 147 /** clear effector chain. */ 152 /** Clear effector slot. 153 * @param slot Effector slot number. 154 */ 148 155 public function clear(slot:int) : void 149 156 { … … 153 160 154 161 155 /** connect effector. */ 162 /** Connect effector to the slot. 163 * @param slot Effector slot number. 164 * @param effector Effector instance. 165 */ 156 166 public function connect(slot:int, effector:SiEffectBase) : void 157 167 { … … 160 170 161 171 162 /** Parse MML for effector */ 172 /** Parse MML for effector 173 * @param slot Effector slot number. 174 * @param mml MML string. 175 */ 163 176 public function parseMML(slot:int, mml:String) : void 164 177 { … … 213 226 public var chain:Vector.<SiEffectBase> = new Vector.<SiEffectBase>(); 214 227 public function get isActive() : Boolean { return (chain.length > 0); } 228 function EffectorChain() {} 215 229 } 216 230 as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectStereoChorus.as
r2526 r2607 12 12 public class SiEffectStereoChorus extends SiEffectBase 13 13 { 14 // variables 15 //------------------------------------------------------------ 14 16 static private const DELAY_BUFFER_BITS:int = 12; 15 17 static private const DELAY_BUFFER_FILTER:int = (1<<DELAY_BUFFER_BITS)-1; … … 27 29 28 30 31 32 33 // constructor 34 //------------------------------------------------------------ 29 35 /** constructor */ 30 36 function SiEffectStereoChorus() … … 36 42 37 43 38 /** constructor 44 45 46 // operation 47 //------------------------------------------------------------ 48 /** set parameter 39 49 * @param delayTime delay time[ms]. maximum value is about 94. 40 50 * @param feedback feedback ratio(0-1). … … 54 64 55 65 56 // overrided funcitons 57 //------------------------------------------------------------ 66 67 68 // overrided funcitons 69 //------------------------------------------------------------ 70 /** @private */ 58 71 override public function initialize() : void 59 72 { … … 65 78 66 79 80 /** @private */ 67 81 override public function mmlCallback(args:Vector.<Number>) : void 68 82 { … … 74 88 75 89 90 /** @private */ 76 91 override public function prepareProcess() : int 77 92 { … … 82 97 83 98 99 /** @private */ 84 100 override public function process(channels:int, buffer:Vector.<Number>, startIndex:int, length:int) : int 85 101 { … … 91 107 imax = startIndex + length; 92 108 for (i=startIndex; i<imax-istep;) { 93 processLFO(buffer, i, istep);109 _processLFO(buffer, i, istep); 94 110 _lfoPhase = (_lfoPhase + 1) & 255; 95 111 i += istep; 96 112 istep = _lfoStep<<1; 97 113 } 98 processLFO(buffer, i, imax-i);114 _processLFO(buffer, i, imax-i); 99 115 _lfoResidueStep = istep - (imax - i); 100 116 return channels; … … 102 118 103 119 104 public function processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 120 // process inside 121 private function _processLFO(buffer:Vector.<Number>, startIndex:int, length:int) : void 105 122 { 106 123 var i:int, n:Number, m:Number, p:int, imax:int = startIndex + length, dly:int=int(_sin[_lfoPhase] * _depth); as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectStereoDelay.as
r2526 r2607 12 12 public class SiEffectStereoDelay extends SiEffectBase 13 13 { 14 // variables 15 //------------------------------------------------------------ 14 16 static private const DELAY_BUFFER_BITS:int = 16; 15 17 static private const DELAY_BUFFER_FILTER:int = (1<<DELAY_BUFFER_BITS)-1; … … 23 25 24 26 27 28 29 // constructor 30 //------------------------------------------------------------ 25 31 /** constructor */ 26 32 function SiEffectStereoDelay() … … 32 38 33 39 34 /** constructor 40 41 42 // operation 43 //------------------------------------------------------------ 44 /** set parameters 35 45 * @param delayTime delay time[ms]. maximum value is about 1500. 36 46 * @param feedback feedback decay(-1-1). Negative value to invert phase. … … 48 58 49 59 50 // overrided funcitons 51 //------------------------------------------------------------ 60 61 62 // overrided funcitons 63 //------------------------------------------------------------ 64 /** @private */ 52 65 override public function initialize() : void 53 66 { … … 56 69 57 70 71 /** @private */ 58 72 override public function mmlCallback(args:Vector.<Number>) : void 59 73 { … … 64 78 65 79 80 /** @private */ 66 81 override public function prepareProcess() : int 67 82 { … … 74 89 75 90 91 /** @private */ 76 92 override public function process(channels:int, buffer:Vector.<Number>, startIndex:int, length:int) : int 77 93 { as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectTable.as
r2526 r2607 9 9 10 10 package org.si.sound.effect { 11 /** @private Tables used in effectors. */ 11 12 public class SiEffectTable { 13 /** sin table */ 12 14 public var sinTable:Vector.<Number>; 13 15 14 16 17 /** constructor. */ 15 18 function SiEffectTable() 16 19 { … … 22 25 23 26 27 /** instance */ 24 28 static public var instance:SiEffectTable; 25 29 as3/SiOPM/trunk/src/org/si/sound/effect/SiEffectWaveShaper.as
r2526 r2607 12 12 public class SiEffectWaveShaper extends SiEffectBase 13 13 { 14 // variables 15 //------------------------------------------------------------ 14 16 private var _coefficient:int; 15 17 16 18 19 20 21 // constructor 22 //------------------------------------------------------------ 23 /** constructor */ 24 function SiEffectWaveShaper() {} 25 26 27 28 // operations 29 //------------------------------------------------------------ 17 30 /** set parameters 18 31 * @param distortion distortion(0-1). … … 24 37 25 38 26 // overrided funcitons 27 //------------------------------------------------------------ 39 40 41 // overrided funcitons 42 //------------------------------------------------------------ 43 /** @private */ 28 44 override public function initialize() : void 29 45 { … … 32 48 33 49 50 /** @private */ 34 51 override public function mmlCallback(args:Vector.<Number>) : void 35 52 { … … 38 55 39 56 57 /** @private */ 40 58 override public function prepareProcess() : int 41 59 { … … 44 62 45 63 64 /** @private */ 46 65 override public function process(channels:int, buffer:Vector.<Number>, startIndex:int, length:int) : int 47 66 { as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterAllPass.as
r2526 r2607 12 12 public class SiFilterAllPass extends SiFilterBase 13 13 { 14 // operations 15 //------------------------------------------------------------ 14 16 /** set parameters 15 17 * @param freq cutoff frequency[Hz]. … … 27 29 28 30 29 // overrided funcitons 30 //------------------------------------------------------------ 31 // overrided funcitons 32 //------------------------------------------------------------ 33 /** @private */ 31 34 override public function initialize() : void 32 35 { … … 35 38 36 39 40 /** @private */ 37 41 override public function mmlCallback(args:Vector.<Number>) : void 38 42 { as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterBandPass.as
r2526 r2607 12 12 public class SiFilterBandPass extends SiFilterBase 13 13 { 14 // operations 15 //------------------------------------------------------------ 14 16 /** set parameters 15 17 * @param freq cutoff frequency[Hz]. … … 29 31 30 32 31 // overrided funcitons 32 //------------------------------------------------------------ 33 34 35 // overrided funcitons 36 //------------------------------------------------------------ 37 /** @private */ 33 38 override public function initialize() : void 34 39 { … … 37 42 38 43 44 /** @private */ 39 45 override public function mmlCallback(args:Vector.<Number>) : void 40 46 { as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterBase.as
r2526 r2607 12 12 public class SiFilterBase extends SiEffectBase 13 13 { 14 // variables 15 //------------------------------------------------------------ 14 16 protected var _a1:Number, _a2:Number, _b0:Number, _b1:Number, _b2:Number; 15 17 private var _in1L:Number, _in2L:Number, _out1L:Number, _out2L:Number; … … 17 19 18 20 19 // Math calculation 20 //------------------------------------------------------------ 21 22 23 // Math calculation 24 //------------------------------------------------------------ 25 /** hyperbolic sinh. */ 21 26 protected function sinh(n:Number) : Number { 22 27 return (Math.exp(n) - Math.exp(-n)) * 0.5; … … 24 29 25 30 26 // overrided funcitons 27 //------------------------------------------------------------ 31 32 33 // constructor 34 //------------------------------------------------------------ 35 /** constructor */ 36 function SiFilterBase() {} 37 38 39 40 41 // overrided funcitons 42 //------------------------------------------------------------ 43 /** @private */ 28 44 override public function prepareProcess() : int 29 45 { … … 33 49 34 50 51 /** @private */ 35 52 override public function process(channels:int, buffer:Vector.<Number>, startIndex:int, length:int) : int 36 53 { as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterHighPass.as
r2526 r2607 12 12 public class SiFilterHighPass extends SiFilterBase 13 13 { 14 // operations 15 //------------------------------------------------------------ 14 16 /** set parameters 15 17 * @param freq cutoff frequency[Hz]. … … 28 30 29 31 30 // overrided funcitons 31 //------------------------------------------------------------ 32 // overrided funcitons 33 //------------------------------------------------------------ 34 /** @private */ 32 35 override public function initialize() : void 33 36 { … … 36 39 37 40 41 /** @private */ 38 42 override public function mmlCallback(args:Vector.<Number>) : void 39 43 { as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterLowPass.as
r2526 r2607 12 12 public class SiFilterLowPass extends SiFilterBase 13 13 { 14 // operations 15 //------------------------------------------------------------ 14 16 /** set parameters 15 17 * @param freq cutoff frequency[Hz]. … … 28 30 29 31 30 // overrided funcitons 31 //------------------------------------------------------------ 32 // overrided funcitons 33 //------------------------------------------------------------ 34 /** @private */ 32 35 override public function initialize() : void 33 36 { … … 36 39 37 40 41 /** @private */ 38 42 override public function mmlCallback(args:Vector.<Number>) : void 39 43 { as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterNotch.as
r2526 r2607 12 12 public class SiFilterNotch extends SiFilterBase 13 13 { 14 // operations 15 //------------------------------------------------------------ 14 16 /** set parameters 15 17 * @param freq cutoff frequency[Hz]. … … 28 30 29 31 30 // overrided funcitons 31 //------------------------------------------------------------ 32 // overrided funcitons 33 //------------------------------------------------------------ 34 /** @private */ 32 35 override public function initialize() : void 33 36 { … … 36 39 37 40 41 /** @private */ 38 42 override public function mmlCallback(args:Vector.<Number>) : void 39 43 { as3/SiOPM/trunk/src/org/si/sound/effect/SiFilterPeak.as
r2526 r2607 12 12 public class SiFilterPeak extends SiFilterBase 13 13 { 14 // operations 15 //------------------------------------------------------------ 14 16 /** set parameters 15 17 * @param freq cutoff frequency[Hz]. … … 31 33 32 34 33 // overrided funcitons 34 //------------------------------------------------------------ 35 // overrided funcitons 36 //------------------------------------------------------------ 37 /** @private */ 35 38 override public function initialize() : void 36 39 { … … 39 42 40 43 44 /** @private */ 41 45 override public function mmlCallback(args:Vector.<Number>) : void 42 46 { as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelBase.as
r2526 r2607 115 115 public function getSiOPMChannelParam(param:SiOPMChannelParam) : void {} 116 116 117 /** algorism ( @al) */117 /** algorism (@al) */ 118 118 public function setAlgorism(cnt:int, alg:int) : void {} 119 /** feedback ( @fb) */119 /** feedback (@fb) */ 120 120 public function setFeedBack(fb:int, fbc:int) : void {} 121 /** parameters ( @ call from SiMMLSequencerTrack.setChannelParameters()) */121 /** parameters (@ call from SiMMLTrack._setChannelParameters()) */ 122 122 public function setParameters(param:Vector.<int>) : void {} 123 /** pgType & ptType ( @call from SiMMLChannelSetting.selectTone()/initializeTone()) */123 /** pgType & ptType (@ call from SiMMLChannelSetting.selectTone()/initializeTone()) */ 124 124 public function setType(pgType:int, ptType:int) : void {} 125 125 /** Release rate (s) */ … … 145 145 /** active operator index (i). */ 146 146 public function set activeOperatorIndex(i:int) : void { } 147 /** Release rate ( @rr) */147 /** Release rate (@rr) */ 148 148 public function set rr(r:int) : void {} 149 /** total level ( @tl) */149 /** total level (@tl) */ 150 150 public function set tl(i:int) : void {} 151 /** fine multiple ( @ml) */151 /** fine multiple (@ml) */ 152 152 public function set fmul(i:int) : void {} 153 /** phase ( @ph) */153 /** phase (@ph) */ 154 154 public function set phase(i:int) : void {} 155 /** detune ( @dt) */155 /** detune (@dt) */ 156 156 public function set detune(i:int) : void {} 157 /** fixed pitch ( @fx) */157 /** fixed pitch (@fx) */ 158 158 public function set fixedPitch(i:int) : void {} 159 /** ssgec ( @se) */159 /** ssgec (@se) */ 160 160 public function set ssgec(i:int) : void {} 161 161 … … 167 167 public function get bufferIndex() : int { return _bufferIndex; } 168 168 169 /** is idling ? */ 170 public function get isIdling() : Boolean { return _isIdling; } 169 171 170 172 … … 265 267 266 268 267 /** LP Filter envelop ( @f).269 /** LP Filter envelop (@f). 268 270 * @param ar attack rate. 269 271 * @param dr1 decay rate 1. … … 293 295 294 296 295 /** LP Filter resonance ( @f) [0,9]. */297 /** LP Filter resonance (@f) [0,9]. */ 296 298 public function setFilterResonance(i:int) : void 297 299 { … … 312 314 // connection control 313 315 //-------------------------------------------------- 314 /** Set input pipe ( @i).315 * @param level Input level. The value for a standard FM sound module is 15.316 /** Set input pipe (@i). 317 * @param level Input level. The value for a standard FM sound module is 5. 316 318 * @param pipeIndex Input pipe index (0-3). 317 319 */ 318 320 public function setInput(level:int, pipeIndex:int) : void 319 321 { 320 var i:int;321 322 322 // pipe index 323 323 pipeIndex &= 3; 324 325 // input level326 _inputLevel = level;327 324 328 325 // set pipe … … 330 327 _inPipe = _chip.getPipe(pipeIndex, _bufferIndex); 331 328 _inputMode = INPUT_PIPE; 329 _inputLevel = level + 10; 332 330 } else { 333 331 _inPipe = _chip.zeroBuffer; 334 332 _inputMode = INPUT_ZERO; 335 } 336 } 337 338 339 /** Set ring modulation pipe (@r). 333 _inputLevel = 0; 334 } 335 } 336 337 338 /** Set ring modulation pipe (@r). 340 339 * @param level. Input level(0-8). 341 340 * @param pipeIndex Input pipe index (0-3). … … 356 355 357 356 358 /** Set output pipe (@o).357 /** Set output pipe (@o). 359 358 * @param outputMode Output mode. 0=standard stereo out, 1=overwrite pipe. 2=add pipe. 360 * @param outputIndex Output stream/pipe index (0-3).359 * @param pipeIndex Output stream/pipe index (0-3). 361 360 */ 362 public function setOutput(outputMode:int, outputIndex:int) : void 363 { 364 if (outputIndex > 3) return; 361 public function setOutput(outputMode:int, pipeIndex:int) : void 362 { 365 363 var i:int, flagAdd:Boolean; 364 365 // pipe index 366 pipeIndex &= 3; 366 367 367 368 // set pipe 368 369 if (outputMode == OUTPUT_STANDARD) { 369 outputIndex = 4;// pipe[4] is used.370 flagAdd = false; // ovewrite mode370 pipeIndex = 4; // pipe[4] is used. 371 flagAdd = false; // ovewrite mode 371 372 } else { 372 373 flagAdd = (outputMode == OUTPUT_ADD); // ovewrite/additional mode … … 377 378 378 379 // set output pipe 379 _outPipe = _chip.getPipe( outputIndex, _bufferIndex);380 _outPipe = _chip.getPipe(pipeIndex, _bufferIndex); 380 381 381 382 // set base pipe … … 472 473 { 473 474 _bufferIndex = 0; 474 _isIdling = false;475 475 } 476 476 … … 507 507 508 508 // update buffer index 509 _bufferIndex += len; 510 } 511 512 513 /** Buffering without processnig */ 514 public function nop(len:int) : void 515 { 516 _nop(len); 509 517 _bufferIndex += len; 510 518 } … … 639 647 protected function _nop(len:int) : void 640 648 { 641 var i:int; 642 // buffering 643 var bp:SLLint = _basePipe, 644 op:SLLint = _outPipe; 645 for (i=0; i<len; i++) { 646 // increment 647 op.i = bp.i; 648 bp = bp.next; 649 op = op.next; 650 } 651 // update pointers 652 _basePipe = bp; 653 _outPipe = op; 649 var i:int, p:SLLint; 650 651 // rotate output buffer 652 if (_outputMode == OUTPUT_STANDARD) { 653 _outPipe = _chip.getPipe(4, (_bufferIndex + len) & (_chip.bufferLength-1)); 654 } else { 655 for (p=_outPipe, i=0; i<len; i++) p = p.next; 656 _outPipe = p; 657 _basePipe = (_outputMode == OUTPUT_ADD) ? p : _chip.zeroBuffer; 658 } 659 660 // rotate input buffer when connected by @i 661 if (_inputMode == INPUT_PIPE) { 662 for (p=_inPipe, i=0; i<len; i++) p = p.next; 663 _inPipe = p; 664 } 665 666 // rotate ring buffer 667 if (_ringPipe) { 668 for (p=_ringPipe, i=0; i<len; i++) p = p.next; 669 _ringPipe = p; 670 } 654 671 } 655 672 as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelFM.as
r2526 r2607 15 15 16 16 17 /** FM sound channel. < br/>17 /** FM sound channel. <p> 18 18 * The calculation of this class is based on OPM emulation (refer from sources of mame, fmgen and x68sound). 19 19 * And it has some extension to simulate other sevral fm sound modules (OPNA, OPLL, OPL2, OPL3, OPX, MA3, MA5, MA7, TSS and DX7). … … 34 34 * <li>ring modulation (from C64?)</li> 35 35 * </ul> 36 * </p> 36 37 */ 37 38 public class SiOPMChannelFM extends SiOPMChannelBase … … 297 298 // interfaces 298 299 //-------------------------------------------------- 299 /** Set algorism ( @al)300 /** Set algorism (@al) 300 301 * @param cnt Operator count. 301 302 * @param alg Algolism number of the operator's connection. … … 315 316 316 317 317 /** Set feedback( @fb). This also initializes the input mode(@i).318 /** Set feedback(@fb). This also initializes the input mode(@i). 318 319 * @param fb Feedback level. Ussualy in the range of 0-7. 319 320 * @param fbc Feedback connection. Operator index which feeds back its output. … … 338 339 339 340 340 /** Set parameters ( @command). */341 /** Set parameters (@ command). */ 341 342 override public function setParameters(param:Vector.<int>) : void 342 343 { … … 347 348 348 349 349 /** pgType & ptType ( @) */350 /** pgType & ptType (@) */ 350 351 override public function setType(pgType:int, ptType:int) : void 351 352 { 353 var funcIndex:int = _operatorCount-1; 354 if (pgType >= SiOPMTable.PG_PCM) { 355 _updateOperatorCount(1); 356 funcIndex = 4; 357 } 352 358 activeOperator.pgType = pgType; 353 359 activeOperator.ptType = ptType; 354 if (operator[0]._pgType >= SiOPMTable.PG_PCM) _funcProcess = _funcProcessList[_lfo_on][4]; 355 else _funcProcess = _funcProcessList[_lfo_on][_operatorCount-1]; 360 _funcProcess = _funcProcessList[_lfo_on][funcIndex]; 356 361 } 357 362 … … 368 373 369 374 370 /** Set input pipe(@i). This function is almost same as super.setInput(). This also initializes the feed back setting(@fb).371 * @param level Input level. The value for a standard FM sound module is 5.372 * @param pipeIndex Input pipe index (0-3).373 */374 override public function setInput(level:int, pipeIndex:int) : void375 {376 var i:int;377 378 // pipe index379 pipeIndex &= 3;380 381 // set pipe382 if (level > 0) {383 _inPipe = _chip.getPipe(pipeIndex, _bufferIndex);384 _inputMode = INPUT_PIPE;385 _inputLevel = level + 10; // different from super.setInput()386 } else {387 _inPipe = _chip.zeroBuffer;388 _inputMode = INPUT_ZERO;389 _inputLevel = 0;390 }391 }392 393 394 375 395 376 … … 412 393 } 413 394 414 /** release rate ( @rr) */395 /** release rate (@rr) */ 415 396 override public function set rr(i:int) : void { activeOperator.rr = i; } 416 397 417 /** total level ( @tl) */398 /** total level (@tl) */ 418 399 override public function set tl(i:int) : void { activeOperator.tl = i; } 419 400 420 /** fine multiple ( @ml) */401 /** fine multiple (@ml) */ 421 402 override public function set fmul(i:int) : void { activeOperator.fmul = i; } 422 403 423 /** phase ( @ph) */404 /** phase (@ph) */ 424 405 override public function set phase(i:int) : void { activeOperator.keyOnPhase = i; } 425 406 426 /** detune ( @dt) */407 /** detune (@dt) */ 427 408 override public function set detune(i:int) : void { activeOperator.detune = i; } 428 409 429 /** fixed pitch ( @fx) */410 /** fixed pitch (@fx) */ 430 411 override public function set fixedPitch(i:int) : void { activeOperator.fixedPitchIndex = i; } 431 412 432 /** ssgec ( @se) */413 /** ssgec (@se) */ 433 414 override public function set ssgec(i:int) : void { activeOperator.ssgec = i; } 434 415 … … 1268 1249 // select processing function 1269 1250 _funcProcess = _funcProcessList[_lfo_on][_operatorCount-1]; 1251 1270 1252 // default active operator is the last one. 1271 1253 activeOperator = operator[_operatorCount-1]; as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelManager.as
r2526 r2607 16 16 static public const CT_CHANNEL_FM:int = 0; 17 17 static public const CT_CHANNEL_SAMPLER:int = 1; 18 static public const CT_EFFECT_DELAY:int = 2; 19 static public const CT_MAX:int = 3; 18 static public const CT_MAX:int = 2; 20 19 21 20 … … 62 61 // operations 63 62 //-------------------------------------------------- 64 / ** allocate channels */63 // allocate channels. 65 64 private function _alloc(count:int) : void 66 65 { … … 167 166 _channelManagers[CT_CHANNEL_FM] = new SiOPMChannelManager(SiOPMChannelFM, CT_CHANNEL_FM); 168 167 _channelManagers[CT_CHANNEL_SAMPLER] = new SiOPMChannelManager(SiOPMChannelSampler, CT_CHANNEL_SAMPLER); 169 _channelManagers[CT_EFFECT_DELAY] = new SiOPMChannelManager(SiOPMChannelEffectDelay, CT_EFFECT_DELAY);170 168 } 171 169 as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelParam.as
r2526 r2607 9 9 10 10 package org.si.sound.module { 11 import org.si.sound.mml. MMLSequence;11 import org.si.sound.mml.base.MMLSequence; 12 12 13 13 14 /** SiOPM Parameters */ 14 /** SiOPM Channel Parameters. This is a member of SiONToneSetting. 15 * @see org.si.sound.SiONToneSetting 16 * @see org.si.sound.module.SiOPMOperatorParam 17 */ 15 18 public class SiOPMChannelParam 16 19 { … … 74 77 lfoFreqStep = SiOPMTable.LFO_TIMER_INITIAL/(fps*2.882352941176471); 75 78 } 76 77 79 public function get lfoFrame() : int 78 80 { … … 81 83 82 84 85 /** constructor */ 83 86 function SiOPMChannelParam() 84 87 { … … 94 97 95 98 99 /** initializer */ 96 100 public function initialize() : SiOPMChannelParam 97 101 { … … 133 137 134 138 139 /** copier */ 135 140 public function copyFrom(org:SiOPMChannelParam) : SiOPMChannelParam 136 141 { … … 171 176 172 177 178 /** information */ 173 179 public function toString() : String 174 180 { as3/SiOPM/trunk/src/org/si/sound/module/SiOPMChannelSampler.as
r2526 r2607 97 97 // interfaces 98 98 //-------------------------------------------------- 99 /** Set algorism ( @al)99 /** Set algorism (@al) 100 100 * @param cnt Operator count. 101 101 * @param alg Algolism number of the operator's connection. … … 106 106 107 107 108 /** Set parameters (@ command). */ 109 override public function setParameters(param:Vector.<int>) : void 110 { 108 /** pgType & ptType (@ call from SiMMLChannelSetting.selectTone()/initializeTone()) */ 109 override public function setType(pgType:int, ptType:int) : void 110 { 111 _bankNumber = pgType & 1; 111 112 } 112 113 … … 132 133 } 133 134 134 /** phase ( @ph) */135 /** phase (@ph) */ 135 136 override public function set phase(i:int) : void { 136 137 _samplePhaseReset = (i!=-1); … … 182 183 _isNoteOn = true; 183 184 _isIdling = false; 184 var idx:int = _waveNumber + (_bankNumber<<7) + SiOPMTable.PG_SAMPLE; 185 var idx:int = _waveNumber + (_bankNumber<<7) + SiOPMTable.PG_SAMPLE, 186 flag:int = _table.waveFixedBits[idx]; 185 187 _sample = _table.waveTables[idx]; 186 188 _sampleLength = _sample.length; 187 _sampleChannelCount = _table.waveFixedBits[idx]; 189 _sampleChannelCount = (flag & 1) ? 2 : 1; 190 _isOneShot = Boolean(flag >> 1); 188 191 if (_samplePhaseReset) _sampleIndex = 0; 189 192 } … … 194 197 override public function noteOff() : void 195 198 { 196 _isNoteOn = false;197 199 if (!_isOneShot) { 200 _isNoteOn = false; 198 201 _isIdling = true; 199 202 _sample = null; … … 210 213 211 214 212 /** Prepare buffering */213 override public function prepareBuffer() : void214 {215 _bufferIndex = 0;216 _isIdling = false;217 }218 219 220 215 /** Buffering */ 221 216 override public function buffer(len:int) : void … … 223 218 var i:int, imax:int, vol:Number; 224 219 if (_isIdling || _sample == null) { 225 _nop(len); // idling220 //_nop(len); 226 221 } else { 227 222 var residureLen:int = _sampleLength - _sampleIndex, … … 237 232 _chip.streamBuffer[0].writeVectorInt(_sample, _sampleIndex, _bufferIndex, procLen, vol, _pan, _sampleChannelCount); 238 233 } 239 if (len > procLen) _nop(len - procLen); 234 if (len > procLen) { 235 _isIdling = true; 236 _sample = null; 237 //_nop(len - procLen); 238 } 240 239 } 241 240 … … 244 243 _sampleIndex += len; 245 244 } 245 246 247 /** Buffering without processnig */ 248 override public function nop(len:int) : void 249 { 250 //_nop(len); 251 _bufferIndex += len; 252 } 246 253 } 247 254 } as3/SiOPM/trunk/src/org/si/sound/module/SiOPMModule.as
r2526 r2607 21 21 // constants 22 22 //-------------------------------------------------- 23 /** maximum value of stream buffer size */ 23 24 static public const STREAM_SIZE_MAX:int = 8; 25 /** pipe size */ 24 26 static public const PIPE_SIZE:int = 5; 25 27 … … 36 38 public var streamBuffer:Vector.<SiOPMStream>; 37 39 38 /** Operator */ 39 protected var _freeOperators:Vector.<SiOPMOperator>; 40 /** buffer length */ 41 protected var _bufferLength:int; 40 private var _freeOperators:Vector.<SiOPMOperator>; // Free list for SiOPMOperator 41 private var _bufferLength:int; // buffer length 42 42 43 43 // pipes … … 54 54 55 55 56 /** stream count */56 /** stream buffer count */ 57 57 public function set streamCount(count:int) : void 58 58 { … … 147 147 } 148 148 149 149 150 /** Clear all buffer. */ 150 151 public function clearAllBuffers() : void as3/SiOPM/trunk/src/org/si/sound/module/SiOPMOperator.as
r2011 r2607 12 12 13 13 14 /** SiOPM operator class.<br/> 14 /** SiOPM operator class. 15 * <p> 15 16 * This operator based on the OPM emulation of MAME, but its extended in below points,<br/> 16 17 * 1) You can set the phase offest of pulse generator. <br/> 17 * 2) You can select the wave form from some wave tables (see class SiOPMTable). 18 * 3) You can set the key scale level. 19 * 4) You can fix the pitch. 20 * 5) You can set the ssgec in OPNA. 18 * 2) You can select the wave form from some wave tables (see class SiOPMTable).<br/> 19 * 3) You can set the key scale level.<br/> 20 * 4) You can fix the pitch.<br/> 21 * 5) You can set the ssgec in OPNA.<br/> 22 * </p> 21 23 */ 22 24 public class SiOPMOperator … … 41 43 // Never access these valiables in other classes reason for the maintenances. 42 44 //---------------------------------------------------------------------------------------------------- 43 /** table */45 /** @private table */ 44 46 internal var _table:SiOPMTable; 45 /** chip */47 /** @private chip */ 46 48 internal var _chip:SiOPMModule; 47 49 48 50 49 51 // FM module parameters 50 /** Attack rate [0,63] */52 /** @private Attack rate [0,63] */ 51 53 internal var _ar:int; 52 /** Decay rate [0,63] */54 /** @private Decay rate [0,63] */ 53 55 internal var _dr:int; 54 /** Sustain rate [0,63] */56 /** @private Sustain rate [0,63] */ 55 57 internal var _sr:int; 56 /** Release rate [0,63] */58 /** @private Release rate [0,63] */ 57 59 internal var _rr:int; 58 /** Sustain level [0,15] */60 /** @private Sustain level [0,15] */ 59 61 internal var _sl:int; 60 /** Total level [0,127] */62 /** @private Total level [0,127] */ 61 63 internal var _tl:int; 62 /** Key scaling rate = 5-ks [5,2] */64 /** @private Key scaling rate = 5-ks [5,2] */ 63 65 internal var _ks:int; 64 /** Key scaling level [0,3] */66 /** @private Key scaling level [0,3] */ 65 67 internal var _ksl:int; 66 /** _multiple = (mul) ? (mul<<7) : 64; [64,128,256,384,512...] */68 /** @private _multiple = (mul) ? (mul<<7) : 64; [64,128,256,384,512...] */ 67 69 internal var _multiple:int; 68 /** dt1 [0,7]. */70 /** @private dt1 [0,7]. */ 69 71 internal var _dt1:int; 70 /** dt2 [0,3]. This value is linked with _pitchIndexShift */72 /** @private dt2 [0,3]. This value is linked with _pitchIndexShift */ 71 73 internal var _dt2:int; 72 /** Amp modulation shift [16,0] */74 /** @private Amp modulation shift [16,0] */ 73 75 internal var _ams:int; 74 /** Key code = oct<<4 + note [0,127] */76 /** @private Key code = oct<<4 + note [0,127] */ 75 77 internal var _kc:int; 76 /** SSG type envelop control */78 /** @private SSG type envelop control */ 77 79 internal var _ssg_type:int; 78 /** Mute [0/SiOPMTable.ENV_BOTTOM] */80 /** @private Mute [0/SiOPMTable.ENV_BOTTOM] */ 79 81 internal var _mute:int; 80 82 81 83 82 84 // pulse generator 83 /** pulse generator type */85 /** @private pulse generator type */ 84 86 internal var _pgType:int; 85 /** pitch table type */87 /** @private pitch table type */ 86 88 internal var _ptType:int; 87 /** wave table */89 /** @private wave table */ 88 90 internal var _waveTable:Vector.<int>; 89 /** phase shift */91 /** @private phase shift */ 90 92 internal var _waveFixedBits:int; 91 /** phase step shift */93 /** @private phase step shift */ 92 94 internal var _wavePhaseStepShift:int; 93 /** pitch table */95 /** @private pitch table */ 94 96 internal var _pitchTable:Vector.<int>; 95 /** pitch table index filter */97 /** @private pitch table index filter */ 96 98 internal var _pitchTableFilter:int; 97 /** phase */99 /** @private phase */ 98 100 internal var _phase:int; 99 /** phase step */101 /** @private phase step */ 100 102 internal var _phase_step:int; 101 /** keyOn phase */103 /** @private keyOn phase */ 102 104 internal var _keyon_phase:int; 103 /** pitch fixed */105 /** @private pitch fixed */ 104 106 internal var _pitchFixed:Boolean; 105 /** dt1 table */107 /** @private dt1 table */ 106 108 internal var _dt1Table:Vector.<int>; 107 109 108 110 109 /** pitch index = note * 64 + key fraction */111 /** @private pitch index = note * 64 + key fraction */ 110 112 internal var _pitchIndex:int; 111 /** pitch index shift. This value is linked with dt2 and detune. */113 /** @private pitch index shift. This value is linked with dt2 and detune. */ 112 114 internal var _pitchIndexShift:int; 113 /** pitch index shift by pitch modulation. This value is linked with dt2. */115 /** @private pitch index shift by pitch modulation. This value is linked with dt2. */ 114 116 internal var _pitchIndexShift2:int; 115 /** frequency modulation left-shift. 15 for FM, fb+6 for feedback. */117 /** @private frequency modulation left-shift. 15 for FM, fb+6 for feedback. */ 116 118 internal var _fmShift:int; 117 119 118 120 119 121 // envelop generator 120 /** State [EG_ATTACK, EG_DECAY, EG_SUSTAIN, EG_RELEASE, EG_OFF] */122 /** @private State [EG_ATTACK, EG_DECAY, EG_SUSTAIN, EG_RELEASE, EG_OFF] */ 121 123 internal var _eg_state:int; 122 /** Envelop generator updating timer, initialized (2047 * 3) << CLOCK_RATIO_BITS. */124 /** @private Envelop generator updating timer, initialized (2047 * 3) << CLOCK_RATIO_BITS. */ 123 125 internal var _eg_timer:int; 124 /** Timer stepping by samples */126 /** @private Timer stepping by samples */ 125 127 internal var _eg_timer_step:int; 126 /** Counter rounded on 8. */128 /** @private Counter rounded on 8. */ 127 129 internal var _eg_counter:int; 128 /** Internal sustain level [0,SiOPMTable.ENV_BOTTOM] */130 /** @private Internal sustain level [0,SiOPMTable.ENV_BOTTOM] */ 129 131 internal var _eg_sustain_level :int; 130 /** Internal total level [0,1024] = ((tl + f(kc, ksl)) << 3) + _eg_tl_offset + 192. */132 /** @private Internal total level [0,1024] = ((tl + f(kc, ksl)) << 3) + _eg_tl_offset + 192. */ 131 133 internal var _eg_total_level:int; 132 /** Internal total level offset by volume [-192,832]*/134 /** @private Internal total level offset by volume [-192,832]*/ 133 135 internal var _eg_tl_offset:int; 134 /** Internal key scaling rate = _kc >> _ks [0,32] */136 /** @private Internal key scaling rate = _kc >> _ks [0,32] */ 135 137 internal var _eg_key_scale_rate:int; 136 /** Internal key scaling level right shift = _ksl[0,1,2,3]->[8,2,1,0] */138 /** @private Internal key scaling level right shift = _ksl[0,1,2,3]->[8,2,1,0] */ 137 139 internal var _eg_key_scale_level_rshift:int; 138 /** Envelop generator level [0,1024] */140 /** @private Envelop generator level [0,1024] */ 139 141 internal var _eg_level:int; 140 /** Envelop generator output [0,1024<<3] */142 /** @private Envelop generator output [0,1024<<3] */ 141 143 internal var _eg_out:int; 142 /** SSG envelop control ar switch */144 /** @private SSG envelop control ar switch */ 143 145 internal var _eg_ssgec_ar:int; 144 /** SSG envelop control state */146 /** @private SSG envelop control state */ 145 147 internal var _eg_ssgec_state:int; 146 148 147 /** Increment table picked up from _eg_incTables or _eg_incTablesAtt. */149 /** @private Increment table picked up from _eg_incTables or _eg_incTablesAtt. */ 148 150 internal var _eg_incTable:Vector.<int>; 149 /** The level to shift the state to next. */151 /** @private The level to shift the state to next. */ 150 152 internal var _eg_stateShiftLevel:int; 151 /** Next status list */153 /** @private Next status list */ 152 154 internal var _eg_nextState:Vector.<int>; 153 /** _eg_level converter */155 /** @private _eg_level converter */ 154 156 internal var _eg_levelTable:Vector.<int>; 155 / ** Next status table */157 // Next status table 156 158 static private var _table_nextState:Array = [ 157 159 // EG_ATTACK, EG_DECAY, EG_SUSTAIN, EG_RELEASE, EG_OFF … … 162 164 163 165 // pipes 164 /** flag that is final carrior. */166 /** @private flag that is final carrior. */ 165 167 internal var _final:Boolean; 166 /** modulator output */168 /** @private modulator output */ 167 169 internal var _inPipe:SLLint; 168 /** base */170 /** @private base */ 169 171 internal var _basePipe:SLLint; 170 /** output */172 /** @private output */ 171 173 internal var _outPipe:SLLint; 172 /** feed back */174 /** @private feed back */ 173 175 internal var _feedPipe:SLLint; 174 176 … … 581 583 // internal operations 582 584 //-------------------------------------------------- 583 /** Update envelop generator. This code is only for testing. */585 /** @private Update envelop generator. This code is only for testing. */ 584 586 internal function eg_update() : void 585 587 { … … 602 604 603 605 604 /** Update pulse generator. This code is only for testing. */606 /** @private Update pulse generator. This code is only for testing. */ 605 607 internal function pg_update() : void 606 608 { … … 614 616 615 617 616 /** Shift envelop generator state. */618 /** @private Shift envelop generator state. */ 617 619 internal function _eg_shiftState(state:int) : void 618 620 { as3/SiOPM/trunk/src/org/si/sound/module/SiOPMOperatorParam.as
r2011 r2607 9 9 10 10 package org.si.sound.module { 11 /** OPM Parameters */ 11 /** OPM Parameters. This is a member of SiOPMChannelParam. 12 * @see org.si.sound.SiONToneSetting 13 * @see org.si.sound.module.SiOPMChannelParam 14 */ 12 15 public class SiOPMOperatorParam 13 16 { … … 70 73 71 74 75 /** constructor */ 72 76 function SiOPMOperatorParam() 73 77 { … … 76 80 77 81 82 /** intialize all parameters. */ 78 83 public function initialize() : void 79 84 { … … 100 105 101 106 107 /** copy all parameters. */ 102 108 public function copyFrom(org:SiOPMOperatorParam) : void 103 109 { … … 124 130 125 131 132 /** all parameters in 1line. */ 126 133 public function toString() : String 127 134 { as3/SiOPM/trunk/src/org/si/sound/module/SiOPMTable.as
r2526 r2607 92 92 static public const PG_CUSTOM :int = 256; // (256- 511) custom wave table. PG_CUSTOM+[0,255] 93 93 static public const PG_PCM :int = 512; // (512-767) pcm module.PG_PCM+[0,255] 94 static public const PG_SAMPLE :int = 768; // (768-102 3) samplar module.PG_SAMPLE+[0,255]95 static public const DEFAULT_PG_MAX:int = 1024; // max value of pgType = 102 394 static public const PG_SAMPLE :int = 768; // (768-1024) samplar module.PG_SAMPLE+[0,255] 95 static public const DEFAULT_PG_MAX:int = 1024; // max value of pgType = 1024 96 96 static public const PG_FILTER :int = 1023; // pg number loops between 0 to 1023 97 97 … … 1106 1106 1107 1107 /** Register Sampler data. */ 1108 static public function registerSample(index:int, table:Vector.<int>, channelCount:int) : void1108 static public function registerSample(index:int, table:Vector.<int>, flag:int) : void 1109 1109 { 1110 1110 // offset index … … 1113 1113 // register wave table 1114 1114 instance.waveTables[table_index] = table; 1115 instance.waveFixedBits[table_index] = channelCount;1115 instance.waveFixedBits[table_index] = flag; 1116 1116 } 1117 1117 } as3/SiOPM/trunk/src/org/si/sound/mx/SiOPMPlayer.as
r2526 r2607 13 13 import flash.media.SoundChannel; 14 14 import mx.core.UIComponent; 15 import org.si.sound.SiOPMData; 16 import org.si.sound.SiOPMEvent; 17 import org.si.sound.SiOPMDriver; 18 import org.si.sound.driver.SiMMLSequencerTrack; 15 import org.si.sound.events.*; 16 import org.si.sound.SiONData; 17 import org.si.sound.SiONDriver; 19 18 20 19 … … 26 25 //---------------------------------------- 27 26 /** driver. */ 28 public var driver:SiO PMDriver;27 public var driver:SiONDriver; 29 28 30 private var _lineCommand:Vector.<int> = new Vector.<int>(65);31 private var _lineVectorL:Vector.<Number> = new Vector.<Number>(130);32 private var _lineVectorR:Vector.<Number> = new Vector.<Number>(130);33 29 34 30 … … 41 37 * @param bitRate Bit ratio of wave. 8 or 16 is available. 42 38 * @param bufferSize Buffer size of sound stream. 8192, 4096 or 2048 is available, but no check. 43 * @param throwErrorEvent true; throw ErrorEvent when it errors. false; throw Error when it errors.44 39 */ 45 function SiOPMPlayer( channelCount:int=2, sampleRate:int=44100, bitRate:int=16, bufferSize:int=8192, throwErrorEvent:Boolean=true)40 function SiOPMPlayer(bufferSize:int=2048, channelCount:int=2, sampleRate:int=44100, bitRate:int=0) 46 41 { 47 driver = new SiOPMDriver(channelCount, sampleRate, bitRate, bufferSize, throwErrorEvent); 48 driver.addEventListener(SiOPMEvent.COMPILE_COMPLETE, _throughEvent); 49 driver.addEventListener(SiOPMEvent.COMPILE_PROGRESS, _throughEvent); 50 driver.addEventListener(SiOPMEvent.STREAM, _onStream); 51 driver.addEventListener(SiOPMEvent.STREAM_START, _throughEvent); 52 driver.addEventListener(SiOPMEvent.STREAM_STOP, _throughEvent); 53 driver.addEventListener(ErrorEvent.ERROR, _throughEvent); 54 55 function _throughEvent(e:Event) : void { dispatchEvent(e); } 56 for (var i:int=0; i<130; i+=2) { 57 _lineCommand[i>>1] = (i) ? 2 : 1; 58 _lineVectorL[i] = _lineVectorR[i] = i; 59 } 42 driver = new SiONDriver(bufferSize, channelCount, sampleRate, bitRate); 43 driver.addEventListener(SiONEvent.STREAM, _onStream); 60 44 } 61 45 62 46 63 private function _onStream(event:SiO PMEvent) : void47 private function _onStream(event:SiONEvent) : void 64 48 { 65 var data:Vector.<Number> = event.driver.module.output,66 ci:int, i:int, imax:int = data.length, step:int = imax>>7;67 for (ci=1, i=0; ci<130; i+=step, ci+=2) {68 _lineVectorL[ci] = data[i]*16+20;69 _lineVectorR[ci] = data[i+1]*16+60;70 }71 graphics.clear();72 graphics.lineStyle(1, 0xffffff);73 graphics.drawPath(_lineCommand, _lineVectorL);74 graphics.drawPath(_lineCommand, _lineVectorR);75 dispatchEvent(event);76 49 } 77 50 }

