87
// if we have no sub-osc, we can't do any modulation... just get our samples
88
void oscillator::updateNoSub( sampleFrame * _ab, const fpab_t _frames,
89
const ch_cnt_t _chnl )
92
float osc_coeff = *m_freq * *m_detuning;
94
for( fpab_t frame = 0; frame < _frames; ++frame )
96
_ab[frame][_chnl] = getSample( m_phase ) * *m_volume;
102
// do pm by using sub-osc as modulator
103
void oscillator::updatePM( sampleFrame * _ab, const fpab_t _frames,
104
const ch_cnt_t _chnl )
106
m_subOsc->update( _ab, _frames, _chnl );
108
float osc_coeff = *m_freq * *m_detuning;
110
for( fpab_t frame = 0; frame < _frames; ++frame )
112
_ab[frame][_chnl] = getSample( m_phase + _ab[frame][_chnl] )
114
m_phase += osc_coeff;
119
// do am by using sub-osc as modulator
120
void oscillator::updateAM( sampleFrame * _ab, const fpab_t _frames,
121
const ch_cnt_t _chnl )
123
m_subOsc->update( _ab, _frames, _chnl );
125
float osc_coeff = *m_freq * *m_detuning;
127
for( fpab_t frame = 0; frame < _frames; ++frame )
129
_ab[frame][_chnl] *= getSample( m_phase ) * *m_volume;
130
m_phase += osc_coeff;
135
// do mix by using sub-osc as mix-sample
136
void oscillator::updateMix( sampleFrame * _ab, const fpab_t _frames,
137
const ch_cnt_t _chnl )
139
m_subOsc->update( _ab, _frames, _chnl );
141
float osc_coeff = *m_freq * *m_detuning;
143
for( fpab_t frame = 0; frame < _frames; ++frame )
145
_ab[frame][_chnl] += getSample( m_phase ) * *m_volume;
146
m_phase += osc_coeff;
151
// sync with sub-osc (every time sub-osc starts new period, we also start new
153
void oscillator::updateSync( sampleFrame * _ab, const fpab_t _frames,
154
const ch_cnt_t _chnl )
156
float sub_osc_coeff = m_subOsc->syncInit( _ab, _frames, _chnl );
158
float osc_coeff = *m_freq * *m_detuning;
160
for( fpab_t frame = 0; frame < _frames ; ++frame )
162
if( m_subOsc->syncOk( sub_osc_coeff ) )
164
m_phase = m_phaseOffset;
166
_ab[frame][_chnl] = getSample( m_phase ) * *m_volume;
167
m_phase += osc_coeff;
174
// do fm by using sub-osc as modulator
175
void oscillator::updateFM( sampleFrame * _ab, const fpab_t _frames,
176
const ch_cnt_t _chnl )
178
m_subOsc->update( _ab, _frames, _chnl );
180
float osc_coeff = *m_freq * *m_detuning;
182
for( fpab_t frame = 0; frame < _frames; ++frame )
184
m_phase += _ab[frame][_chnl];
185
_ab[frame][_chnl] = getSample( m_phase ) * *m_volume;
186
m_phase += osc_coeff;
193
inline sample_t oscillator::getSample( const float _sample )
195
switch( *m_waveShape )
198
return( sinSample( _sample ) );
200
return( triangleSample( _sample ) );
202
return( sawSample( _sample ) );
204
return( squareSample( _sample ) );
206
return( moogSawSample( _sample ) );
208
return( expSample( _sample ) );
209
case WHITE_NOISE_WAVE:
210
return( noiseSample( _sample ) );
212
return( userWaveSample( _sample ) );
214
return( sinSample( _sample ) );
87
void oscillator::updateNoSub( sampleFrame * _ab, const fpp_t _frames,
88
const ch_cnt_t _chnl )
94
updateNoSub<SIN_WAVE>( _ab, _frames, _chnl );
97
updateNoSub<TRIANGLE_WAVE>( _ab, _frames, _chnl );
100
updateNoSub<SAW_WAVE>( _ab, _frames, _chnl );
103
updateNoSub<SQUARE_WAVE>( _ab, _frames, _chnl );
106
updateNoSub<MOOG_SAW_WAVE>( _ab, _frames, _chnl );
109
updateNoSub<EXP_WAVE>( _ab, _frames, _chnl );
111
case WHITE_NOISE_WAVE:
112
updateNoSub<WHITE_NOISE_WAVE>( _ab, _frames, _chnl );
115
updateNoSub<USER_DEF_WAVE>( _ab, _frames, _chnl );
123
void oscillator::updatePM( sampleFrame * _ab, const fpp_t _frames,
124
const ch_cnt_t _chnl )
126
switch( m_waveShape )
130
updatePM<SIN_WAVE>( _ab, _frames, _chnl );
133
updatePM<TRIANGLE_WAVE>( _ab, _frames, _chnl );
136
updatePM<SAW_WAVE>( _ab, _frames, _chnl );
139
updatePM<SQUARE_WAVE>( _ab, _frames, _chnl );
142
updatePM<MOOG_SAW_WAVE>( _ab, _frames, _chnl );
145
updatePM<EXP_WAVE>( _ab, _frames, _chnl );
147
case WHITE_NOISE_WAVE:
148
updatePM<WHITE_NOISE_WAVE>( _ab, _frames, _chnl );
151
updatePM<USER_DEF_WAVE>( _ab, _frames, _chnl );
159
void oscillator::updateAM( sampleFrame * _ab, const fpp_t _frames,
160
const ch_cnt_t _chnl )
162
switch( m_waveShape )
166
updateAM<SIN_WAVE>( _ab, _frames, _chnl );
169
updateAM<TRIANGLE_WAVE>( _ab, _frames, _chnl );
172
updateAM<SAW_WAVE>( _ab, _frames, _chnl );
175
updateAM<SQUARE_WAVE>( _ab, _frames, _chnl );
178
updateAM<MOOG_SAW_WAVE>( _ab, _frames, _chnl );
181
updateAM<EXP_WAVE>( _ab, _frames, _chnl );
183
case WHITE_NOISE_WAVE:
184
updateAM<WHITE_NOISE_WAVE>( _ab, _frames, _chnl );
187
updateAM<USER_DEF_WAVE>( _ab, _frames, _chnl );
195
void oscillator::updateMix( sampleFrame * _ab, const fpp_t _frames,
196
const ch_cnt_t _chnl )
198
switch( m_waveShape )
202
updateMix<SIN_WAVE>( _ab, _frames, _chnl );
205
updateMix<TRIANGLE_WAVE>( _ab, _frames, _chnl );
208
updateMix<SAW_WAVE>( _ab, _frames, _chnl );
211
updateMix<SQUARE_WAVE>( _ab, _frames, _chnl );
214
updateMix<MOOG_SAW_WAVE>( _ab, _frames, _chnl );
217
updateMix<EXP_WAVE>( _ab, _frames, _chnl );
219
case WHITE_NOISE_WAVE:
220
updateMix<WHITE_NOISE_WAVE>( _ab, _frames, _chnl );
223
updateMix<USER_DEF_WAVE>( _ab, _frames, _chnl );
231
void oscillator::updateSync( sampleFrame * _ab, const fpp_t _frames,
232
const ch_cnt_t _chnl )
234
switch( m_waveShape )
238
updateSync<SIN_WAVE>( _ab, _frames, _chnl );
241
updateSync<TRIANGLE_WAVE>( _ab, _frames, _chnl );
244
updateSync<SAW_WAVE>( _ab, _frames, _chnl );
247
updateSync<SQUARE_WAVE>( _ab, _frames, _chnl );
250
updateSync<MOOG_SAW_WAVE>( _ab, _frames, _chnl );
253
updateSync<EXP_WAVE>( _ab, _frames, _chnl );
255
case WHITE_NOISE_WAVE:
256
updateSync<WHITE_NOISE_WAVE>( _ab, _frames, _chnl );
259
updateSync<USER_DEF_WAVE>( _ab, _frames, _chnl );
267
void oscillator::updateFM( sampleFrame * _ab, const fpp_t _frames,
268
const ch_cnt_t _chnl )
270
switch( m_waveShape )
274
updateFM<SIN_WAVE>( _ab, _frames, _chnl );
277
updateFM<TRIANGLE_WAVE>( _ab, _frames, _chnl );
280
updateFM<SAW_WAVE>( _ab, _frames, _chnl );
283
updateFM<SQUARE_WAVE>( _ab, _frames, _chnl );
286
updateFM<MOOG_SAW_WAVE>( _ab, _frames, _chnl );
289
updateFM<EXP_WAVE>( _ab, _frames, _chnl );
291
case WHITE_NOISE_WAVE:
292
updateFM<WHITE_NOISE_WAVE>( _ab, _frames, _chnl );
295
updateFM<USER_DEF_WAVE>( _ab, _frames, _chnl );
253
334
m_subOsc->update( _ab, _frames, _chnl );
256
return( *m_freq * *m_detuning );
337
return( m_freq * m_detuning );
343
// if we have no sub-osc, we can't do any modulation... just get our samples
344
template<oscillator::waveShapes W>
345
void oscillator::updateNoSub( sampleFrame * _ab, const fpp_t _frames,
346
const ch_cnt_t _chnl )
349
const float osc_coeff = m_freq * m_detuning;
351
for( fpp_t frame = 0; frame < _frames; ++frame )
353
_ab[frame][_chnl] = getSample<W>( m_phase ) * m_volume;
354
m_phase += osc_coeff;
361
// do pm by using sub-osc as modulator
362
template<oscillator::waveShapes W>
363
void oscillator::updatePM( sampleFrame * _ab, const fpp_t _frames,
364
const ch_cnt_t _chnl )
366
m_subOsc->update( _ab, _frames, _chnl );
368
const float osc_coeff = m_freq * m_detuning;
370
for( fpp_t frame = 0; frame < _frames; ++frame )
372
_ab[frame][_chnl] = getSample<W>( m_phase + _ab[frame][_chnl] )
374
m_phase += osc_coeff;
381
// do am by using sub-osc as modulator
382
template<oscillator::waveShapes W>
383
void oscillator::updateAM( sampleFrame * _ab, const fpp_t _frames,
384
const ch_cnt_t _chnl )
386
m_subOsc->update( _ab, _frames, _chnl );
388
const float osc_coeff = m_freq * m_detuning;
390
for( fpp_t frame = 0; frame < _frames; ++frame )
392
_ab[frame][_chnl] *= getSample<W>( m_phase ) * m_volume;
393
m_phase += osc_coeff;
400
// do mix by using sub-osc as mix-sample
401
template<oscillator::waveShapes W>
402
void oscillator::updateMix( sampleFrame * _ab, const fpp_t _frames,
403
const ch_cnt_t _chnl )
405
m_subOsc->update( _ab, _frames, _chnl );
407
const float osc_coeff = m_freq * m_detuning;
409
for( fpp_t frame = 0; frame < _frames; ++frame )
411
_ab[frame][_chnl] += getSample<W>( m_phase ) * m_volume;
412
m_phase += osc_coeff;
419
// sync with sub-osc (every time sub-osc starts new period, we also start new
421
template<oscillator::waveShapes W>
422
void oscillator::updateSync( sampleFrame * _ab, const fpp_t _frames,
423
const ch_cnt_t _chnl )
425
const float sub_osc_coeff = m_subOsc->syncInit( _ab, _frames, _chnl );
427
const float osc_coeff = m_freq * m_detuning;
429
for( fpp_t frame = 0; frame < _frames ; ++frame )
431
if( m_subOsc->syncOk( sub_osc_coeff ) )
433
m_phase = m_phaseOffset;
435
_ab[frame][_chnl] = getSample<W>( m_phase ) * m_volume;
436
m_phase += osc_coeff;
443
// do fm by using sub-osc as modulator
444
template<oscillator::waveShapes W>
445
void oscillator::updateFM( sampleFrame * _ab, const fpp_t _frames,
446
const ch_cnt_t _chnl )
448
m_subOsc->update( _ab, _frames, _chnl );
450
const float osc_coeff = m_freq * m_detuning;
452
for( fpp_t frame = 0; frame < _frames; ++frame )
454
m_phase += _ab[frame][_chnl];
455
_ab[frame][_chnl] = getSample<W>( m_phase ) * m_volume;
456
m_phase += osc_coeff;
464
inline sample_t oscillator::getSample<oscillator::SIN_WAVE>(
465
const float _sample )
467
return( sinSample( _sample ) );
474
inline sample_t oscillator::getSample<oscillator::TRIANGLE_WAVE>(
475
const float _sample )
477
return( triangleSample( _sample ) );
484
inline sample_t oscillator::getSample<oscillator::SAW_WAVE>(
485
const float _sample )
487
return( sawSample( _sample ) );
494
inline sample_t oscillator::getSample<oscillator::SQUARE_WAVE>(
495
const float _sample )
497
return( squareSample( _sample ) );
504
inline sample_t oscillator::getSample<oscillator::MOOG_SAW_WAVE>(
505
const float _sample )
507
return( moogSawSample( _sample ) );
514
inline sample_t oscillator::getSample<oscillator::EXP_WAVE>(
515
const float _sample )
517
return( expSample( _sample ) );
524
inline sample_t oscillator::getSample<oscillator::WHITE_NOISE_WAVE>(
525
const float _sample )
527
return( noiseSample( _sample ) );
534
inline sample_t oscillator::getSample<oscillator::USER_DEF_WAVE>(
535
const float _sample )
537
return( userWaveSample( _sample ) );