root/lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MOscTriangle.as @ 38797

Revision 38797, 2.8 kB (checked in by tekisuke, 2 years ago)

@aloerinさんの代理コミット。
#USING POLYによるポリフォニック(複数発音)指定が追加されました。
その他、#TITLE, #COMMENT, #ARTIST, #CODINGなど各種情報を埋め込めるようになりました。

Line 
1package com.txt_nifty.sketch.flmml {
2    import __AS3__.vec.Vector;
3
4    public class MOscTriangle extends MOscMod {
5        public static const MAX_WAVE:int = 2;
6        protected static var s_init:int = 0;
7        protected static var s_table:Vector.<Vector.<Number>>;
8        protected var m_waveNo:int;
9
10        public function MOscTriangle() {
11            boot();
12            super();
13            setWaveNo(0);
14        }
15        public static function boot():void {
16            if (s_init) return;
17            var d0:Number = 1.0 / TABLE_LEN;
18            var p0:Number;
19            var i:int;
20            s_table = new Vector.<Vector.<Number>>(MAX_WAVE);
21            for (i = 0; i < MAX_WAVE; i++) {
22                s_table[i] = new Vector.<Number>(TABLE_LEN, true);
23            }                   
24            for(i = 0, p0 = 0.0; i < TABLE_LEN; i++) {
25                s_table[0][i] = (p0 < 0.50) ? (1.0-4.0* p0) : (1.0-4.0*(1.0-p0));
26                s_table[1][i] = (p0 < 0.25) ? (0.0-4.0* p0) : ((p0 < 0.75) ? (-2.0+4.0* p0) : (4.0-4.0* p0));
27                p0 += d0;
28            }
29            s_init = 1;
30        }
31        public override function getNextSample():Number {
32            var val:Number = s_table[m_waveNo][m_phase >> PHASE_SFT];
33            m_phase = (m_phase + m_freqShift) & PHASE_MSK;
34            return val;
35        }
36        public override function getNextSampleOfs(ofs:int):Number {
37            var val:Number = s_table[m_waveNo][((m_phase + ofs) & PHASE_MSK) >> PHASE_SFT];
38            m_phase = (m_phase + m_freqShift) & PHASE_MSK;
39            return val;
40        }
41        public override function getSamples(samples:Vector.<Number>, start:int, end:int):void {
42            var i:int;
43            for(i = start; i < end; i++) {
44                samples[i] = s_table[m_waveNo][m_phase >> PHASE_SFT];
45                m_phase = (m_phase + m_freqShift) & PHASE_MSK;
46            }
47        }
48        public override function getSamplesWithSyncIn(samples:Vector.<Number>, syncin:Vector.<Boolean>, start:int, end:int):void {
49                        var i:int;
50                        for(i = start; i < end; i++) {
51                                if(syncin[i]){
52                                        resetPhase();
53                                }
54                samples[i] = s_table[m_waveNo][m_phase >> PHASE_SFT];
55                m_phase = (m_phase + m_freqShift) & PHASE_MSK;
56                        }               
57        }
58        public override function getSamplesWithSyncOut(samples:Vector.<Number>, syncout:Vector.<Boolean>, start:int, end:int):void {
59                        var i:int;
60                        for(i = start; i < end; i++) {
61                samples[i] = s_table[m_waveNo][m_phase >> PHASE_SFT];
62                m_phase += m_freqShift;
63                syncout[i] = (m_phase > PHASE_MSK);
64                m_phase &= PHASE_MSK;
65                        }               
66        }
67        public override function setWaveNo(waveNo:int):void {
68            m_waveNo = Math.min(waveNo, MAX_WAVE-1);
69        }               
70    }
71}
Note: See TracBrowser for help on using the browser.