Changeset 15293 for lang/actionscript
- Timestamp:
- 07/06/08 22:12:37 (5 years ago)
- Location:
- lang/actionscript/flmml/trunk/src
- Files:
-
- 9 modified
-
com/txt_nifty/sketch/flmml/MChannel.as (modified) (6 diffs)
-
com/txt_nifty/sketch/flmml/MEnvelope.as (modified) (4 diffs)
-
com/txt_nifty/sketch/flmml/MEvent.as (modified) (2 diffs)
-
com/txt_nifty/sketch/flmml/MFilter.as (modified) (4 diffs)
-
com/txt_nifty/sketch/flmml/MML.as (modified) (1 diff)
-
com/txt_nifty/sketch/flmml/MSequencer.as (modified) (1 diff)
-
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
r14833 r15293 25 25 private var m_lpfFrq:Number; 26 26 private var m_lpfRes:Number; 27 private var m_volMode:int; 27 28 public static var PITCH_RESOLUTION:int = 100; 28 29 protected static var s_init:int = 0; 29 30 protected static var s_frequencyMap:Array = new Array(128 * PITCH_RESOLUTION); 30 31 protected static var s_frequencyLen:int; 32 protected static var s_volumeMap:Array = new Array(128); 33 protected static var s_volumeLen:int; 31 34 protected static var s_samples:Array; 32 35 … … 54 57 m_lpfFrq = 0; 55 58 m_lpfRes = 0; 59 m_volMode = 0; 56 60 } 57 61 public static function boot(numSamples:int):void { … … 61 65 for(i = 0; i < s_frequencyLen; i++) { 62 66 s_frequencyMap[i] = 440.0 * Math.pow(2.0, (i-69*PITCH_RESOLUTION)/(12*PITCH_RESOLUTION)); 67 } 68 s_volumeLen = s_volumeMap.length; 69 s_volumeMap[0] = 0.0; 70 for(i = 1; i < s_volumeLen; i++) { 71 s_volumeMap[i] = Math.pow(10.0, (i-127.0)*(48.0/(127.0*20.0))); // min:-48db 72 //trace(i+","+s_volumeMap[i]); 63 73 } 64 74 s_init = 1; … … 87 97 m_oscillator2.resetPhase(); 88 98 m_filter.reset(); 89 m_velocity = velocity / 127.0;99 m_velocity = (m_volMode) ? s_volumeMap[velocity] : velocity / 127.0; 90 100 m_onCounter = 0; 91 101 } … … 157 167 if (m_lpfRes > 1.0) m_lpfRes = 1.0; 158 168 } 159 protected function getNextSample():Number { 160 return m_oscillator1.getNextSample() * m_envelope1.getNextAmplitude() * m_velocity; 169 public function setVolMode(m:int):void { 170 m_volMode = m; 171 } 172 protected function getNextSampleLinear():Number { 173 return m_oscillator1.getNextSample() * m_envelope1.getNextAmplitudeLinear() * m_velocity; 174 } 175 protected function getNextSampleNonLinear():Number { 176 return m_oscillator1.getNextSample() * m_envelope1.getNextAmplitudeNonLinear() * m_velocity; 161 177 } 162 178 protected function getNextCutoff():Number { 163 var cut:Number = m_lpfFrq + m_lpfAmt * m_envelope2.getNextAmplitude ();179 var cut:Number = m_lpfFrq + m_lpfAmt * m_envelope2.getNextAmplitudeLinear(); 164 180 cut = getFrequency(cut) * m_oscillator1.getFrequency() * (2.0 * Math.PI / (Audio.RATE44100 * 440.0)); 165 181 if (cut < (1.0/127.0)) cut = 0.0; … … 178 194 // no LFO 179 195 m_oscillator1.getSamples(s_samples, start, end); 180 m_envelope1.ampSamples(s_samples, start, end, m_velocity); 196 if (m_volMode == 0) m_envelope1.ampSamplesLinear(s_samples, start, end, m_velocity); 197 else m_envelope1.ampSamplesNonLinear(s_samples, start, end, m_velocity); 181 198 } 182 199 else { 183 // with LFO 184 for(i = start; i < end; i++) { 185 freqNo = m_freqNo; 186 if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 187 freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 200 // with LFO, linear 201 if (m_volMode == 0) { 202 for(i = start; i < end; i++) { 203 freqNo = m_freqNo; 204 if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 205 freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 206 } 207 m_oscillator1.setFrequency(getFrequency(freqNo)); 208 s_samples[i] = getNextSampleLinear(); 209 m_onCounter++; 188 210 } 189 m_oscillator1.setFrequency(getFrequency(freqNo)); 190 s_samples[i] = getNextSample(); 191 m_onCounter++; 211 } 212 // with LFO, non linear 213 else { 214 for(i = start; i < end; i++) { 215 freqNo = m_freqNo; 216 if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 217 freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 218 } 219 m_oscillator1.setFrequency(getFrequency(freqNo)); 220 s_samples[i] = getNextSampleNonLinear(); 221 m_onCounter++; 222 } 192 223 } 193 224 } -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MEnvelope.as
r13769 r15293 20 20 private var m_timeInSamples:int; 21 21 private var m_startAmplitude:Number; 22 protected static var s_init:int = 0; 23 protected static var s_volumeMap:Array = new Array(256); 24 protected static var s_volumeLen:int; 22 25 23 26 public function MEnvelope(attack:Number, decay:Number, sustain:Number, release:Number) { … … 31 34 m_releaseStep = 0; 32 35 } 36 37 public static function boot():void { 38 if (!s_init) { 39 s_volumeLen = s_volumeMap.length; 40 s_volumeMap[0] = 0.0; 41 for(var i:int = 1; i < s_volumeLen; i++) { 42 s_volumeMap[i] = Math.pow(10.0, (i-255.0)*(48.0/(255.0*20.0))); // min:-48db 43 } 44 s_init = 1; 45 } 46 } 33 47 34 48 public function setAD(attack:Number, decay:Number):void { … … 55 69 } 56 70 57 public function getNextAmplitude ():Number {71 public function getNextAmplitudeLinear():Number { 58 72 if (!m_playing) return 0; 59 73 var val:Number; … … 82 96 return m_currentVal; 83 97 } 98 public function getNextAmplitudeNonLinear():Number { 99 if (!m_playing) return 0; 100 var val:Number; 101 var offset:Number = (m_timeInSamples as Number) / Audio.RATE44100; 102 103 if (!m_releasing) { 104 if (offset < m_attack) { // attack phase 105 val = m_startAmplitude + (1 - m_startAmplitude) * offset / m_attack; 106 } 107 else if (offset < (m_attack + m_decay)) { //decay phase 108 val = 1.0 - ((offset - m_attack) / m_decay) * (1.0 - m_sustain); 109 } 110 else if (offset >= (m_attack + m_decay)) { //sustain phase 111 val = m_sustain; 112 } 113 } 114 else { 115 val = m_currentVal - m_releaseStep; //release phase 116 } 117 118 if (val < 0) { 119 m_playing = false; 120 } 121 m_currentVal = Math.max(0, val); 122 ++m_timeInSamples; 123 var d:int = m_currentVal * 255.0; 124 return s_volumeMap[d]; 125 } 84 126 85 public function ampSamples (samples:Array, start:int, end:int, velocity:Number):void {127 public function ampSamplesLinear(samples:Array, start:int, end:int, velocity:Number):void { 86 128 var i:int; 87 129 for(i = start; i < end; i++) { 88 samples[i] = Number(samples[i]) * getNextAmplitude() * velocity; 130 samples[i] = Number(samples[i]) * getNextAmplitudeLinear() * velocity; 131 } 132 } 133 public function ampSamplesNonLinear(samples:Array, start:int, end:int, velocity:Number):void { 134 var i:int; 135 for(i = start; i < end; i++) { 136 samples[i] = Number(samples[i]) * getNextAmplitudeNonLinear() * velocity; 89 137 } 90 138 } -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MEvent.as
r14830 r15293 39 39 public function setLPFFRQRES(frq:int, res:int):void { set(MStatus.LPF_FRQRES, frq, res); } 40 40 public function setClose():void { set(MStatus.CLOSE, 0, 0); } 41 public function setVolMode(m:int):void { set(MStatus.VOL_MODE, m, 0); } 41 42 public function setDelta(delta:int):void { m_delta = delta; } 42 43 public function getStatus():int { return m_status; } … … 66 67 public function getLPFFrq():int { return m_data0; } 67 68 public function getLPFRes():int { return m_data1; } 69 public function getVolMode():int { return m_data0; } 68 70 } 69 71 } -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MFilter.as
r14830 r15293 46 46 if (amt > 0.0001 || amt < -0.0001) { 47 47 for(i = start; i < end; i++) { 48 cut = MChannel.getFrequency(frq + amt * envelope.getNextAmplitude ()) * k;48 cut = MChannel.getFrequency(frq + amt * envelope.getNextAmplitudeLinear()) * k; 49 49 if (cut < (1.0/127.0)) cut = 0.0; 50 50 if (cut > (1.0-0.0001)) cut = 1.0-0.0001; … … 70 70 var k:Number = key * (2.0 * Math.PI / (Audio.RATE44100 * 440.0)); 71 71 for(var i:int = start; i < end; i++) { 72 var cut:Number = MChannel.getFrequency(frq + amt * envelope.getNextAmplitude ()) * k;72 var cut:Number = MChannel.getFrequency(frq + amt * envelope.getNextAmplitudeLinear()) * k; 73 73 if (cut < (1.0/127.0)) cut = 0.0; 74 74 if (cut > 1.0) cut = 1.0; … … 98 98 if (amt > 0.0001 || amt < -0.0001) { 99 99 for(i = start; i < end; i++) { 100 cut = MChannel.getFrequency(frq + amt * envelope.getNextAmplitude ()) * k;100 cut = MChannel.getFrequency(frq + amt * envelope.getNextAmplitudeLinear()) * k; 101 101 if (cut < (1.0/127.0)) cut = 0.0; 102 102 if (cut > (1.0-0.0001)) cut = 1.0-0.0001; … … 126 126 var k:Number = key * (2.0 * Math.PI / (Audio.RATE44100 * 440.0)); 127 127 for(var i:int = start; i < end; i++) { 128 var cut:Number = MChannel.getFrequency(frq + amt * envelope.getNextAmplitude ()) * k;128 var cut:Number = MChannel.getFrequency(frq + amt * envelope.getNextAmplitudeLinear()) * k; 129 129 if (cut < (1.0/127.0)) cut = 0.0; 130 130 if (cut > 1.0) cut = 1.0; -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MML.as
r14830 r15293 242 242 case '@': 243 243 atmark(); 244 break; 245 case 'x': 246 m_tracks[m_trackNo].recVolMode(getUInt(1)); 244 247 break; 245 248 default: -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MSequencer.as
r14830 r15293 24 24 MChannel.boot(multiple * Audio.RATE44100); 25 25 MOscillator.boot(); 26 MEnvelope.boot(); 26 27 m_trackArr = new Array(); 27 28 m_volume = 100; -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MStatus.as
r14830 r15293 24 24 public static const LPF_FRQRES:int = 19; 25 25 public static const CLOSE:int = 20; 26 public static const VOL_MODE:int = 21; 26 27 } 27 28 } -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MTrack.as
r14833 r15293 123 123 m_ch.setLpfFrqRes(e.getLPFFrq(), e.getLPFRes()); 124 124 break; 125 case MStatus.VOL_MODE: 126 m_ch.setVolMode(e.getVolMode()); 127 break; 125 128 case MStatus.CLOSE: 126 129 m_ch.close(); … … 326 329 e = new MEvent(); 327 330 e.setLPFFRQRES(frq, res); 331 m_events.push(e); 332 } 333 334 public function recVolMode(m:int): void { 335 var e:MEvent = new MEvent(); 336 recDelta(e); 337 e.setVolMode(m); 328 338 m_events.push(e); 329 339 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)