Changeset 14830
- Timestamp:
- 06/29/08 14:11:52 (5 years ago)
- Location:
- lang/actionscript/flmml/trunk/src
- Files:
-
- 1 added
- 1 removed
- 8 modified
-
com/txt_nifty/sketch/flmml/MChannel.as (modified) (8 diffs)
-
com/txt_nifty/sketch/flmml/MEvent.as (modified) (1 diff)
-
com/txt_nifty/sketch/flmml/MFilter.as (added)
-
com/txt_nifty/sketch/flmml/MLPFilter.as (deleted)
-
com/txt_nifty/sketch/flmml/MML.as (modified) (2 diffs)
-
com/txt_nifty/sketch/flmml/MOscillator.as (modified) (1 diff)
-
com/txt_nifty/sketch/flmml/MSequencer.as (modified) (3 diffs)
-
com/txt_nifty/sketch/flmml/MStatus.as (modified) (1 diff)
-
com/txt_nifty/sketch/flmml/MTrack.as (modified) (2 diffs)
-
flmml.swf (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MChannel.as
r13769 r14830 12 12 private var m_osc2Connect:int; 13 13 private var m_osc2Sign:Number; 14 private var m_ lpfilter:MLPFilter;15 private var m_ lpfConnect:int;14 private var m_filter:MFilter; 15 private var m_filterConnect:int; 16 16 private var m_formant:MFormant; 17 17 private var m_velocity:Number; // velocity (max:1.0) … … 42 42 m_oscillator2.setForm(MOscillator.SINE); 43 43 m_osc2Connect = 0; 44 m_ lpfilter = new MLPFilter();45 m_ lpfConnect = 0;44 m_filter = new MFilter(); 45 m_filterConnect = 0; 46 46 m_formant = new MFormant(); 47 47 m_velocity = 100.0 / 127.0; … … 88 88 m_oscillator1.resetPhase(); 89 89 m_oscillator2.resetPhase(); 90 m_filter.reset(); 90 91 m_velocity = velocity / 127.0; 91 92 m_onCounter = 0; … … 94 95 m_envelope1.releaseEnvelope(); 95 96 m_envelope2.releaseEnvelope(); 97 } 98 public function close():void { 99 noteOff(); 100 m_filter.setSwitch(0); 96 101 } 97 102 public function setNoiseFreq(frequency:Number):void { … … 140 145 } 141 146 public function setLpfSwtAmt(swt:int, amt:int):void { 142 //if (swt == 1) m_lpfConnect = 1; else m_lpfConnect = 0; 147 if (-3 < swt && swt < 3 && swt != m_filterConnect) { 148 m_filterConnect = swt; 149 m_filter.setSwitch(swt); 150 } 143 151 m_lpfAmt = ((amt < -127) ? -127 : (amt < 127) ? amt : 127) * PITCH_RESOLUTION; 144 152 } … … 147 155 if (frq > 127) frq = 127; 148 156 m_lpfFrq = frq * PITCH_RESOLUTION; 149 m_lpfRes = res * ( 4.0 / 127.0);157 m_lpfRes = res * (1.0 / 127.0); 150 158 if (m_lpfRes < 0.0) m_lpfRes = 0.0; 151 if (m_lpfRes > 4.0) m_lpfRes = 4.0;159 if (m_lpfRes > 1.0) m_lpfRes = 1.0; 152 160 } 153 161 public function getNextSample():Number { … … 156 164 public function getNextCutoff():Number { 157 165 var cut:Number = m_lpfFrq + m_lpfAmt * m_envelope2.getNextAmplitude(); 158 cut = getFrequency(cut) * m_oscillator1.getFrequency() * ( 6.0/ (Audio.RATE44100 * 440.0));166 cut = getFrequency(cut) * m_oscillator1.getFrequency() * (2.0 * Math.PI / (Audio.RATE44100 * 440.0)); 159 167 if (cut < (1.0/127.0)) cut = 0.0; 160 if (cut > 1.0) cut = 1.0;161 168 return cut; 162 169 } … … 169 176 var i:int; 170 177 if (end >= max) end = max; 178 var key:Number = m_oscillator1.getFrequency(); 171 179 if (m_osc2Connect == 0) { 172 if (m_lpfConnect == 0) { 173 // no LFO, no LPF 174 m_oscillator1.getSamples(s_samples, start, end); 175 m_envelope1.ampSamples(s_samples, start, end, m_velocity); 180 // no LFO 181 m_oscillator1.getSamples(s_samples, start, end); 182 m_envelope1.ampSamples(s_samples, start, end, m_velocity); 183 } 184 else { 185 // with LFO 186 for(i = start; i < end; i++) { 187 freqNo = m_freqNo; 188 if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 189 freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 190 } 191 m_oscillator1.setFrequency(getFrequency(freqNo)); 192 s_samples[i] = getNextSample(); 193 m_onCounter++; 176 194 } 177 else {178 // no LFO, with LPF179 m_oscillator1.getSamples(s_samples, start, end);180 m_envelope1.ampSamples(s_samples, start, end, m_velocity);181 for(i = start; i < end; i++) {182 s_samples[i] = m_lpfilter.getNextSample(s_samples[i], getNextCutoff(), m_lpfRes);183 }184 }185 }186 else {187 // with LFO, no LPF188 if (m_lpfConnect == 0) {189 for(i = start; i < end; i++) {190 freqNo = m_freqNo;191 if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) {192 freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth;193 }194 m_oscillator1.setFrequency(getFrequency(freqNo));195 s_samples[i] = getNextSample();196 m_onCounter++;197 }198 }199 // with LFO, with LPF200 else {201 for(i = start; i < end; i++) {202 freqNo = m_freqNo;203 if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) {204 freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth;205 }206 m_oscillator1.setFrequency(getFrequency(freqNo));207 s_samples[i] = getNextSample();208 s_samples[i] = m_lpfilter.getNextSample(s_samples[i], getNextCutoff(), m_lpfRes);209 m_onCounter++;210 }211 }212 195 } 213 196 m_formant.run(s_samples, start, end); 197 m_filter.run(s_samples, start, end, m_envelope2, m_lpfFrq, m_lpfAmt, m_lpfRes, key); 214 198 for(i = start; i < end; i++) { 215 199 amplitude = s_samples[i]; -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MEvent.as
r13769 r14830 38 38 public function setLPFSWTAMT(swt:int, amt:int):void { set(MStatus.LPF_SWTAMT, swt, amt); } 39 39 public function setLPFFRQRES(frq:int, res:int):void { set(MStatus.LPF_FRQRES, frq, res); } 40 public function setClose():void { set(MStatus.CLOSE, 0, 0); } 40 41 public function setDelta(delta:int):void { m_delta = delta; } 41 42 public function getStatus():int { return m_status; } -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MML.as
r13952 r14830 166 166 } 167 167 break; 168 case 'f': // low passFilter168 case 'f': // Filter 169 169 { 170 170 var swt:int = 0, amt:int = 0, frq:int = 0, res:int = 0; 171 171 next(); 172 swt = get UInt(swt);172 swt = getSInt(swt); 173 173 if (getChar() == ',') { 174 174 next(); … … 592 592 for(var i:int = MTrack.TEMPO_TRACK; i < m_tracks.length; i++) { 593 593 m_tracks[i].recRest(384); 594 m_tracks[i].recClose(); 595 m_tracks[i].recRest(96); 594 596 m_tracks[i].recEOT(); 595 597 m_sequencer.connect(m_tracks[i]); -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MOscillator.as
r13769 r14830 90 90 public function getSamples(samples:Array, start:int, end:int):void { 91 91 var i:int; 92 var dp:Number = 1.0 / Audio.RATE44100; 92 93 switch(m_form) { 93 94 case SINE: 95 dp *= m_frequency; 94 96 for(i = start; i < end; i++) { 95 samples[i] = Number(s_sinTable[int(m_phase * s_sinLen)]);96 m_phase += (m_frequency * (1.0 / Audio.RATE44100));97 samples[i] = s_sinTable[int(m_phase * s_sinLen)] as Number; 98 m_phase += dp; 97 99 if (m_phase > 1.0) m_phase -= 1.0; 98 100 } 99 101 break; 100 102 case SAW: 103 dp *= m_frequency; 101 104 for(i = start; i < end; i++) { 102 105 samples[i] = m_phase / 0.5 - 1.0; 103 m_phase += (m_frequency * (1.0 / Audio.RATE44100));106 m_phase += dp; 104 107 if (m_phase > 1.0) m_phase -= 1.0; 105 108 } 106 109 break; 107 110 case TRIANGLE: 111 dp *= m_frequency; 108 112 for(i = start; i < end; i++) { 109 113 samples[i] = (m_phase < 0.5) ? (1.0 - 4.0 * m_phase) : (1.0 - 4.0 * (1.0 - m_phase)); 110 m_phase += (m_frequency * (1.0 / Audio.RATE44100));114 m_phase += dp; 111 115 if (m_phase > 1.0) m_phase -= 1.0; 112 116 } 113 117 break; 114 118 case PULSE: 119 dp *= m_frequency; 115 120 for(i = start; i < end; i++) { 116 121 samples[i] = (m_phase < m_pwm) ? 1.0 : -1.0; 117 m_phase += (m_frequency * (1.0 / Audio.RATE44100));122 m_phase += dp; 118 123 if (m_phase > 1.0) m_phase -= 1.0; 119 124 } 120 125 break; 121 126 case NOISE: 127 dp *= m_noiseFreq; 122 128 for(i = start; i < end; i++) { 123 samples[i] = Number(s_rndTable[int(m_phase * s_rndLen)]);124 m_phase += m_noiseFreq * (1.0 / Audio.RATE44100);129 samples[i] = s_rndTable[int(m_phase * s_rndLen)] as Number; 130 m_phase += dp; 125 131 if (m_phase > 1.0) m_phase -= 1.0; 126 132 } -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MSequencer.as
r13952 r14830 10 10 protected static const STATUS_BUFFERING:int = 2; 11 11 protected static const STATUS_PLAY:int = 3; 12 protected static const STATUS_LAST1:int = 4; 13 protected static const STATUS_LAST2:int = 5; 12 14 protected var m_audioBuffer:AudioBuffer; 13 15 protected var m_trackArr:Array; … … 100 102 private function onAudioBufferComplete(buffer:AudioBuffer):void { 101 103 if (m_status < STATUS_BUFFERING) return; 104 if (m_status == STATUS_LAST2) { 105 stop(); 106 dispatchEvent(new MMLEvent(MMLEvent.COMPLETE)); 107 return; 108 } 109 if (m_status == STATUS_LAST1) m_status++; 102 110 //var starttime:Date = new Date(); 103 111 var samples:Array = buffer.getSamples(); … … 135 143 136 144 // end of sequence 137 var n:int = 0;138 for (i = 0; i < m_trackArr.length; i++) {139 if (m_trackArr[i].isEnd()) n++;140 }141 if (n >= m_trackArr.length) {142 stop();143 dispatchEvent(new MMLEvent(MMLEvent.COMPLETE));144 m_status = STATUS_STOP;145 if (m_status == STATUS_PLAY) { 146 var n:int = 0; 147 for (i = 0; i < m_trackArr.length; i++) { 148 if (m_trackArr[i].isEnd()) n++; 149 } 150 if (n >= m_trackArr.length) { 151 m_status = STATUS_LAST1; 152 } 145 153 } 146 154 -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MStatus.as
r13769 r14830 23 23 public static const LPF_SWTAMT:int = 18; 24 24 public static const LPF_FRQRES:int = 19; 25 public static const CLOSE:int = 20; 25 26 } 26 27 } -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MTrack.as
r13769 r14830 123 123 m_ch.setLpfFrqRes(e.getLPFFrq(), e.getLPFRes()); 124 124 break; 125 case MStatus.CLOSE: 126 m_ch.close(); 127 break; 125 128 case MStatus.EOT: 126 m_ch.noteOff();127 129 m_isEnd = 1; 128 130 break; … … 322 324 e = new MEvent(); 323 325 e.setLPFFRQRES(frq, res); 326 m_events.push(e); 327 } 328 329 public function recClose():void { 330 var e:MEvent = new MEvent(); 331 e.setClose(); 324 332 m_events.push(e); 325 333 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)