comparison audioio/ContinuousSynth.cpp @ 326:8e44c7302cf3 tonioni

Indentation only
author Chris Cannam
date Fri, 17 Jan 2014 08:40:01 +0000
parents 7bdfbaa8d93f
children d2c13ec0f148
comparison
equal deleted inserted replaced
325:7bdfbaa8d93f 326:8e44c7302cf3
23 m_channels(channels), 23 m_channels(channels),
24 m_sampleRate(sampleRate), 24 m_sampleRate(sampleRate),
25 m_blockSize(blockSize), 25 m_blockSize(blockSize),
26 m_prevF0(-1.f), 26 m_prevF0(-1.f),
27 m_phase(0.0), 27 m_phase(0.0),
28 m_wavetype(waveType) // 0: 3 sinusoids, 1: 1 sinusoid, 2: sawtooth, 3: square 28 m_wavetype(waveType) // 0: 3 sinusoids, 1: 1 sinusoid, 2: sawtooth, 3: square
29 { 29 {
30 } 30 }
31 31
32 ContinuousSynth::~ContinuousSynth() 32 ContinuousSynth::~ContinuousSynth()
33 { 33 {
81 81
82 int harmonics = (m_sampleRate / 4) / fHere - 1; 82 int harmonics = (m_sampleRate / 4) / fHere - 1;
83 if (harmonics < 1) harmonics = 1; 83 if (harmonics < 1) harmonics = 1;
84 84
85 switch (m_wavetype) { 85 switch (m_wavetype) {
86 case 1: 86 case 1:
87 harmonics = 1; 87 harmonics = 1;
88 break; 88 break;
89 case 2: 89 case 2:
90 break; 90 break;
91 case 3: 91 case 3:
92 break; 92 break;
93 default: 93 default:
94 harmonics = 3; 94 harmonics = 3;
95 break; 95 break;
96 } 96 }
97 97
98 98
99 for (int h = 0; h < harmonics; ++h) { 99 for (int h = 0; h < harmonics; ++h) {
100 100
101 double v = 0; 101 double v = 0;
102 double hn = 0; 102 double hn = 0;
103 double hp = 0; 103 double hp = 0;
104 104
105 switch (m_wavetype) { 105 switch (m_wavetype) {
106 case 1: // single sinusoid 106 case 1: // single sinusoid
107 v = sin(m_phase); 107 v = sin(m_phase);
108 break; 108 break;
109 case 2: // sawtooth 109 case 2: // sawtooth
110 if (h != 0) { 110 if (h != 0) {
111 hn = h + 1;
112 hp = m_phase * hn;
113 v = -(1.0 / M_PI) * sin(hp) / hn;
114 } else {
115 v = 0.5;
116 }
117 break;
118 case 3: // square
119 hn = h*2 + 1;
120 hp = m_phase * hn;
121 v = sin(hp) / hn;
122 break;
123 default: // 3 sinusoids
124 hn = h + 1; 111 hn = h + 1;
125 hp = m_phase * hn; 112 hp = m_phase * hn;
126 v = sin(hp) / hn; 113 v = -(1.0 / M_PI) * sin(hp) / hn;
127 break; 114 } else {
128 } 115 v = 0.5;
116 }
117 break;
118 case 3: // square
119 hn = h*2 + 1;
120 hp = m_phase * hn;
121 v = sin(hp) / hn;
122 break;
123 default: // 3 sinusoids
124 hn = h + 1;
125 hp = m_phase * hn;
126 v = sin(hp) / hn;
127 break;
128 }
129 129
130 if (!wasOn && i < fadeLength) { 130 if (!wasOn && i < fadeLength) {
131 // fade in 131 // fade in
132 v = v * (i / double(fadeLength)); 132 v = v * (i / double(fadeLength));
133 } else if (!nowOn) { 133 } else if (!nowOn) {