Detect LFO object

Rolfdegen

Well-known member
Hallo..

I use two LFO in my synth project. I want booth LFO with oneshoot function. How can I identify the LFOs in my audio object code?

My solution is a bit cumbersome. I use two waveforms (LFO1 = WAVEFORM_SINE and LFO2 = WAVEFORM_SINE2) with oneshoot function.

Is there a better solution ?


Code:
void AudioSynthWaveform::update(void)
{
  audio_block_t *block;
  int16_t *bp, *end;
  int32_t val1, val2;
  int16_t magnitude15;
  uint32_t i, ph, index, index2, scale;
  const uint32_t inc = phase_increment;


  if(syncFlag==1){
    phase_accumulator = 0;
    syncFlag = 0;
  }  
  
  ph = phase_accumulator + phase_offset;
  
  if (magnitude == 0) {
    phase_accumulator += inc * AUDIO_BLOCK_SAMPLES;
    return;
  }
  block = allocate();
  if (!block) {
    phase_accumulator += inc * AUDIO_BLOCK_SAMPLES;
    return;
  }
  bp = block->data;


  switch(tone_type) {
  case WAVEFORM_SINE:
    for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
      index = ph >> 24;
      val1 = AudioWaveformSine[index];
      val2 = AudioWaveformSine[index+1];
      scale = (ph >> 8) & 0xFFFF;
      val2 *= scale;
      val1 *= 0x10000 - scale;
      *bp++ = multiply_32x32_rshift32(val1 + val2, magnitude);
      uint32_t ph_old = ph;
      ph += inc;
      if (lfo1oneShoot == true && ph < inc) {
          ph = ph_old;
      }
    }
    break;
    
    case WAVEFORM_SINE2:
    for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
        index = ph >> 24;
        val1 = AudioWaveformSine[index];
        val2 = AudioWaveformSine[index+1];
        scale = (ph >> 8) & 0xFFFF;
        val2 *= scale;
        val1 *= 0x10000 - scale;
        *bp++ = multiply_32x32_rshift32(val1 + val2, magnitude);
        uint32_t ph_old = ph;
        ph += inc;
        if (lfo2oneShoot == true && ph < inc) {
            ph = ph_old;
        }
    }
    break;
 
Back
Top