チェンジセット 634: as3/Study/fm_module_test
- コミット日時:
- 2008/06/14 07:15:12 (4 年前)
- ファイル:
-
- as3/Study/fm_module_test/src/org/si/sound/driver/SIOscConnector.as (更新) (3 diffs)
- as3/Study/fm_module_test/src/org/si/sound/driver/TSSDriver.as (更新) (28 diffs)
- as3/Study/fm_module_test/src/org/si/sound/fm.xls (追加)
- as3/Study/fm_module_test/src/org/si/sound/license.txt (追加)
- as3/Study/fm_module_test/src/org/si/sound/mml/MMLEvent.as (更新) (1 diff)
- as3/Study/fm_module_test/src/org/si/sound/mml/MMLParser.as (更新) (17 diffs)
- as3/Study/fm_module_test/src/org/si/sound/mml/MMLParserSetting.as (更新) (6 diffs)
- as3/Study/fm_module_test/src/org/si/sound/module/FOPMChannel.as (追加)
- as3/Study/fm_module_test/src/org/si/sound/module/FOPMChannelBase.as (追加)
- as3/Study/fm_module_test/src/org/si/sound/module/FOPMModule.as (追加)
- as3/Study/fm_module_test/src/org/si/sound/module/FOPMOscillator.as (更新) (11 diffs)
- as3/Study/fm_module_test/src/org/si/sound/module/FOPMTable.as (更新) (11 diffs)
- as3/Study/fm_module_test/src/org/si/sound/module/OPMEnvelop.as (削除)
- as3/Study/fm_module_test/src/org/si/sound/module/SIModule.as (削除)
- as3/Study/fm_module_test/src/org/si/sound/module/SIOscillator.as (削除)
- as3/Study/fm_module_test/src/org/si/sound/module/TOPMChannel.as (追加)
- as3/Study/fm_module_test/src/org/si/sound/module/TOPMModule.as (追加)
- as3/Study/fm_module_test/src/org/si/sound/module/fmgenEnvelop.as.tmp (削除)
- as3/Study/fm_module_test/src/org/si/sound/tss2si_memo.txt (削除)
- as3/Study/fm_module_test/src/org/si/sound/tss2topm_memo.txt (追加)
- as3/Study/fm_module_test/test/caution.txt (更新) (3 diffs)
- as3/Study/fm_module_test/test/ssGenerator/app.swf (更新) (変更前)
- as3/Study/fm_module_test/test/ssGenerator/main.as (更新) (2 diffs)
- as3/Study/fm_module_test/test/tss/app.swf (更新) (変更前)
- as3/Study/fm_module_test/test/tss/main.as (更新) (2 diffs)
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
as3/Study/fm_module_test/src/org/si/sound/driver/SIOscConnector.as
r580 r634 1 1 //---------------------------------------------------------------------------------------------------- 2 // SIOscillatorconnector.2 // TOPMChannel connector. 3 3 // Copyright (c) 2008 keim All rights reserved. 4 4 // Distributed under BSD-style license (see license.txt). … … 10 10 package org.si.sound.driver { 11 11 import org.si.sound.mml.*; 12 import org.si.sound.module. SIModule;13 import org.si.sound.module. SIOscillator;12 import org.si.sound.module.TOPMModule; 13 import org.si.sound.module.TOPMChannel; 14 14 15 15 … … 150 150 if (outPipe != -1) { 151 151 seq.unshiftEvent(MMLEvent.PARAMETER, outPipe); 152 seq.unshiftEvent(TSSDriver.eventID_OUTPUT, (firstOsc) ? SIOscillator.OUTPIPE_OVERWRITE : SIOscillator.OUTPIPE_ADD);152 seq.unshiftEvent(TSSDriver.eventID_OUTPUT, (firstOsc) ? TOPMChannel.OUTPIPE_OVERWRITE : TOPMChannel.OUTPIPE_ADD); 153 153 //trace(" @o"+((firstOsc)?'1,':'2,')+outPipe); 154 154 } else { 155 155 seq.unshiftEvent(MMLEvent.PARAMETER, 0); 156 seq.unshiftEvent(TSSDriver.eventID_OUTPUT, SIOscillator.OUTPIPE_OFF);156 seq.unshiftEvent(TSSDriver.eventID_OUTPUT, TOPMChannel.OUTPIPE_OFF); 157 157 //trace(" @o0,0"); 158 158 } as3/Study/fm_module_test/src/org/si/sound/driver/TSSDriver.as
r580 r634 1 1 //---------------------------------------------------------------------------------------------------- 2 // TSS bridge for SIModule.2 // TSS bridge for TOPMModule. 3 3 // Copyright (c) 2008 keim All rights reserved. 4 4 // Distributed under BSD-style license (see license.txt). … … 10 10 package org.si.sound.driver { 11 11 import org.si.sound.mml.*; 12 import org.si.sound.module. SIModule;13 import org.si.sound.module. SIOscillator;12 import org.si.sound.module.TOPMModule; 13 import org.si.sound.module.FOPMChannelBase; 14 14 import org.si.sound.module.FOPMTable; 15 15 import org.si.utils.SLLNumber; 16 16 17 17 18 /** TSS bridge for SIModule. NOTE: This is very, very dishonest impelemtation for TSS... ('A`) */18 /** TSS bridge for TOPMModule. NOTE: This is very, very dishonest impelemtation for TSS... ('A`) */ 19 19 public class TSSDriver extends MMLEventListener 20 20 { … … 37 37 public var title:String; 38 38 /** Module instance. */ 39 public var module: SIModule;39 public var module:TOPMModule; 40 40 41 41 /** TSSDriverTracks */ … … 48 48 protected var currentDriverTrack:TSSDriverTrack; 49 49 /** Current processing channel (1 channel equals 1 oscillator in SI). */ 50 protected var currentChannel: SIOscillator;50 protected var currentChannel:FOPMChannelBase; 51 51 52 52 … … 66 66 function TSSDriver() 67 67 { 68 module = new SIModule();68 module = new TOPMModule(); 69 69 driverTracks = []; 70 70 oscConnectors = []; … … 83 83 newMMLEventListener('@ns', _onNoteShiftRelative); 84 84 newMMLEventListener('ml', _onMultiple); 85 newMMLEventListener('@ml', _onFineMultiple); 85 86 newMMLEventListener('s', _onSustain); 86 87 newMMLEventListener('%', _onChangeModule); … … 90 91 // very very dishonest implementations 91 92 newMMLEventListener('@s', _onTSSEnvelop); 92 newMMLEventListener('@ml', _onFineMultiple);93 93 newMMLEventListener('@ks', _onKeyScale); 94 94 95 95 // original commands 96 newMMLEventListener('@ fm', _onFMParam);96 newMMLEventListener('@opm', _onOPMParam); 97 97 98 98 // do nothing … … 108 108 setMMLEventListener(MMLEvent.FINE_VOLUME, _onFineVolume); 109 109 setMMLEventListener(MMLEvent.AT, _onChangeTone); 110 setMMLEventListener(MMLEvent.SLUR, _onSlur); 111 setMMLEventListener(MMLEvent.PORTAMENT, _onPortament); 110 112 111 113 // call at once … … 136 138 } 137 139 //trace(_v2tl); 140 138 141 139 142 FOPMTable.initialize(3580000, 44100); … … 192 195 { 193 196 // initialize module 194 module.initialize(trackCount, 3580000, sampleRate,bufferLength);197 module.initialize(trackCount, bufferLength); 195 198 module.reset(); 196 199 … … 199 202 for (var i:int=0; i<imax; i++) { 200 203 if (driverTracks.length == i) driverTracks.push(new TSSDriverTrack()); 201 driverTracks[i].initialize(module. oscillators[i]);204 driverTracks[i].initialize(module.channels[i]); 202 205 } 203 206 } … … 215 218 currentDriverTrack = driverTracks[i]; 216 219 currentChannel = currentDriverTrack.channel; 217 currentChannel.prepare Buffer();220 currentChannel.prepareProcess(); 218 221 ret = processTrack(i, module.bufferLength) && ret; 219 222 } … … 232 235 setting.defaultBPM = 150; 233 236 setting.defaultLValue = 8; 234 setting.default GateRatio= 12;237 setting.defaultQuantRatio = 12; 235 238 setting.defaultOctave = 5; 236 239 setting.maxVolume = 16; … … 238 241 setting.maxFineVolume = 255; 239 242 setting.defaultFineVolume = 255; 240 setting.expandLength = true;241 setting.expandOctave = true;242 setting.expandVolume = false;243 setting.expandOctaveShift = true;244 setting.expandVolumeShift = true;245 243 setting.commentRegExp = "{.*?}"; 246 244 … … 349 347 override protected function onProcess(sampleLength:int) : void 350 348 { 351 currentChannel. buffer(sampleLength);349 currentChannel.process(sampleLength); 352 350 } 353 351 … … 414 412 private function _onNoteOn(e:MMLEvent) : void 415 413 { 416 currentChannel. note = (e.data & 0x7f) + currentDriverTrack.noteShift;414 currentChannel.setNote((e.data & 0x7f) + currentDriverTrack.noteShift); 417 415 currentChannel.noteOn(); 416 } 417 418 419 private function _onSlur(e:MMLEvent) : void 420 { 421 currentDriverTrack.flagSlur = true; 422 } 423 424 425 private function _onPortament(e:MMLEvent) : void 426 { 427 currentDriverTrack.flagPortament = true; 428 } 429 430 431 private function _onRestart(e:MMLEvent) : void 432 { 418 433 } 419 434 … … 426 441 427 442 428 private function _onRestart(e:MMLEvent) : void429 {430 }431 432 443 433 444 private function _onFineVolume(e:MMLEvent) : void … … 440 451 private function _onMultiple(e:MMLEvent) : void 441 452 { 442 if (e.data < 0 || e.data > 255) throw _errorOutOfRange('ml', e.data); 443 currentChannel.mul = e.data; 453 currentChannel.mul = (e.data & 255); 444 454 } 445 455 … … 447 457 private function _onFineMultiple(e:MMLEvent) : void 448 458 { 449 // ('A`) 450 if (e.data < 0 || e.data > 32767) throw _errorOutOfRange('@ml', e.data); 451 currentChannel.mul = e.data >> 7; 459 currentChannel.fmul = (e.data & 32767); 460 } 461 462 463 private function _onPhase(e:MMLEvent) : void 464 { 465 if (e.data < 0 || e.data > 255) throw _errorOutOfRange('ph', e.data); 466 currentChannel.keyOnPhase = e.data; 452 467 } 453 468 … … 457 472 currentDriverTrack.tssModuleNum = e.data; 458 473 switch(currentDriverTrack.tssModuleNum) { 459 case 0: currentChannel.pulseGenerator = FOPMTable.PG_SQUARE; break; 460 case 1: currentChannel.pulseGenerator = FOPMTable.PG_SQUARE_FC+1; break; 461 case 2: currentChannel.pulseGenerator = FOPMTable.PG_NOISE; break; 462 case 3: currentChannel.pulseGenerator = FOPMTable.PG_SINE; break; 463 case 4: currentChannel.pulseGenerator = FOPMTable.PG_SCC; break; 464 case 5: currentChannel.pulseGenerator = FOPMTable.PG_SINE; break; 465 case 6: currentChannel.pulseGenerator = FOPMTable.PG_CUSTOM; break; 474 case 0: currentChannel.pgType = FOPMTable.PG_SQUARE; break; 475 case 1: currentChannel.pgType = FOPMTable.PG_SQUARE_FC+1; break; 476 case 2: currentChannel.pgType = FOPMTable.PG_NOISE; break; 477 case 3: currentChannel.pgType = FOPMTable.PG_SINE; break; 478 case 4: currentChannel.pgType = FOPMTable.PG_SCC; break; 479 case 5: currentChannel.pgType = FOPMTable.PG_SINE; break; 480 case 6: currentChannel.pgType = FOPMTable.PG_CUSTOM; break; 481 case 7: break; 466 482 default: 467 483 throw _errorOutOfRange('%', e.data); … … 473 489 { 474 490 switch(currentDriverTrack.tssModuleNum) { 475 case 1: 476 currentChannel.pulseGenerator = FOPMTable.PG_SQUARE_FC + ((e.data >= 0 && e.data < 8) ? (e.data) : 0); 477 break; 478 case 4: 479 currentChannel.pulseGenerator = FOPMTable.PG_SCC + ((e.data >= 0 && e.data < 256) ? (e.data) : 0); 480 break; 481 case 5: 482 currentChannel.pulseGenerator = e.data; 483 break; 484 case 6: 485 currentChannel.pulseGenerator = FOPMTable.PG_CUSTOM + ((e.data >= 0 && e.data < 256) ? (e.data) : 0); 486 break; 491 case 1: currentChannel.pgType = FOPMTable.PG_SQUARE_FC + (e.data & 7); break; 492 case 4: currentChannel.pgType = FOPMTable.PG_SCC + (e.data & 255); break; 493 case 5: currentChannel.pgType = e.data; break; 494 case 6: currentChannel.pgType = FOPMTable.PG_CUSTOM + (e.data & 255); break; 487 495 default: 488 496 break; … … 494 502 { 495 503 switch (e.data) { 496 case 0: currentChannel.pan = 0; break; 497 case 1: currentChannel.pan = 0; break; 498 case 2: currentChannel.pan = 127; break; 499 case 3: currentChannel.pan = 64; break; 500 default: throw _errorOutOfRange('p', e.data); 504 case 0: currentChannel.setPan(0); break; 505 case 1: currentChannel.setPan(0); break; 506 case 2: currentChannel.setPan(128); break; 507 case 3: currentChannel.setPan(64); break; 508 default: 509 throw _errorOutOfRange('p', e.data); 501 510 } 502 511 } … … 505 514 private function _onFinePan(e:MMLEvent) : void 506 515 { 507 if (e.data < 0 || e.data > 12 7) throw _errorOutOfRange('@p', e.data);508 currentChannel. pan = e.data;516 if (e.data < 0 || e.data > 128) throw _errorOutOfRange('@p', e.data); 517 currentChannel.setPan((e.data == int.MIN_VALUE) ? 64 : e.data); 509 518 } 510 519 … … 515 524 // SUPPOSED: 16 = 1 half tone (64 on module.keyFraction) 516 525 currentChannel.detune = (e.data == int.MIN_VALUE) ? 0 : (e.data << 2); 517 }518 519 520 private function _onPhase(e:MMLEvent) : void521 {522 if (e.data < 0 || e.data > 255) throw _errorOutOfRange('ph', e.data);523 currentChannel.keyOnPhase = e.data;524 526 } 525 527 … … 600 602 } 601 603 602 var channel: SIOscillator= currentChannel;604 var channel:FOPMChannelBase = currentChannel; 603 605 channel.ar = _s2ar[_p[0]]; 604 606 channel.dr = _s2dr[_p[1]]; … … 617 619 618 620 619 private function _on FMParam(e:MMLEvent) : MMLEvent621 private function _onOPMParam(e:MMLEvent) : MMLEvent 620 622 { 621 623 e = e.getParameters(_p, 10); 622 624 623 625 // no check !! 624 var channel:SIOscillator = currentChannel; 626 var channel:FOPMChannelBase = currentChannel; 627 channel.pgType = FOPMTable.PG_SINE; // set sine wave 625 628 if (_p[0] != int.MIN_VALUE) channel.ar = int(_p[0])<<1; // 31->63 626 629 if (_p[1] != int.MIN_VALUE) channel.dr = int(_p[1])<<1; // 31->63 … … 714 717 715 718 716 import org.si.sound.module. SIOscillator;719 import org.si.sound.module.FOPMChannelBase; 717 720 import org.si.sound.module.FOPMTable; 718 721 719 722 720 723 class TSSDriverTrack { 721 public var channel: SIOscillator;724 public var channel:FOPMChannelBase; 722 725 public var tssModuleNum:int = 0; 726 723 727 public var noteShift:int = 0; 728 public var flagSlur:Boolean = false; 729 public var flagPortament:Boolean = false; 724 730 725 731 function TSSDriverTrack() … … 727 733 } 728 734 729 public function initialize(channel: SIOscillator) :void735 public function initialize(channel:FOPMChannelBase) :void 730 736 { 731 737 this.channel = channel; 732 738 tssModuleNum = 0; 733 739 noteShift = 0; 734 channel.pulseGenerator = FOPMTable.PG_SQUARE; 740 flagSlur = false; 741 flagPortament = false; 742 channel.pgType = FOPMTable.PG_SQUARE; 735 743 channel.tl = 8; //_v2tl[255]; 736 744 channel.rr = 28; //_s2rr[16]; as3/Study/fm_module_test/src/org/si/sound/mml/MMLEvent.as
r580 r634 18 18 static public const NOTE_OFF :int = 2; 19 19 static public const NOTE_ON :int = 3; 20 static public const LENGTH :int = 4;21 static public const TEI :int = 5;22 static public const GATE_RATIO:int = 6;23 static public const GATE_COUNT:int = 7;24 static public const OCTAVE :int = 8;25 static public const OCTAVE_SHIFT :int = 9;20 //static public const LENGTH :int = 4; 21 //static public const TEI :int = 5; 22 //static public const QUANT_RATIO :int = 6; 23 //static public const QUANT_COUNT :int = 7; 24 //static public const OCTAVE :int = 8; 25 //static public const OCTAVE_SHIFT :int = 9; 26 26 static public const VOLUME :int = 10; 27 27 static public const VOLUME_SHIFT :int = 11; as3/Study/fm_module_test/src/org/si/sound/mml/MMLParser.as
r580 r634 34 34 static private var _bpm:int = 0; 35 35 static private var _staticLength:int = 0; 36 static private var _ gateRatio:int= 0;37 static private var _ gateCount:int= 0;36 static private var _quantRatio:int = 0; 37 static private var _quantCount:int = 0; 38 38 static private var _staticOctave:int = 0; 39 static private var _staticVolume:int = 0;40 39 static private var _channelNumber:int = 0; 41 40 static private var _slurFlag:Boolean = false; … … 195 194 var gateLength:int, restLength:int, 196 195 processEvent:MMLEvent = _lastEvent; 197 gateLength = (_slurFlag) ? (processEvent.data) : (processEvent.data * _ gateRatio / _setting.maxGateRatio - _gateCount);196 gateLength = (_slurFlag) ? (processEvent.data) : (processEvent.data * _quantRatio / _setting.maxQuantRatio - _quantCount); 198 197 _slurFlag = false; 199 198 if (gateLength < 0) gateLength = 0; … … 228 227 var uderex:String = (ude.length > 0) ? (ude.sort(Array.DESCENDING).join('|')) : 'a'; // ('A`) I know its an ad-hok solution... 229 228 230 var rex:String = "(" + _setting.commentRegExp + "|[ \t\r\n]+)"; // comment (res[1]) 231 rex += "|(" + _setting.systemRegExp + ")"; // system (res[2]) 232 rex += "|("; // --all-- (res[3]) 233 rex += "([a-g])([\\-+#!]?)"; // note (res[4],[5]) 234 rex += "|(" + uderex + ")"; // module events (res[6]) 235 rex += "|(@[qv]?|[rlqovt^<>()\\[\\]|,;]|" + _setting._rex + ")"; // default events (res[7]) 236 rex += ")[ \t\r\n]*(-?[0-9]*)" // parameter (res[8]) 237 rex += "[ \t\r\n]*(\\.*)" // periods (res[9]) 238 rex += "[ \t\r\n]*([&*]?)" // slur or portament (res[10]) 229 var rex:String; 230 if (_setting.commentRegExp.length != 0) rex = "(" + _setting.commentRegExp + "|[ \t\r\n]+)"; // comment (res[1]) 231 else rex = "([ \t\r\n]+)"; // whitespace (res[1]) 232 rex += "|(#[^;]*)"; // system (res[2]) 233 rex += "|("; // --all-- (res[3]) 234 rex += "([a-g])([\\-+#!]?)"; // note (res[4],[5]) 235 rex += "|(" + uderex + ")"; // module events (res[6]) 236 rex += "|(/:|:/|@[qv]?|[rlqovt^<>()\\[\\]/|:,;])"; // default events (res[7]) 237 rex += ")[ \t\r\n]*(-?[0-9]*)" // parameter (res[8]) 238 rex += "[ \t\r\n]*(\\.*)" // periods (res[9]) 239 rex += "[ \t\r\n]*([&*]?)" // slur or portament (res[10]) 239 240 _mmlRegExp = new RegExp(rex, 'gms'); 240 241 } … … 307 308 case 'l': _length (__calcLength()); break; 308 309 case '^': _tie (__calcLength()); break; 309 case 'q': _quant (__param(_setting.default GateRatio));break;310 case '@q': _at_quant (__param(_setting.default GateCount));break;310 case 'q': _quant (__param(_setting.defaultQuantRatio)); break; 311 case '@q': _at_quant (__param(_setting.defaultQuantCount)); break; 311 312 case 'o': _octave (__param(_setting.defaultOctave)); break; 312 313 case 'v': _volume (__param(_setting.defaultVolume)); break; … … 317 318 case '<': _octaveShift( __param(1)); break; 318 319 case '>': _octaveShift(-__param(1)); break; 319 case ' [': _repeatBegin( __param(2));break;320 case ' ]': _repeatEnd();break;321 case ' |': _repeatBreak();break;320 case '/:': case '[': _repeatBegin(__param(2)); break; 321 case ':/': case ']': _repeatEnd(__param()); break; 322 case '/': case '|': case ':': _repeatBreak(); break; 322 323 case ',': _parameter(__param()); break; 323 324 case ';': _channel(); break; 324 325 case 't': _tempo(__param(_setting.defaultBPM)); break; 325 326 default: 326 if (res[REX_EVENT] == _setting.loopBeginLetter) _repeatBegin(__param(2)); 327 else if (res[REX_EVENT] == _setting.loopEndLetter) _repeatEnd(); 328 else if (res[REX_EVENT] == _setting.loopBreakLetter) _repeatBreak(); 329 else throw errorUnknown("1"); 327 throw errorUnknown("1"); 330 328 break; 331 329 } … … 366 364 _bpm = _setting.defaultBPM; // initialize t command value 367 365 _staticLength = _setting.defaultLength; // initialize l command value 368 _ gateRatio = _setting.defaultGateRatio;// initialize q command value369 _ gateCount= 0; // initialize @q command value366 _quantRatio = _setting.defaultQuantRatio; // initialize q command value 367 _quantCount = 0; // initialize @q command value 370 368 _staticOctave = _setting.defaultOctave; // initialize o command value 371 _staticVolume = _setting.defaultVolume; // initialize v command value372 369 _slurFlag = false; // initialize & command flag 373 370 _repeatStac.length = 0; // clear repeating pointer stac … … 382 379 static private function _note(note:int, ilength:int, slur:*) : void 383 380 { 384 if (_setting.expandOctave) { 385 note += _staticOctave*12; 386 if (note < 0 || note > 127) throw errorNoteOutofRange(note); 387 } 388 if (_setting.expandVolume) { 389 note |= _staticVolume << 8; 390 } 391 /**/ 381 note += _staticOctave*12; 382 if (note < 0 || note > 127) throw errorNoteOutofRange(note); 392 383 if (ilength == -1) ilength = _staticLength; 393 384 if (slur) { … … 408 399 static private function _rest(ilength:int) : void 409 400 { 410 /**/411 401 if (ilength == -1) ilength = _staticLength; 412 402 addMMLEvent(MMLEvent.NOTE_OFF, 0, ilength); … … 427 417 static private function _tie(ilength:int) : void 428 418 { 429 /**/430 419 if (ilength == -1) ilength = _staticLength; 431 420 if (_lastNoteEvent) { … … 440 429 static private function _quant(param:int) : void 441 430 { 442 if (param<_setting.min GateRatio || param>_setting.maxGateRatio) {443 throw errorRangeOver("q", _setting.min GateRatio, _setting.maxGateRatio);444 } 445 _ gateRatio = param;431 if (param<_setting.minQuantRatio || param>_setting.maxQuantRatio) { 432 throw errorRangeOver("q", _setting.minQuantRatio, _setting.maxQuantRatio); 433 } 434 _quantRatio = param; 446 435 } 447 436 … … 450 439 static private function _at_quant(param:int) : void 451 440 { 452 if (param<_setting.min GateCount || param>_setting.maxGateCount) {453 throw errorRangeOver("@q", _setting.min GateCount, _setting.maxGateCount);454 } 455 _ gateCount = param * _setting.resolution / _setting.maxGateCount;441 if (param<_setting.minQuantCount || param>_setting.maxQuantCount) { 442 throw errorRangeOver("@q", _setting.minQuantCount, _setting.maxQuantCount); 443 } 444 _quantCount = param * _setting.resolution / _setting.maxQuantCount; 456 445 } 457 446 … … 466 455 } 467 456 _staticOctave = param; 468 if (!_setting.expandOctave) {469 addMMLEvent(MMLEvent.OCTAVE, param);470 }471 457 } 472 458 … … 477 463 param *= _setting.octavePolarization; 478 464 _staticOctave += param; 479 if (_setting.expandOctaveShift) {480 if (!_setting.expandOctave) {481 if (_lastEvent.id == MMLEvent.OCTAVE) {482 _lastEvent.data += param;483 } else {484 addMMLEvent(MMLEvent.OCTAVE, _staticOctave);485 }486 }487 } else {488 if (_lastEvent.id == MMLEvent.OCTAVE_SHIFT || _lastEvent.id == MMLEvent.OCTAVE) {489 _lastEvent.data += param;490 } else {491 addMMLEvent(MMLEvent.OCTAVE_SHIFT, param);492 }493 }494 465 } 495 466 … … 501 472 throw errorRangeOver("v", _setting.minVolume, _setting.maxVolume); 502 473 } 503 _staticVolume = param; 504 if (!_setting.expandVolume) { 505 addMMLEvent(MMLEvent.VOLUME, param); 506 } 474 addMMLEvent(MMLEvent.VOLUME, param); 507 475 } 508 476 … … 522 490 { 523 491 param *= _setting.volumePolarization; 524 _staticVolume += param; 525 if (_setting.expandVolumeShift) { 526 if (!_setting.expandVolume) { 527 if (_lastEvent.id == MMLEvent.VOLUME) { 528 _lastEvent.data += param; 529 } else { 530 addMMLEvent(MMLEvent.VOLUME, _staticVolume); 531 } 532 } 492 if (_lastEvent.id == MMLEvent.VOLUME_SHIFT || _lastEvent.id == MMLEvent.VOLUME) { 493 _lastEvent.data += param; 533 494 } else { 534 if (_lastEvent.id == MMLEvent.VOLUME_SHIFT || _lastEvent.id == MMLEvent.VOLUME) { 535 _lastEvent.data += param; 536 } else { 537 addMMLEvent(MMLEvent.VOLUME_SHIFT, param); 538 } 495 addMMLEvent(MMLEvent.VOLUME_SHIFT, param); 539 496 } 540 497 } … … 562 519 563 520 // end repeating 564 static private function _repeatEnd( ) : void521 static private function _repeatEnd(param:int) : void 565 522 { 566 523 if (_repeatStac.length == 0) throw errorStacUnderflow("]"); … … 569 526 _lastEvent.jump = startEvent; 570 527 startEvent.jump = _lastEvent; 528 if (param != int.MIN_VALUE) { 529 if (param < 1 || param > 65535) throw errorRangeOver("]", 1, 65535); 530 startEvent.data = param; 531 } 571 532 } 572 533 as3/Study/fm_module_test/src/org/si/sound/mml/MMLParserSetting.as
r580 r634 22 22 public var defaultLValue :int; 23 23 /** Minimum ratio of the q command. */ 24 public var min GateRatio :int;24 public var minQuantRatio :int; 25 25 /** Maximum ratio of the q command. */ 26 public var max GateRatio :int;26 public var maxQuantRatio :int; 27 27 /** Default value of the q command. */ 28 public var default GateRatio :int;28 public var defaultQuantRatio :int; 29 29 /** Minimum value of the @q command. */ 30 public var min GateCount :int;30 public var minQuantCount :int; 31 31 /** Maximum value of the @q command. */ 32 public var max GateCount :int;32 public var maxQuantCount :int; 33 33 /** Default value of the @q command. */ 34 public var default GateCount :int;34 public var defaultQuantCount :int; 35 35 /** Minimum value of the v command. */ 36 36 public var minVolume :int; … … 56 56 public var octavePolarization:int; 57 57 58 /** Expand l,q,@q commands when it compiling. This setting is not available now. */59 public var expandLength:Boolean;60 /** Expand o,<,> commands when it compiling. Expanded value is added simply on the 'data' of MMLEvent.NOTE_ON. */61 public var expandOctave:Boolean;62 /** Expand v,@v,(,) commands when it compiling. Expanded value can be picked up by (data >> 8) of MMLEvent.NOTE_ON. */63 public var expandVolume:Boolean;64 private var _expandOctaveShift:Boolean;65 private var _expandVolumeShift:Boolean;66 67 58 /** Letter to begin loop. */ 68 59 public var loopBeginLetter:String; … … 86 77 /** Default value of length in mml event. */ 87 78 public function get defaultLength() : int { return resolution / defaultLValue; } 88 89 /** Expand <,> commands as o command. */ 90 public function set expandOctaveShift(b:Boolean) : void { _expandOctaveShift = b; } 91 public function get expandOctaveShift() : Boolean { return _expandOctaveShift || expandOctave; } 92 93 /** Expand (,) commands as v command. */ 94 public function set expandVolumeShift(b:Boolean) : void { _expandVolumeShift = b; } 95 public function get expandVolumeShift() : Boolean { return _expandVolumeShift || expandVolume; } 96 79 97 80 /** Default value of the o command. */ 98 81 public function set defaultOctave(o:int) : void … … 128 111 129 112 defaultLValue = 4; 130 min GateRatio = 0;131 max GateRatio = 16;132 default GateRatio = 10;133 min GateCount = 0;134 max GateCount = 192;135 default GateCount = 0;113 minQuantRatio = 0; 114 maxQuantRatio = 16; 115 defaultQuantRatio = 10; 116 minQuantCount = 0; 117 maxQuantCount = 192; 118 defaultQuantCount = 0; 136 119 137 120 minVolume = 0; … … 142 125 defaultFineVolume = 64; 143 126 144 minOctave = 0;145 maxOctave = 8;146 defaultOctave = 4;127 minOctave = 0; 128 maxOctave = 8; 129 defaultOctave = 4; 147 130 148 131 volumePolarization = 1; 149 132 octavePolarization = 1; 150 151 expandOctaveShift = false;152 expandVolumeShift = false;153 expandLength = false;154 expandOctave = false;155 expandVolume = false;156 157 loopBeginLetter = "/:";158 loopEndLetter = ":/";159 loopBreakLetter = "/";160 systemRegExp = "#[^;]*";161 commentRegExp = "//[^\\n]*$|/\\*.*?\\*/";162 133 163 134 change(initializer); … … 175 146 if (initializer.defaultBPM != undefined) defaultBPM = initializer.defaultBPM; 176 147 177 if (initializer.defaultLValue != undefined) defaultLValue = initializer.defaultLValue;178 if (initializer.min GateRatio != undefined) minGateRatio = initializer.minGateRatio;179 if (initializer.max GateRatio != undefined) maxGateRatio = initializer.maxGateRatio;180 if (initializer.default GateRatio != undefined) defaultGateRatio = initializer.defaultGateRatio;181 if (initializer.min GateCount != undefined) minGateCount = initializer.minGateCount;182 if (initializer.max GateCount != undefined) maxGateCount = initializer.maxGateCount;183 if (initializer.default GateCount != undefined) defaultGateCount = initializer.defaultGateCount;148 if (initializer.defaultLValue != undefined) defaultLValue = initializer.defaultLValue; 149 if (initializer.minQuantRatio != undefined) minQuantRatio = initializer.minQuantRatio; 150 if (initializer.maxQuantRatio != undefined) maxQuantRatio = initializer.maxQuantRatio; 151 if (initializer.defaultQuantRatio != undefined) defaultQuantRatio = initializer.defaultQuantRatio; 152 if (initializer.minQuantCount != undefined) minQuantCount = initializer.minQuantCount; 153 if (initializer.maxQuantCount != undefined) maxQuantCount = initializer.maxQuantCount; 154 if (initializer.defaultQuantCount != undefined) defaultQuantCount = initializer.defaultQuantCount; 184 155 185 if (initializer.minVolume != undefined) minVolume = initializer.minVolume;186 if (initializer.maxVolume != undefined) maxVolume = initializer.maxVolume;187 if (initializer.defaultVolume != undefined) defaultVolume = initializer.defaultVolume;188 if (initializer.minFineVolume != undefined) minFineVolume = initializer.minFineVolume;189 if (initializer.maxFineVolume != undefined) maxFineVolume = initializer.maxFineVolume;156 if (initializer.minVolume != undefined) minVolume = initializer.minVolume; 157 if (initializer.maxVolume != undefined) maxVolume = initializer.maxVolume; 158 if (initializer.defaultVolume != undefined) defaultVolume = initializer.defaultVolume; 159 if (initializer.minFineVolume != undefined) minFineVolume = initializer.minFineVolume; 160 if (initializer.maxFineVolume != undefined) maxFineVolume = initializer.maxFineVolume; 190 161 if (initializer.defaultFineVolume != undefined) defaultFineVolume = initializer.defaultFineVolume; 191 162 192 if (initializer.minOctave != undefined) minOctave = initializer.minOctave;193 if (initializer.maxOctave != undefined) maxOctave = initializer.maxOctave;163 if (initializer.minOctave != undefined) minOctave = initializer.minOctave; 164 if (initializer.maxOctave != undefined) maxOctave = initializer.maxOctave; 194 165 if (initializer.defaultOctave != undefined) defaultOctave = initializer.defaultOctave; 195 166 196 167 if (initializer.volumePolarization != undefined) volumePolarization = initializer.volumePolarization; 197 168 if (initializer.octavePolarization != undefined) octavePolarization = initializer.volumePolarization; 198 199 if (initializer.expandOctaveShift != undefined) expandOctaveShift = initializer.expandOctaveShift;200 if (initializer.expandVolumeShift != undefined) expandVolumeShift = initializer.expandVolumeShift;201 if (initializer.expandLength != undefined) expandLength = initializer.expandLength;202 if (initializer.expandOctave != undefined) expandOctave = initializer.expandOctave;203 if (initializer.expandVolume != undefined) expandVolume = initializer.expandVolume;204 205 if (initializer.loopBeginLetter != undefined) loopBeginLetter = initializer.loopBeginLetter;206 if (initializer.loopEndLetter != undefined) loopEndLetter = initializer.loopEndLetter;207 if (initializer.loopBreakLetter != undefined) loopBreakLetter = initializer.loopBreakLetter;208 if (initializer.systemRegExp != undefined) systemRegExp = initializer.systemRegExp;209 if (initializer.commentRegExp != undefined) commentRegExp = initializer.commentRegExp;210 }211 212 213 /** @private [internal use] */214 internal function get _rex() : String215 {216 return loopBeginLetter + "|" + loopEndLetter + "|" + loopBreakLetter;217 169 } 218 170 } as3/Study/fm_module_test/src/org/si/sound/module/FOPMOscillator.as
r580 r634 12 12 13 13 14 /** OPM oscillator class */ 14 /** FOPM oscillator class.<br/> 15 * This oscillator based on the OPM emulation of MAME, but its extended in below points,<br/> 16 * 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 FOPMTable). 18 */ 15 19 public class FOPMOscillator 16 20 { … … 26 30 27 31 28 32 29 33 // valiables 30 34 //-------------------------------------------------- 31 35 /** tables */ 32 protectedvar _t:FOPMTable;36 internal var _t:FOPMTable; 33 37 34 38 /** chip */ 35 protected var _chip:SIModule;39 internal var _chip:FOPMModule; 36 40 37 41 38 42 // FM module parameters 39 43 /** Attack rate [0,63] */ 40 protectedvar _ar:int;44 internal var _ar:int; 41 45 /** Decay rate [0,63] */ 42 protectedvar _dr:int;46 internal var _dr:int; 43 47 /** Sustain rate [0,63] */ 44 protectedvar _sr:int;48 internal var _sr:int; 45 49 /** Release rate [0,63] */ 46 protectedvar _rr:int;50 internal var _rr:int; 47 51 /** Sustain level [0,15] */ 48 protectedvar _sl:int;52 internal var _sl:int; 49 53 /** Total level [0,127] */ 50 protectedvar _tl:int;54 internal var _tl:int; 51 55 /** Key scaling = 5-ks [5,2] */ 52 protected var _ks:int; 56 internal var _ks:int; 57 /** _multiple = (mul) ? (mul<<7) : 64; [64,128,256,384,512...] */ 58 internal var _multiple:int; 59 /** dt1 [0,7]. This value is linked with _freqShift */ 60 internal var _dt1:int; 61 /** dt2 [0,3]. This value is linked with _pitchIndexShift */ 62 internal var _dt2:int; 63 /** Amp modulation shift [0,3] */ 64 internal var _ams:int; 65 /** Pitch modulation shift [0,7] */ 66 internal var _pms:int; 53 67 /** Key code = oct<<4 + note [0,127] */ 54 protected var _kc:int; 55 /** dt1 [0,7]. This value is linked with _freqShift */ 56 protected var _dt1:int; 57 /** dt2 [0,3]. This value is linked with _pitchIndexShift */ 58 protected var _dt2:int; 59 /** _multiple = (ml) ? (ml<<1) : 1; [1,2,4,6,8...] */ 60 protected var _multiple:int; 68 internal var _kc:int; 61 69 62 70 63 71 // pulse generator 64 72 /** pulse generator type */ 65 protectedvar _pgType:int;73 internal var _pgType:int; 66 74 /** wave table */ 67 protectedvar _waveTable:Array;75 internal var _waveTable:Array; 68 76 /** phase shift */ 69 protected var _waveShift:int; 70 77 internal var _waveShift:int; 71 78 /** phase */ 72 protectedvar _phase:int;79 internal var _phase:int; 73 80 /** phase step */ 74 protected var _phase_step:int; 81 internal var _phase_step:int; 82 /** keyOn phase */ 83 internal var _keyon_phase:int; 84 75 85 76 86 /** pitch index = note * 64 */ 77 protectedvar _pitchIndex:int;87 internal var _pitchIndex:int; 78 88 /** pitch index shift. This value is linked with dt2. */ 79 protectedvar _pitchIndexShift:int;89 internal var _pitchIndexShift:int; 80 90 /** frequency shift. This value is linked with dt1. */ 81 protectedvar _freqShift:int;91 internal var _freqShift:int; 82 92 /** frequency modulation left-shift. 15 for FM, fb+6 for feedback. */ 83 protectedvar _fmShift:int;93 internal var _fmShift:int; 84 94 85 95 86 96 // envelop generator 87 97 /** State [EG_ATTACK, EG_DECAY, EG_SUSTAIN, EG_RELEASE, EG_OFF] */ 88 protectedvar _eg_state:int;98 internal var _eg_state:int; 89 99 /** Envelop generator updating timer, initialized (2047 * 3) << CLOCK_RATIO_BITS. */ 90 protectedvar _eg_timer:int;100 internal var _eg_timer:int; 91 101 /** Timer stepping by samples */ 92 protectedvar _eg_timer_step:int;102 internal var _eg_timer_step:int; 93 103 /** Counter rounded on 8. */ 94 protectedvar _eg_counter:int;104 internal var _eg_counter:int; 95 105 /** Internal sustain level [0,FOPMTable.ENV_BOTTOM] */ 96 protectedvar _eg_sustain_level :int;106 internal var _eg_sustain_level :int; 97 107 /** Internal total level [0,FOPMTable.ENV_BOTTOM] */ 98 protectedvar _eg_total_level :int;108 internal var _eg_total_level :int; 99 109 /** Internal key scaling = _kc >> _ks [0,32] */ 100 protectedvar _eg_key_scale_rate:int;110 internal var _eg_key_scale_rate:int; 101 111 /** Envelop generator level [0,FOPMTable.ENV_BOTTOM] */ 102 protectedvar _eg_level:int;112 internal var _eg_level:int; 103 113 /** Envelop generator output [0,FOPMTable.ENV_BOTTOM] */ 104 protectedvar _eg_out:int;114 internal var _eg_out:int; 105 115 106 116 /** Increment table picked up from _eg_incTables or _eg_incTablesAtt. */ 107 protectedvar _eg_incTable:Array;117 internal var _eg_incTable:Array; 108 118 /** The level to shift the state to next. */ 109 protectedvar _eg_stateShiftLevel:int;119 internal var _eg_stateShiftLevel:int; 110 120 111 121 112 122 // pipes 113 123 /** input pipe buffer */ 114 protectedvar _inPipe:SLLint;124 internal var _inPipe:SLLint; 115 125 /** modulation pipe buffer */ 116 protectedvar _modPipe:SLLint;126 internal var _modPipe:SLLint; 117 127 /** output pipe buffer */ 118 protectedvar _outPipe:SLLint;128 internal var _outPipe:SLLint; 119 129 /** feed back pipe buffer */ 120 protectedvar _feedPipe:SLLint;121 122 123 124 125 // properties 130 internal var _feedPipe:SLLint; 131 132 133 134 135 // properties (fm parameters) 126 136 //-------------------------------------------------- 127 137 /** Attack rate [0,63] */ 128 public function set ar(i:int) : void { _ar = i ; }138 public function set ar(i:int) : void { _ar = i & 63; } 129 139 /** Decay rate [0,63] */ 130 public function set dr(i:int) : void { _dr = i ; }140 public function set dr(i:int) : void { _dr = i & 63; } 131 141 /** Sustain rate [0,63] */ 132 public function set sr(i:int) : void { _sr = i ; }142 public function set sr(i:int) : void { _sr = i & 63; } 133 143 /** Release rate [0,63] */ 134 public function set rr(i:int) : void { _rr = i ; }144 public function set rr(i:int) : void { _rr = i & 63; } 135 145 /** Sustain level [0,15] */ 136 public function set sl(i:int) : void { _sl = i ;_eg_sustain_level = _t.eg_slTable[i]; }146 public function set sl(i:int) : void { _sl = i & 15; _eg_sustain_level = _t.eg_slTable[i]; } 137 147 /** Total level [0,127] */ 138 public function set tl(i:int) : void { _tl = i ;_eg_total_level = i<<FOPMTable.ENV_LSHIFT; _eg_out = (_eg_level + _eg_total_level)<<3; }148 public function set tl(i:int) : void { _tl = i & 127; _eg_total_level = i<<FOPMTable.ENV_LSHIFT; _eg_out = (_eg_level + _eg_total_level)<<3; } 139 149 /** Key scaling [0,3] */ 140 public function set ks(i:int) : void { _ks = 5-i; _eg_key_scale_rate = _kc >> _ks; } 141 /** Key code [0,127] */ 142 public function set kc(i:int) : void { 143 _kc = i; 144 _eg_key_scale_rate = _kc >> _ks; 145 _freqShift = (_dt1<4) ? (_t.dt1Table[_dt1][_kc>>2]) : -(_t.dt1Table[_dt1-4][_kc>>2]); 146 } 147 /** key fraction [0-63] */ 148 public function set kf(f:int) : void { 149 _pitchIndex = (_pitchIndex & 0x1fc0) | f; 150 _updateFreq(); 151 } 150 public function set ks(i:int) : void { _ks = 5-(i&3); _eg_key_scale_rate = _kc >> _ks; } 152 151 /** multiple [0-15] */ 153 152 public function set mul(m:int) : void { 154 _multiple = (m) ? (m<<1) : 1; 155 _updateFreq(); 153 m &= 15; 154 _multiple = (m) ? (m<<7) : 64; 155 _updatePhaseStep(); 156 156 } 157 157 /** dt1 [0-7] */ 158 158 public function set dt1(d:int) : void { 159 _dt1 = d ;159 _dt1 = d & 7; 160 160 _freqShift = (_dt1<4) ? (_t.dt1Table[_dt1][_kc>>2]) : -(_t.dt1Table[_dt1-4][_kc>>2]); 161 _update Freq();161 _updatePhaseStep(); 162 162 } 163 163 /** dt2 [0-3] */ 164 164 public function set dt2(d:int) : void { 165 _dt2 = d; 166 _pitchIndexShift = _t.dt2Table[d]; 167 _updateFreq(); 168 } 169 165 _dt2 = d & 3; 166 _pitchIndexShift = _t.dt2Table[_dt2]; 167 _updatePhaseStep(); 168 } 169 /** amplitude modulation switch [0-3] */ 170 public function set ams(i:int) : void { _ams = i & 3; } 171 /** phase modulation switch [0-7] */ 172 public function set pms(i:int) : void { _pms = i & 7; } 170 173 /** feed back [0-7] */ 171 174 public function set fb(f:int) : void { 172 } 173 /** noise frequency [0-31] */ 174 public function set noiseFreq(nf:int) : void { 175 _phase_step = _t.noisePeriodTable[nf]; 176 } 177 175 f &= 7; 176 _feedPipe.i = 0; 177 _fmShift = f + 6; 178 _modPipe = (f) ? _feedPipe : _chip._zeroBuffer; 179 } 178 180 179 181 public function get ar() : int { return _ar; } … … 184 186 public function get tl() : int { return _tl; } 185 187 public function get ks() : int { return 5-_ks; } 186 public function get mul() : int { return (_multiple>> 1); }188 public function get mul() : int { return (_multiple>>7); } 187 189 public function get dt1() : int { return _dt1; } 188 190 public function get dt2() : int { return _dt2; } 189 public function get fb() : int { return 0; } 191 public function get ams() : int { return _ams; } 192 public function get pms() : int { return _pms; } 193 public function get fb() : int { return (_modPipe===_feedPipe) ? (_fmShift - 6) : 0; } 194 195 196 // properties (other fm parameters) 197 //-------------------------------------------------- 198 /** Key code [0,127] */ 199 public function set kc(i:int) : void { 200 _kc = i & 127; 201 _eg_key_scale_rate = _kc >> _ks; 202 _freqShift = (_dt1<4) ? (_t.dt1Table[_dt1][_kc>>2]) : -(_t.dt1Table[_dt1-4][_kc>>2]); 203 } 204 /** key fraction [0-63] */ 205 public function set kf(f:int) : void { 206 _pitchIndex = (_pitchIndex & 0x1fc0) | (f & 63); 207 _updatePhaseStep(); 208 } 209 /** F-Number for OPNA. This property resets kf,dt2 and detune. */ 210 public function set fnum(f:int) : void { 211 // dishonest implement. 212 kc = (f >> 7) & 127; 213 _dt2 = 0; 214 _pitchIndex = 0; 215 _pitchIndexShift = 0; 216 _phase_step = (f & 2047) << ((f >> 11) & 7); 217 _phase_step += _freqShift; 218 _phase_step *= _multiple; 219 _phase_step >>= (7 - _t.sampleRatePitchShift); // 44kHz:1/128, 22kHz:1/256 220 } 221 /** Noise frequency [0-31]. This property is available only for noise generating mode. */ 222 public function set noiseFreq(nf:int) : void { 223 _phase_step = _t.noisePeriodTable[nf & 31]; 224 _phase_step += _freqShift 225 _phase_step *= _multiple; 226 _phase_step >>= (7 - _t.sampleRatePitchShift); // 44kHz:1/128, 22kHz:1/256 227 } 228 /** Noise frequency for fc short noise [0-31]. This property is available only for noise generating mode. */ 229 public function set noiseFreqFC(nf:int) : void { 230 _phase_step = _t.noisePeriodTableFC[nf]; 231 _phase_step += _freqShift 232 _phase_step *= _multiple; 233 _phase_step >>= (7 - _t.sampleRatePitchShift); // 44kHz:1/128, 22kHz:1/256 234 } 235 236 // Get status, but all of them cannot be read. 190 237 public function get kc() : int { return _kc; } 191 238 public function get kf() : int { return (_pitchIndex & 63); } 192 239 193 240 194 // internal calculation of frequency. 195 protected function _updateFreq() : void 196 { 197 if (_pgType != FOPMTable.PG_NOISE) { 198 // frequency. NOTE: This is dishonest. Pitch table is fixed at FMClock=3.56MHz. Details are shown in MAME or fmgen source. 199 _phase_step = _t.pitchTable[_pitchIndex + _pitchIndexShift]; 200 } else { 201 // noise period. NOTE: This is dishonest. Details are shown in MAME or fmgen source. 202 noiseFreq = _kc >> 2; 241 // properties (pTSS) 242 //-------------------------------------------------- 243 /** Detune for pTSS. 1 halftone divides into 64 steps. This property resets dt2. */ 244 public function set detune(d:int) : void { 245 _dt2 = 0; 246 _pitchIndexShift = d; 247 _updatePhaseStep(); 248 } 249 /** Fine multiple for pTSS. 128=x1. */ 250 public function set fmul(m:int) : void { 251 _multiple = m; 252 _updatePhaseStep(); 253 } 254 /** Phase at keyOn [0-255] for pTSS. */ 255 public function set keyOnPhase(p:int) : void { 256 _keyon_phase = (p & 255) << (FOPMTable.PHASE_BITS - 8); 257 } 258 /** Pulse generator type. */ 259 public function set pgType(n:int) : void 260 { 261 if (n < FOPMTable.DEFAULT_PG_MAX) { 262 _pgType = n; 263 _waveTable = _t.waveTables[n]; 264 _waveShift = _t.waveShifts[n]; 203 265 } 204 _phase_step += _freqShift 205 _phase_step *= _multiple; 206 _phase_step >>= (1 - _chip._sampleRatePitchShift); // 44kHz:x1, 22kHz:x2 207 } 266 } 267 268 269 // Get status, but all of them cannot be read. 270 public function get detune() : int { return _pitchIndexShift; } 271 public function get fmul() : int { return _multiple; } 272 public function get keyOnPhase() : int { return _keyon_phase >> (FOPMTable.PHASE_BITS - 8); } 273 public function get pgType() : int { return _pgType; } 208 274 209 275 … … 212 278 // constructor 213 279 //-------------------------------------------------- 214 function FOPMOscillator( )280 function FOPMOscillator(chip:FOPMModule) 215 281 { 216 282 _t = FOPMTable.instance; 283 _chip = chip; 284 _feedPipe = SLLint.allocRing(1); 217 285 } 218 286 … … 223 291 //-------------------------------------------------- 224 292 /** Initialize. */ 225 public function eg_initialize(clock:int, samplingRate:int) : void293 public function initialize() : void 226 294 { 227 295 _ar = 63; … … 229 297 _sr = 0; 230 298 _rr = 63; 231 sl = 0; 232 tl = 0; 233 ks = 0; 234 kc = 0; 299 _sl = 0; 300 _tl = 0; 301 _ks = 5; 302 _dt1 = 0; 303 _dt2 = 0; 304 _ams = 0; 305 _pms = 0; 306 307 _kc = 0; 308 _multiple = 128; 309 _eg_sustain_level = 0; 310 _eg_key_scale_rate = 0; 235 311 236 _eg_timer = FOPMTable.ENV_TIMER_INITIAL; 237 _eg_timer_step = 0; 238 _eg_counter = 0; 312 _keyon_phase = 0; 313 _phase = 0; 314 _phase_step = 0; 315 _freqShift = 0; 316 _pitchIndex = 0; 317 _pitchIndexShift = 0; 318 _fmShift = 15; 239 319 240 eg_reset(); 320 _pgType = FOPMTable.PG_SINE; 321 _waveTable = _t.waveTables[FOPMTable.PG_SINE]; 322 _waveShift = _t.waveShifts[FOPMTable.PG_SINE]; 323 324 _modPipe = _chip._zeroBuffer; 325 _inPipe = _chip._zeroBuffer; 326 _feedPipe.i = 0; 327 328 _updatePhaseStep(); 329 330 reset(); 241 331 } 242 332 243 333 244 334 /** Reset. */ 245 public function eg_reset() : void335 public function reset() : void 246 336 { 247 337 _eg_shiftState(EG_OFF); … … 249 339 _eg_timer = FOPMTable.ENV_TIMER_INITIAL; 250 340 _eg_counter = 0; 251 } 252 253 341 _phase = 0; 342 } 343 344 345 /** Set by MIDI note number [0,127] */ 346 public function setNote(n:int) : void 347 { 348 n &= 127; 349 kc = _t.nnToKC[n]; 350 // 1 halftone = 64, 6 LSBs are key fraction 351 _pitchIndex = (n << 6) | (_pitchIndex & 0x3f); 352 _updatePhaseStep(); 353 } 354 355 356 /** Note on. */ 357 public function noteOn() : void 358 { 359 if (_keyon_phase >= 0) _phase = _keyon_phase; 360 _eg_shiftState(EG_ATTACK); 361 _eg_out = (_eg_level + _eg_total_level)<<3; 362 } 363 364 365 /** Note off. */ 366 public function noteOff() : void 367 { 368 _eg_shiftState(EG_RELEASE); 369 _eg_out = (_eg_level + _eg_total_level)<<3; 370 } 371 372 373 /** Set pipes. */ 374 public function setPipes(outPipe:SLLint, modPipe:SLLint=null) : void 375 { 376 _inPipe = outPipe; 377 _outPipe = outPipe; 378 _modPipe = modPipe || _chip._zeroBuffer; 379 } 380 381 382 383 384 // internal operations 385 //-------------------------------------------------- 254 386 /** update envelop generator. */ 255 publicfunction eg_update() : void387 internal function eg_update() : void 256 388 { 257 389 _eg_timer -= _eg_timer_step; 258 390 if (_eg_timer < 0) { 259 391 if (_eg_state == EG_ATTACK) { 260 _eg_level -= 1 + (_eg_level >> _eg_incTable[_eg_counter&7]); 261 if (_eg_level <= 0) _eg_shiftState(EG_DECAY); 392 if (_eg_incTable[_eg_counter] > 0) { 393 _eg_level -= 1 + (_eg_level >> _eg_incTable[_eg_counter]); 394 if (_eg_level <= 0) _eg_shiftState(EG_DECAY); 395 } 262 396 } else { 263 _eg_level += _eg_incTable[_eg_counter &7];397 _eg_level += _eg_incTable[_eg_counter]; 264 398 if (_eg_level >= _eg_stateShiftLevel) _eg_shiftState(_eg_state+1); 265 399 } 266 400 _eg_out = (_eg_level + _eg_total_level)<<3; 267 _eg_counter ++;401 _eg_counter = (_eg_counter+1)&7; 268 402 _eg_timer += FOPMTable.ENV_TIMER_INITIAL; 269 403 } … … 272 406 273 407 /** update pulse generator. */ 274 publicfunction pg_update() : void408 internal function pg_update() : void 275 409 { 276 410 _phase += _phase_step; 277 var ph:int = _phase + (_modPipe.i << _fmShift); 278 var lg:int = _waveTable[(ph & FOPMTable.PHASE_FILTER) >> _waveShift] + _eg_out; 279 _feedPipe.i = _t.logTable[lg]; 411 var p:int = ((_phase + (_modPipe.i << _fmShift)) & FOPMTable.PHASE_FILTER) >> _waveShift; 412 var l:int = _waveTable[p]; 413 l += _eg_out; 414 _feedPipe.i = _t.logTable[l]; 280 415 _outPipe.i = _feedPipe.i + _inPipe.i; 281 416 } 282 417 283 418 284 285 286 // operations 287 //-------------------------------------------------- 288 // note on 289 public function eg_noteOn() : void 290 { 291 _eg_shiftState(EG_ATTACK); 292 _eg_out = (_eg_level + _eg_total_level)<<3; 293 } 294 295 296 // note off 297 public function eg_noteOff() : void 298 { 299 _eg_shiftState(EG_RELEASE); 300 _eg_out = (_eg_level + _eg_total_level)<<3; 301 } 302 303 304 305 306 // privates 307 //-------------------------------------------------- 308 // shift state 309 protected function _eg_shiftState(state:int) : void 419 /** shift envelop generator state. */ 420 internal function _eg_shiftState(state:int) : void 310 421 { 311 422 switch (state) { 312 423 case EG_ATTACK: 313 424 if (_ar + _eg_key_scale_rate < 62) { 314 __shift _state(EG_ATTACK, (_ar) ? (_ar + _eg_key_scale_rate) : 96);425 __shiftState(EG_ATTACK, (_ar) ? (_ar + _eg_key_scale_rate) : 96); 315 426 break; 316 427 } … … 319 430 _eg_level = 0; 320 431 _eg_stateShiftLevel = _eg_sustain_level; 321 __shift _state(EG_DECAY, (_dr) ? (_dr + _eg_key_scale_rate) : 96);432 __shiftState(EG_DECAY, (_dr) ? (_dr + _eg_key_scale_rate) : 96); 322 433 break; 323 434 } … … 325 436 _eg_level = _eg_sustain_level; 326 437 _eg_stateShiftLevel = FOPMTable.ENV_BOTTOM; 327 __shift _state(EG_SUSTAIN, (_sr) ? (_sr + _eg_key_scale_rate) : 96);438 __shiftState(EG_SUSTAIN, (_sr) ? (_sr + _eg_key_scale_rate) : 96); 328 439 break; 329 440 case EG_RELEASE: 330 441 if (_eg_level < FOPMTable.ENV_BOTTOM) { 331 442 _eg_stateShiftLevel = FOPMTable.ENV_BOTTOM; 332 __shift _state(EG_RELEASE, _rr + _eg_key_scale_rate);443 __shiftState(EG_RELEASE, _rr + _eg_key_scale_rate); 333 444 break; 334 445 } … … 337 448 _eg_level = FOPMTable.ENV_BOTTOM; 338 449 _eg_stateShiftLevel = FOPMTable.ENV_BOTTOM+1; 339 __shift _state(EG_OFF, 96);450 __shiftState(EG_OFF, 96); 340 451 break; 341 452 } 342 453 343 454 344 function __shift _state(state:int, r:int) : void455 function __shiftState(state:int, r:int) : void 345 456 { 346 457 _eg_state = state; 347 458 _eg_incTable = (state == EG_ATTACK) ? (_t.eg_incTablesAtt[_t.eg_tableSelector[r]]) : (_t.eg_incTables[_t.eg_tableSelector[r]]); 348 _eg_timer_step = _t.eg_timerSteps[r] * _chip._clock_ratio;459 _eg_timer_step = _t.eg_timerSteps[r]; 349 460 } 461 } 462 463 464 /** internal calculation of frequency. */ 465 internal function _updatePhaseStep() : void 466 { 467 // frequency. 468 _phase_step = _t.pitchTable[_pitchIndex + _pitchIndexShift]; 469 _phase_step += _freqShift 470 _phase_step *= _multiple; 471 _phase_step >>= (7 - _t.sampleRatePitchShift); // 44kHz:1/128, 22kHz:1/256 350 472 } 351 473 } as3/Study/fm_module_test/src/org/si/sound/module/FOPMTable.as
r580 r634 25 25 static public const PULSE_OUTPUT_MAX :Number = 0.5; 26 26 27 static public const ENV_BOTTOM :int = (1 << ENV_BITS)-1; // Minimum value of envelop output28 27 static public const ENV_LSHIFT :int = ENV_BITS - 7; // Shift number from input tl [0,127] to internal value [0,ENV_BOTTOM]. 29 28 static public const ENV_TIMER_INITIAL :int = (2047 * 3) << CLOCK_RATIO_BITS; // envelop timer initial value … … 37 36 static public const NOISE_PHASE_MAX :int = 1 << (PHASE_BITS - NOISE_TABLE_BITS); 38 37 static public const LOG_TABLE_SIZE :int = LOG_TABLE_MAX_BITS * LOG_TABLE_RESOLUTION * 2; // *2 posi&nega 38 static public const ENV_BOTTOM :int = (LOG_TABLE_SIZE >> 2); // minimum gain of envelop = 832 39 39 40 40 static public const PG_SINE :int = 0; … … 59 59 public var eg_incTables:Array = [ // eg_incTables[19][8] 60 60 /*cycle: 0 1 2 3 4 5 6 7 */ 61 /* 0*/ [0,1, 0,1, 0,1, 0,1], /* rates 00..11 0 (increment by 0 or 1) */62 /* 1*/ [0,1, 0,1, 1,1, 0,1], /* rates 00..11 1 */63 /* 2*/ [0,1, 1,1, 0,1, 1,1], /* rates 00..11 2 */64 /* 3*/ [0,1, 1,1, 1,1, 1,1], /* rates 00..11 3 */65 /* 4*/ [1,1, 1,1, 1,1, 1,1], /* rate 12 0 (increment by 1) */66 /* 5*/ [1,1, 1,2, 1,1, 1,2], /* rate 12 1 */67 /* 6*/ [1,2, 1,2, 1,2, 1,2], /* rate 12 2 */68 /* 7*/ [1,2, 2,2, 1,2, 2,2], /* rate 12 3 */69 /* 8*/ [2,2, 2,2, 2,2, 2,2], /* rate 13 0 (increment by 2) */70 /* 9*/ [2,2, 2,4, 2,2, 2,4], /* rate 13 1 */71 /*10*/ [2,4, 2,4, 2,4, 2,4], /* rate 13 2 */72 /*11*/ [2,4, 4,4, 2,4, 4,4], /* rate 13 3 */73 /*12*/ [4,4, 4,4, 4,4, 4,4], /* rate 14 0 (increment by 4) */74 /*13*/ [4,4, 4,8, 4,4, 4,8], /* rate 14 1 */75 /*14*/ [4,8, 4,8, 4,8, 4,8], /* rate 14 2 */76 /*15*/ [4,8, 8,8, 4,8, 8,8], /* rate 14 3 */77 /*16*/ [8,8, 8,8, 8,8, 8,8], /* rates 15 0, 15 1, 15 2, 15 3 (increment by 8) */78 /*17*/ [0,0, 0,0, 0,0, 0,0] ,/* infinity rates for attack and decay(s) */61 /* 0*/ [0,1, 0,1, 0,1, 0,1], /* rates 00..11 0 (increment by 0 or 1) */ 62 /* 1*/ [0,1, 0,1, 1,1, 0,1], /* rates 00..11 1 */ 63 /* 2*/ [0,1, 1,1, 0,1, 1,1], /* rates 00..11 2 */ 64 /* 3*/ [0,1, 1,1, 1,1, 1,1], /* rates 00..11 3 */ 65 /* 4*/ [1,1, 1,1, 1,1, 1,1], /* rate 12 0 (increment by 1) */ 66 /* 5*/ [1,1, 1,2, 1,1, 1,2], /* rate 12 1 */ 67 /* 6*/ [1,2, 1,2, 1,2, 1,2], /* rate 12 2 */ 68 /* 7*/ [1,2, 2,2, 1,2, 2,2], /* rate 12 3 */ 69 /* 8*/ [2,2, 2,2, 2,2, 2,2], /* rate 13 0 (increment by 2) */ 70 /* 9*/ [2,2, 2,4, 2,2, 2,4], /* rate 13 1 */ 71 /*10*/ [2,4, 2,4, 2,4, 2,4], /* rate 13 2 */ 72 /*11*/ [2,4, 4,4, 2,4, 4,4], /* rate 13 3 */ 73 /*12*/ [4,4, 4,4, 4,4, 4,4], /* rate 14 0 (increment by 4) */ 74 /*13*/ [4,4, 4,8, 4,4, 4,8], /* rate 14 1 */ 75 /*14*/ [4,8, 4,8, 4,8, 4,8], /* rate 14 2 */ 76 /*15*/ [4,8, 8,8, 4,8, 8,8], /* rate 14 3 */ 77 /*16*/ [8,8, 8,8, 8,8, 8,8], /* rates 15 0, 15 1, 15 2, 15 3 (increment by 8) */ 78 /*17*/ [0,0, 0,0, 0,0, 0,0] /* infinity rates for attack and decay(s) */ 79 79 ]; 80 /** EG:increment table for attack. This shortcut is based on fmgen (shift= 16 equals x0). */80 /** EG:increment table for attack. This shortcut is based on fmgen (shift=0 means x0). */ 81 81 public var eg_incTablesAtt:Array = [ 82 82 /*cycle: 0 1 2 3 4 5 6 7 */ 83 /* 0*/ [ 16, 4, 16, 4, 16, 4, 16,4], /* rates 00..11 0 (increment by 0 or 1) */84 /* 1*/ [ 16, 4, 16, 4, 4, 4, 16,4], /* rates 00..11 1 */85 /* 2*/ [ 16, 4, 4, 4, 16, 4, 4,4], /* rates 00..11 2 */86 /* 3*/ [ 16, 4, 4, 4, 4, 4, 4,4], /* rates 00..11 3 */87 /* 4*/ [ 4, 4, 4, 4, 4, 4, 4,4], /* rate 12 0 (increment by 1) */88 /* 5*/ [ 4, 4, 4, 3, 4, 4, 4,3], /* rate 12 1 */89 /* 6*/ [ 4, 3, 4, 3, 4, 3, 4,3], /* rate 12 2 */90 /* 7*/ [ 4, 3, 3, 3, 4, 3, 3,3], /* rate 12 3 */91 /* 8*/ [ 3, 3, 3, 3, 3, 3, 3,3], /* rate 13 0 (increment by 2) */92 /* 9*/ [ 3, 3, 3, 2, 3, 3, 3,2], /* rate 13 1 */93 /*10*/ [ 3, 2, 3, 2, 3, 2, 3,2], /* rate 13 2 */94 /*11*/ [ 3, 2, 2, 2, 3, 2, 2,2], /* rate 13 3 */95 /*12*/ [ 2, 2, 2, 2, 2, 2, 2,2], /* rate 14 0 (increment by 4) */96 /*13*/ [ 2, 2, 2, 1, 2, 2, 2,1], /* rate 14 1 */97 /*14*/ [ 2, 8, 2, 1, 2, 1, 2,1], /* rate 14 2 */98 /*15*/ [ 2, 1, 1, 1, 2, 1, 1,1], /* rate 14 3 */99 /*16*/ [ 1, 1, 1, 1, 1, 1, 1,1], /* rates 15 0, 15 1, 15 2, 15 3 (increment by 8) */100 /*17*/ [ 16,16, 16,16, 16,16, 16,16],/* infinity rates for attack and decay(s) */83 /* 0*/ [0,4, 0,4, 0,4, 0,4], /* rates 00..11 0 (increment by 0 or 1) */ 84 /* 1*/ [0,4, 0,4, 4,4, 0,4], /* rates 00..11 1 */ 85 /* 2*/ [0,4, 4,4, 0,4, 4,4], /* rates 00..11 2 */ 86 /* 3*/ [0,4, 4,4, 4,4, 4,4], /* rates 00..11 3 */ 87 /* 4*/ [4,4, 4,4, 4,4, 4,4], /* rate 12 0 (increment by 1) */ 88 /* 5*/ [4,4, 4,3, 4,4, 4,3], /* rate 12 1 */ 89 /* 6*/ [4,3, 4,3, 4,3, 4,3], /* rate 12 2 */ 90 /* 7*/ [4,3, 3,3, 4,3, 3,3], /* rate 12 3 */ 91 /* 8*/ [3,3, 3,3, 3,3, 3,3], /* rate 13 0 (increment by 2) */ 92 /* 9*/ [3,3, 3,2, 3,3, 3,2], /* rate 13 1 */ 93 /*10*/ [3,2, 3,2, 3,2, 3,2], /* rate 13 2 */ 94 /*11*/ [3,2, 2,2, 3,2, 2,2], /* rate 13 3 */ 95 /*12*/ [2,2, 2,2, 2,2, 2,2], /* rate 14 0 (increment by 4) */ 96 /*13*/ [2,2, 2,1, 2,2, 2,1], /* rate 14 1 */ 97 /*14*/ [2,8, 2,1, 2,1, 2,1], /* rate 14 2 */ 98 /*15*/ [2,1, 1,1, 2,1, 1,1], /* rate 14 3 */ 99 /*16*/ [1,1, 1,1, 1,1, 1,1], /* rates 15 0, 15 1, 15 2, 15 3 (increment by 8) */ 100 /*17*/ [0,0, 0,0, 0,0, 0,0] /* infinity rates for attack and decay(s) */ 101 101 ]; 102 102 /** EG:table selector. */ … … 113 113 /** PG:noise period table. */ 114 114 public var noisePeriodTable:Array = null; 115 /** PG:noise period table for fc short noise. */ 116 public var noisePeriodTableFC:Array = null; 115 117 116 118 /** PG:MIDI note number to FM key code. */ … … 133 135 /** int->Number ratio on pulse data */ 134 136 public var i2n:Number; 137 /** (clock/64/sampling_rate)<<CLOCK_RATIO_BITS */ 138 public var clock_ratio:int; 139 /** 44100Hz=0, 22050Hz=1 */ 140 public var sampleRatePitchShift:int; 135 141 136 142 … … 145 151 function FOPMTable(clock:int, rate:int) 146 152 { 147 _createEGTables(clock, rate); 148 _createPGTables(clock, rate); 149 _createWaveSamples(clock, rate); 150 } 151 152 153 private function _createEGTables(clock:int, rate:int) : void 153 _setConstants(clock, rate); 154 _createEGTables(); 155 _createPGTables(); 156 _createWaveSamples(); 157 } 158 159 160 private function _setConstants(clock:int, rate:int) : void 161 { 162 sampleRatePitchShift = (rate == 44100) ? 0 : (rate == 22050) ? 1 : -1; 163 if (sampleRatePitchShift == -1) throw new Error("FOPMTable error : Sampling rate ("+ rate + ") is not supported."); 164 clock_ratio = ((clock/64)<<CLOCK_RATIO_BITS)/rate; 165 } 166 167 168 private function _createEGTables() : void 154 169 { 155 170 // 128 = 64rates + 32ks-rates + 32dummies for dr,sr=0 … … 159 174 var i:int = 0; 160 175 for (; i< 44; i++) { // rate = 0-43 161 eg_timerSteps [i] = 1<<(i>>2);176 eg_timerSteps [i] = int((1<<(i>>2)) * clock_ratio); 162 177 eg_tableSelector[i] = (i & 3); 163 178 } 164 179 for (; i< 48; i++) { // rate = 44-47 165 eg_timerSteps [i] = 2047;180 eg_timerSteps [i] = int(2047 * clock_ratio); 166 181 eg_tableSelector[i] = (i & 3); 167 182 } 168 183 for (; i< 60; i++) { // rate = 48-59 169 eg_timerSteps [i] = 2047;184 eg_timerSteps [i] = int(2047 * clock_ratio); 170 185 eg_tableSelector[i] = i - 44; 171 186 } 172 187 for (; i< 96; i++) { // rate = 60-95 (rate=60-95 are same as rate=63(maximum)) 173 eg_timerSteps [i] = 2047;188 eg_timerSteps [i] = int(2047 * clock_ratio); 174 189 eg_tableSelector[i] = 16; 175 190 } … … 187 202 188 203 189 private function _createPGTables( clock:int, rate:int) : void204 private function _createPGTables() : void 190 205 { 191 206 // multipurpose … … 216 231 217 232 // log table 218 logTable = new Array( (ENV_BOTTOM<<3) * 3); // *3(2more zerofillarea) 1024*8*3 = 24576233 logTable = new Array(LOG_TABLE_SIZE * 3); // *3(2more zerofillarea) 13*256*2*3 = 24576 219 234 imax = LOG_TABLE_RESOLUTION * 2; // *2(posi&nega) 220 235 jmax = LOG_TABLE_SIZE; … … 234 249 for (i=jmax; i<imax; i++) { logTable[i] = int(0); } 235 250 236 // noise period table. NOTE: This is dishonest. Pitch table is fixed at FMClock=3.56MHz. Details are shown in MAME source.251 // noise period table. 237 252 noisePeriodTable = new Array(32); 238 n = NOISE_PHASE_MAX ;253 n = NOISE_PHASE_MAX * clock_ratio; // clock_ratio = ((clock/64)/rate) << CLOCK_RATIO_BITS 239 254 for (i=0; i<31; i++) { 240 noisePeriodTable[i] = int(n / ((32-i)*0.5) * 1.2684240362811791); // 1.2684240362811791 = (3.58MHz/64)/44.1kHz255 noisePeriodTable[i] = (int(n / ((32-i)*0.5))) >> CLOCK_RATIO_BITS; 241 256 } 242 257 noisePeriodTable[31] = noisePeriodTable[30]; 243 } 244 245 246 private function _createWaveSamples(clock:int, rate:int) : void 258 noisePeriodTableFC = new Array(32); 259 n = SAMPLING_TABLE_SIZE * clock_ratio; // clock_ratio = ((clock/64)/rate) << CLOCK_RATIO_BITS 260 for (i=0; i<31; i++) { 261 noisePeriodTableFC[i] = (int(n / ((32-i)*0.5))) >> CLOCK_RATIO_BITS; 262 } 263 noisePeriodTableFC[31] = noisePeriodTableFC[30]; 264 } 265 266 267 private function _createWaveSamples() : void 247 268 { 248 269 // multipurpose … … 270 291 for (i=0, p=dp*0.5; i<imax; i++, p+=dp) { 271 292 iv = calcLogTableIndex(p); 272 table1[i] = iv; // positive index273 table1[imax*2-i-1] = iv+1; // negative value index274 table2[i ] = iv+1; // positive index275 table2[imax *2-i-1] = iv; // negative value index293 table1[i] = iv; // positive 294 table1[imax*2-i-1] = iv+1; // negative 295 table2[imax-i-1] = iv; // positive 296 table2[imax+i] = iv+1; // negative 276 297 } 277 298 waveTables[PG_SAW] = table1; as3/Study/fm_module_test/test/caution.txt
r580 r634 2 2 3 3 4 長 い MML は 【 確 実 に 】ハ ン グ る4 演 奏 時 間 が 長 い MML は 【 確 実 に 】ハ ン グ る 5 5 6 6 7 7 どっちもsazamekiが100%データ生成してから再生するので,30秒くらいが多分限界. 8 FM音源ユニット自体は, FP10の低レベルサウンド操作を考慮して設計してある.8 FM音源ユニット自体は,一応FP10の低レベルサウンド操作を考慮して設計してあるけど,動くかはわからない. 9 9 コンパイルにはac3/sazameki/trunk/srcが必要. 10 10 … … 18 18 test/tss/ 19 19 偽tsscp互換っぽいMML(色々未実装)でFM音源ユニットをならすてすつ. 20 21 @fmコマンドを追加.10パラメータ↓ 22 @fm ar[0-31],dr[0-31],sr[0-31],rr[0-31],sl[0-15],tl[0-127],ks[0-3],ml[0-15],dt1[0-7],dt2[0-3] 20 @opmコマンドを追加.10パラメータ.↓ 21 @opm ar[0-31],dr[0-31],sr[0-31],rr[0-31],sl[0-15],tl[-24-127],ks[0-3],ml[0-15],dt1[0-7],dt2[0-3] 23 22 24 23 … … 28 27 パイプ処理は,tsscpっぽく#FMマクロを使って26オペまで接続可. 29 28 opmと同じにするならモジュレーション5を指定,フィードバックは-1する. 30 波形は,sin,三角,鋸,矩形,ノイズ,ファミ矩形,ファミ三角,ファミ短ノイズ,#WAVでSCC,から選択. 29 波形を,sin(%5@0),三角(%5@4),鋸(%5@1,@2),矩形(%0),ノイズ(%2),ファミ矩形(%1),ファミ三角(%5@3),ファミ短ノイズ(%5@7),#WAVでSCC(%4),から選択. 30 初期位相を,phで指定可.tl は-24から指定可(音が歪む). 31 31 32 32 偽tsscpドライバ 33 33 実装は /src/org/si/sound/driver/ 辺り. 34 34 MMLは偽tsscp準拠だけど,音源はあくまでopmベース. 35 ドライバ内で,偽tssのパラメータを,opm上何となく近い値に変換してる.なので再現性は 壊滅的.35 ドライバ内で,偽tssのパラメータを,opm上何となく近い値に変換してる.なので再現性は皆無. 36 36 37 37 mml文法 as3/Study/fm_module_test/test/ssGenerator/main.as
r580 r634 31 31 32 32 var mml:String = "mml:\n"; 33 mml += "#A= %3@fm22/ 5/0/3/ 5/41/0/1/3/0@f6;\n";34 mml += "#B= %3@fm16/ 8/8/7/ 2/ 6/1/2/3/0;\n";35 mml += "#C= %3@fm31/18/0/3/10/44/0/8/7/0;\n";36 mml += "#D= %3@fm31/ 9/7/7/ 2/ 9/1/1/7/0;\n";33 mml += "#A=@opm22/ 5/0/3/ 5/41/0/1/3/0@f6;\n"; 34 mml += "#B=@opm16/ 8/8/7/ 2/ 6/1/2/3/0;\n"; 35 mml += "#C=@opm31/18/0/3/10/44/0/8/7/0;\n"; 36 mml += "#D=@opm31/ 9/7/7/ 2/ 9/1/1/7/0;\n"; 37 37 mml += "#K=cdefedcrefgagfercrcrcrcrcdefedc;\n"; 38 38 mml += "#L=o6K;\n"; … … 68 68 { 69 69 if (e.keyCode == Keyboard.ENTER && e.shiftKey) { 70 ssGen.generateByString(tf.text); 71 tf.type = 'dynamic'; 70 try { 71 ssGen.generateByString(tf.text); 72 tf.type = 'dynamic'; 73 } 74 catch(e:Error) { 75 msg.text = e.toString(); 76 } 72 77 } 73 78 } as3/Study/fm_module_test/test/tss/main.as
r580 r634 48 48 49 49 var mml:String; 50 mml = "#A= %3@fm22, 5, 0, 3, 5,41, 0, 1, 3, 0@f6;\n"51 mml += "#B= %3@fm16, 8, 8, 7, 2, 6, 1, 2, 3, 0;\n"52 mml += "#C= %3@fm31,18, 0, 3,10,44, 0, 8, 7, 0;\n"53 mml += "#D= %3@fm31, 9, 7, 7, 2, 9, 1, 1, 7, 0;\n"50 mml = "#A=@opm22, 5, 0, 3, 5,41, 0, 1, 3, 0@f6;\n" 51 mml += "#B=@opm16, 8, 8, 7, 2, 6, 1, 2, 3, 0;\n" 52 mml += "#C=@opm31,18, 0, 3,10,44, 0, 8, 7, 0;\n" 53 mml += "#D=@opm31, 9, 7, 7, 2, 9, 1, 1, 7, 0;\n" 54 54 mml += "#K=cdefedcrefgagfercrcrcrcrcdefedc;\n" 55 55 mml += "#L=o6K;\n" … … 107 107 private function _executeMML(mml:String, maxProcessTime:int) : void 108 108 { 109 __begin(mml); 110 addEventListener(Event.ENTER_FRAME, __onEnterFrame); 109 try { 110 __begin(mml); 111 addEventListener(Event.ENTER_FRAME, __onEnterFrame); 112 } 113 catch(e:Error) { 114 msg.text = e.toString(); 115 } 111 116 112 117 function __onEnterFrame(e:Event) : void { 113 if (__process(maxProcessTime)) { 118 try { 119 if (__process(maxProcessTime)) { 120 removeEventListener(Event.ENTER_FRAME, __onEnterFrame); 121 __end(); 122 } 123 msg.text = "\n\n\nprocessing completed : " + totalWaveLength + "[ms]\n"; 124 } 125 catch(e:Error) { 126 msg.text = e.toString(); 114 127 removeEventListener(Event.ENTER_FRAME, __onEnterFrame); 115 __end();116 128 } 117 msg.text = "\n\n\nprocessing completed : " + totalWaveLength + "[ms]\n";118 129 } 119 130 }

