236
235
if( _n->released() == FALSE )
238
release_begin += eng()->getMixer()->framesPerAudioBuffer();
237
release_begin += engine::getMixer()->framesPerPeriod();
241
return( m_envLFOWidgets[VOLUME]->level( _frame, release_begin, 0 ) );
241
m_envLFOWidgets[VOLUME]->fillLevel( &volume_level, _frame,
244
return( volume_level );
247
250
void envelopeTabWidget::processAudioBuffer( sampleFrame * _ab,
248
const fpab_t _frames,
249
252
notePlayHandle * _n )
251
f_cnt_t total_frames = _n->totalFramesPlayed();
254
const f_cnt_t total_frames = _n->totalFramesPlayed();
252
255
f_cnt_t release_begin = total_frames - _n->releaseFramesDone() +
253
256
_n->framesBeforeRelease();
255
258
if( _n->released() == FALSE )
257
release_begin += eng()->getMixer()->framesPerAudioBuffer();
260
release_begin += engine::getMixer()->framesPerPeriod();
260
263
// because of optimizations, there's special code for several cases:
261
// - volume-, cut- and res-lfo/envelope active
262
// - volume- and cut-lfo/envelope active
263
// - volume- and res-lfo/envelope active
264
// - cut- and res-lfo/envelope active
264
265
// - cut-lfo/envelope active
265
266
// - res-lfo/envelope active
266
// - volume-lfo/envelope active
267
267
// - no lfo/envelope active but filter is used
268
// now there's a lot of similar code but I didn't found a way to
269
// generalize it yet... may be later we could do that
270
// by using preprocessor and macro-expansion... (like in oscillator.cpp)
272
269
// only use filter, if it is really needed
274
if( _n->m_filter == NULL )
276
_n->m_filter = new basicFilters<>(
277
eng()->getMixer()->sampleRate() );
280
271
if( m_filterGroupBox->isActive() )
282
273
int old_filter_cut = 0;
283
274
int old_filter_res = 0;
285
basicFilters<>::filterTypes filter =
286
basicFilters<>::getFilterType(
287
m_filterComboBox->value() );
289
if( m_envLFOWidgets[VOLUME]->used() &&
290
m_envLFOWidgets[CUT]->used() &&
276
if( _n->m_filter == NULL )
278
_n->m_filter = new basicFilters<>(
279
engine::getMixer()->sampleRate() );
281
_n->m_filter->setFilterType( m_filterComboBox->value() );
283
float * cut_buf = NULL;
284
float * res_buf = NULL;
286
if( m_envLFOWidgets[CUT]->used() )
288
cut_buf = new float[_frames];
289
m_envLFOWidgets[CUT]->fillLevel( cut_buf, total_frames,
290
release_begin, _frames );
292
if( m_envLFOWidgets[RES]->used() )
294
res_buf = new float[_frames];
295
m_envLFOWidgets[RES]->fillLevel( res_buf, total_frames,
296
release_begin, _frames );
299
if( m_envLFOWidgets[CUT]->used() &&
291
300
m_envLFOWidgets[RES]->used() )
293
for( fpab_t frame = 0; frame < _frames;
294
++frame, ++total_frames )
302
for( fpp_t frame = 0; frame < _frames; ++frame )
296
float new_cut_val = m_envLFOWidgets[CUT]->level( total_frames, release_begin, frame );
297
new_cut_val = envelopeAndLFOWidget::expKnobVal( new_cut_val ) * CUT_FREQ_MULTIPLIER +
304
float new_cut_val = envelopeAndLFOWidget::expKnobVal( cut_buf[frame] ) * CUT_FREQ_MULTIPLIER +
298
305
m_filterCutKnob->value();
300
307
float new_res_val = m_filterResKnob->value() + RES_MULTIPLIER *
301
m_envLFOWidgets[RES]->level( total_frames, release_begin, frame );
303
310
if( static_cast<int>( new_cut_val ) != old_filter_cut ||
304
311
static_cast<int>( new_res_val*RES_PRECISION ) != old_filter_res )
306
_n->m_filter->calcFilterCoeffs( filter, new_cut_val, new_res_val );
307
old_filter_cut = static_cast<int>( new_cut_val );
308
old_filter_res = static_cast<int>( new_res_val*RES_PRECISION );
311
float vol_level = m_envLFOWidgets[VOLUME]->level( total_frames, release_begin, frame );
312
vol_level = vol_level*vol_level;
314
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
316
_ab[frame][chnl] = vol_level * _n->m_filter->update( _ab[frame][chnl], chnl );
320
else if( m_envLFOWidgets[VOLUME]->used() && m_envLFOWidgets[CUT]->used() )
322
for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
324
float new_cut_val = m_envLFOWidgets[CUT]->level( total_frames, release_begin, frame );
325
new_cut_val = envelopeAndLFOWidget::expKnobVal( new_cut_val ) * CUT_FREQ_MULTIPLIER +
326
m_filterCutKnob->value();
328
if( static_cast<int>( new_cut_val ) != old_filter_cut )
330
_n->m_filter->calcFilterCoeffs( filter, new_cut_val, m_filterResKnob->value() );
331
old_filter_cut = static_cast<int>( new_cut_val );
334
float vol_level = m_envLFOWidgets[VOLUME]->level( total_frames, release_begin, frame );
335
vol_level = vol_level*vol_level;
337
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
339
_ab[frame][chnl] = vol_level * _n->m_filter->update( _ab[frame][chnl], chnl );
343
else if( m_envLFOWidgets[VOLUME]->used() && m_envLFOWidgets[RES]->used() )
346
for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
348
float new_res_val = m_filterResKnob->value() + RES_MULTIPLIER *
349
m_envLFOWidgets[RES]->level( total_frames, release_begin, frame );
351
if( static_cast<int>( new_res_val*RES_PRECISION ) != old_filter_res )
353
_n->m_filter->calcFilterCoeffs( filter, m_filterCutKnob->value(), new_res_val );
354
old_filter_res = static_cast<int>( new_res_val*RES_PRECISION );
357
float vol_level = m_envLFOWidgets[VOLUME]->level( total_frames, release_begin, frame );
358
vol_level = vol_level*vol_level;
360
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
362
_ab[frame][chnl] = vol_level * _n->m_filter->update( _ab[frame][chnl], chnl );
313
_n->m_filter->calcFilterCoeffs( new_cut_val, new_res_val );
314
old_filter_cut = static_cast<int>( new_cut_val );
315
old_filter_res = static_cast<int>( new_res_val*RES_PRECISION );
318
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
320
_ab[frame][chnl] = _n->m_filter->update( _ab[frame][chnl], chnl );
367
324
else if( m_envLFOWidgets[CUT]->used() )
369
for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
326
for( fpp_t frame = 0; frame < _frames; ++frame )
371
float new_cut_val = m_envLFOWidgets[CUT]->level( total_frames, release_begin, frame );
372
new_cut_val = envelopeAndLFOWidget::expKnobVal( new_cut_val ) * CUT_FREQ_MULTIPLIER +
328
float new_cut_val = envelopeAndLFOWidget::expKnobVal( cut_buf[frame] ) * CUT_FREQ_MULTIPLIER +
373
329
m_filterCutKnob->value();
375
331
if( static_cast<int>( new_cut_val ) != old_filter_cut )
377
_n->m_filter->calcFilterCoeffs( filter, new_cut_val, m_filterResKnob->value() );
333
_n->m_filter->calcFilterCoeffs( new_cut_val, m_filterResKnob->value() );
378
334
old_filter_cut = static_cast<int>( new_cut_val );
434
else if( m_envLFOWidgets[VOLUME]->used() /*&& m_envLFOWidgets[PANNING]->used() == FALSE*/ )
379
if( m_envLFOWidgets[VOLUME]->used() )
436
// only use volume-envelope...
437
for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
381
float * vol_buf = new float[_frames];
382
m_envLFOWidgets[VOLUME]->fillLevel( vol_buf, total_frames,
383
release_begin, _frames );
385
for( fpp_t frame = 0; frame < _frames; ++frame )
439
float vol_level = m_envLFOWidgets[VOLUME]->level( total_frames, release_begin, frame );
440
vol_level = vol_level*vol_level;
441
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
387
float vol_level = vol_buf[frame];
388
vol_level = vol_level * vol_level;
389
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS;
443
392
_ab[frame][chnl] = vol_level * _ab[frame][chnl];
447
398
/* else if( m_envLFOWidgets[VOLUME]->used() == FALSE && m_envLFOWidgets[PANNING]->used() )
449
400
// only use panning-envelope...
450
for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
401
for( fpp_t frame = 0; frame < _frames; ++frame )
452
float vol_level = m_envLFOWidgets[PANNING]->level( total_frames, release_begin, frame );
403
float vol_level = pan_buf[frame];
453
404
vol_level = vol_level*vol_level;
454
405
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )