void EFFECT_ALLPASS_FILTER::process(void)
{
  i.begin();
  while(!i.end()) {
    if (inbuf[i.channel()].size() >= D) {
      inbuf[i.channel()].push_back(*i.current());

      //      *i.current() = -feedback_gain * (*i.current()) +
      //	             inbuf[i.channel()].front() +
      //	             feedback_gain * outbuf[i.channel()].front();

      *i.current() = ecaops_flush_to_zero(-feedback_gain * (*i.current()) +
					  (feedback_gain * inbuf[i.channel()].front() +
					   *i.current()) * 
					  (1.0 - feedback_gain * feedback_gain));

      //      feedback_gain * outbuf[i.channel()].front();
      //      outbuf[i.channel()].push_back(*i.current());

      inbuf[i.channel()].pop_front();
      // outbuf[i.channel()].pop_front();
    } 
    else {
      inbuf[i.channel()].push_back(*i.current());
      *i.current() = ecaops_flush_to_zero(*i.current() * (1.0 - feedback_gain));
      // outbuf[i.channel()].push_back(*i.current());
    }
    i.next();
  }
}
void EFFECT_REVERB::process(void)
{
  l.begin(SAMPLE_SPECS::ch_left);
  r.begin(SAMPLE_SPECS::ch_right);
  while(!l.end() && !r.end()) {
    SAMPLE_SPECS::sample_t temp_left = 0.0;
    SAMPLE_SPECS::sample_t temp_right = 0.0;
    if (buffer[SAMPLE_SPECS::ch_left].size() >= dtime) {
      temp_left = buffer[SAMPLE_SPECS::ch_left].front();
      temp_right = buffer[SAMPLE_SPECS::ch_right].front();
      
      if (surround == 0) {
	*l.current() = (*l.current() * (1 - feedback)) + (temp_left *  feedback);
	*r.current() = (*r.current() * (1 - feedback)) + (temp_right * feedback);
      }
      else {
	*l.current() = (*l.current() * (1 - feedback)) + (temp_right *  feedback);
	*r.current() = (*r.current() * (1 - feedback)) + (temp_left * feedback);
      }
      buffer[SAMPLE_SPECS::ch_left].pop_front();
      buffer[SAMPLE_SPECS::ch_right].pop_front();
    }
    else {
	*l.current() = (*l.current() * (1 - feedback));
	*r.current() = (*r.current() * (1 - feedback));
    }
    *l.current() = ecaops_flush_to_zero(*l.current());
    *r.current() = ecaops_flush_to_zero(*r.current());
    buffer[SAMPLE_SPECS::ch_left].push_back(*l.current());
    buffer[SAMPLE_SPECS::ch_right].push_back(*r.current());
    l.next();
    r.next();
  }
}
void EFFECT_PHASER::process(void)
{
  EFFECT_MODULATING_DELAY::process();

  i.begin();
  while(!i.end()) {
    SAMPLE_SPECS::sample_t temp1 = 0.0;
    parameter_t p = vartime * lfo.value(lfo_pos_secs_rep);
    if (filled[i.channel()] == true) {
      DBC_CHECK((dtime + delay_index[i.channel()] + static_cast<long int>(p)) % (dtime * 2) >= 0);
      DBC_CHECK((dtime + delay_index[i.channel()] + static_cast<long int>(p)) % (dtime * 2) < static_cast<long int>(buffer[i.channel()].size()));
      temp1 = buffer[i.channel()][(dtime + delay_index[i.channel()] + static_cast<long int>(p)) % (dtime * 2)];
      //          cerr << "b: "
      //    	   << (delay_index[i.channel()] + static_cast<long int>(p)) % dtime
      //    	   << "," << p << ".\n";
    }
    *i.current() = ecaops_flush_to_zero(*i.current() * (1.0 - feedback) + (-1.0 * temp1 * feedback));
    buffer[i.channel()][delay_index[i.channel()]] = *i.current();

    ++(delay_index[i.channel()]);
    if (delay_index[i.channel()] == 2 * dtime) {
      delay_index[i.channel()] = 0;
      filled[i.channel()] = true;
    }
    i.next();
  }
}
Example #4
0
void ADVANCED_REVERB::process(void)
{
  i_channels.begin();
  while(!i_channels.end()) {
    int ch = i_channels.channel();

    cdata[ch].bufferpos_rep++;
    cdata[ch].bufferpos_rep &= 65535;

    double old_value = cdata[ch].oldvalue;
    cdata[ch].buffer[cdata[ch].bufferpos_rep] = 
      ecaops_flush_to_zero(*i_channels.current() + old_value);

    old_value = 0.0;
    for(int i = 0; i < 64; i++) {
      old_value +=
	static_cast<float>(cdata[ch].buffer[(cdata[ch].bufferpos_rep - cdata[ch].dpos[i]) & 65535] * cdata[ch].mul[i]);
    }

    /**
     * This is just a very simple high-pass-filter to remove offsets
     * which can accour during calculation of the echos
     */
    cdata[ch].lpvalue = 
      ecaops_flush_to_zero(cdata[ch].lpvalue * 0.99 + old_value * 0.01);
    old_value = old_value - cdata[ch].lpvalue;

    /**
     * This is a simple lowpass to make the apearence of the reverb 
     * more realistic... (Walls do not reflect high frequencies very
     * well at all...) 
     */
    cdata[ch].oldvalue = 
      ecaops_flush_to_zero(cdata[ch].oldvalue * 0.75 + old_value * 0.25);

    *i_channels.current() = cdata[ch].oldvalue * wet_rep + *i_channels.current() * (1 - wet_rep);
    i_channels.next();
  }
}
void EFFECT_RESONATOR::process(void)
{
  i.begin();
  while(!i.end()) {
    *i.current() = cona[0] * (*i.current()) -
                   conb[0] * saout0[i.channel()] -
		   conb[1] * saout1[i.channel()];
    
    saout1[i.channel()] = saout0[i.channel()];
    saout0[i.channel()] = ecaops_flush_to_zero(*i.current());
				 
    i.next();
  }
}
void EFFECT_RESONANT_BANDPASS::process(void)
{
  i.begin();
  while(!i.end()) {
    *i.current() = ecaops_flush_to_zero(a * (*i.current()) +
					b * outhist1[i.channel()] -
					c * outhist2[i.channel()]);
  
    outhist2[i.channel()] = outhist1[i.channel()];
    outhist1[i.channel()] = *i.current();

    i.next();
  }
}
void EFFECT_RESONANT_LOWPASS::process(void)
{
  i.begin();
  while(!i.end()) {
    *i.current() = (*i.current()) * gain;

    // first section:
    // --------------
    
    // poles:
    *i.current() =  (*i.current()) - outhist0[i.channel()] * Coef[0].A;
    newhist0[i.channel()] = ecaops_flush_to_zero((*i.current()) - outhist1[i.channel()] * Coef[0].B);
        
    // zeros:
    *i.current() = newhist0[i.channel()] + outhist0[i.channel()] * Coef[0].C;
    *i.current() = (*i.current()) +  outhist1[i.channel()] * Coef[0].D;
    
    outhist1[i.channel()] = outhist0[i.channel()];
    outhist0[i.channel()] = newhist0[i.channel()];
        
    // second section:
    // --------------
    
    // poles:
    *i.current() =  (*i.current()) - outhist2[i.channel()] * Coef[1].A;
    newhist1[i.channel()] = ecaops_flush_to_zero((*i.current()) - outhist3[i.channel()] * Coef[1].B);
       
    // zeros:
    *i.current() = newhist1[i.channel()] + outhist2[i.channel()] * Coef[1].C;
    *i.current() = (*i.current()) +  outhist3[i.channel()] * Coef[1].D;
    
    outhist3[i.channel()] = outhist2[i.channel()];
    outhist2[i.channel()] = newhist1[i.channel()];

    i.next();
  }
}
void EFFECT_LOWPASS_SIMPLE::process(void)
{
  i.begin();
  while(!i.end()) {
    tempin[i.channel()] = *i.current();
    temphist[i.channel()] = outhist[i.channel()];
    outhist[i.channel()] = tempin[i.channel()];
    
    tempin[i.channel()] *= A * 0.5;
    temphist[i.channel()] *= B * 0.5;

    *i.current() = ecaops_flush_to_zero(tempin[i.channel()] + temphist[i.channel()]);

    i.next();
  }
}
void EFFECT_BW_FILTER::process(void)
{
  i.begin();
  while(!i.end()) {
    outputSample = ecaops_flush_to_zero(a[0] * (*i.current()) + 
					a[1] * sin[i.channel()][0] + 
					a[2] * sin[i.channel()][1] - 
					b[0] * sout[i.channel()][0] - 
					b[1] * sout[i.channel()][1]);
    sin[i.channel()][1] = sin[i.channel()][0];
    sin[i.channel()][0] = *i.current();

    sout[i.channel()][1] = sout[i.channel()][0];
    sout[i.channel()][0] = outputSample;

    *i.current() = outputSample;
    i.next();
  }
}