comparison audioio/ContinuousSynth.cpp @ 327:d2c13ec0f148 tonioni

scale gain of synth wave, replace tabs with spaces
author Justin Salamon <justin.salamon@nyu.edu>
date Fri, 17 Jan 2014 11:59:49 -0500
parents 8e44c7302cf3
children 8d2112977aa0 72c662fe7ea3
comparison
equal deleted inserted replaced
326:8e44c7302cf3 327:d2c13ec0f148
46 46
47 bool wasOn = (m_prevF0 > 0.f); 47 bool wasOn = (m_prevF0 > 0.f);
48 bool nowOn = (f0 > 0.f); 48 bool nowOn = (f0 > 0.f);
49 49
50 if (!nowOn && !wasOn) { 50 if (!nowOn && !wasOn) {
51 m_phase = 0; 51 m_phase = 0;
52 return; 52 return;
53 } 53 }
54 54
55 int fadeLength = 100; // samples 55 int fadeLength = 100; // samples
56 56
57 float *levels = new float[m_channels]; 57 float *levels = new float[m_channels];
58 58
59 for (int c = 0; c < m_channels; ++c) { 59 for (int c = 0; c < m_channels; ++c) {
60 levels[c] = gain; 60 levels[c] = gain * 0.5; // scale gain otherwise too loud compared to source
61 } 61 }
62 if (pan != 0.0 && m_channels == 2) { 62 if (pan != 0.0 && m_channels == 2) {
63 levels[0] *= 1.0 - pan; 63 levels[0] *= 1.0 - pan;
64 levels[1] *= pan + 1.0; 64 levels[1] *= pan + 1.0;
65 } 65 }
66 66
67 // cerr << "ContinuousSynth::mix: f0 = " << f0 << " (from " << m_prevF0 << "), phase = " << m_phase << endl; 67 // cerr << "ContinuousSynth::mix: f0 = " << f0 << " (from " << m_prevF0 << "), phase = " << m_phase << endl;
68 68
69 for (int i = 0; i < m_blockSize; ++i) { 69 for (int i = 0; i < m_blockSize; ++i) {
80 m_phase = m_phase + phasor; 80 m_phase = m_phase + phasor;
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;
138 138
139 for (int c = 0; c < m_channels; ++c) { 139 for (int c = 0; c < m_channels; ++c) {
140 toBuffers[c][i] += levels[c] * v; 140 toBuffers[c][i] += levels[c] * v;
141 } 141 }
142 } 142 }
143 } 143 }
144 144
145 m_prevF0 = f0; 145 m_prevF0 = f0;
146 146
147 delete[] levels; 147 delete[] levels;
148 } 148 }