The Source Of The Effect Edit

Flanging is one of the earliest known audio effects. occurs when an audio signal is mixed with a very slightly delayed version of itself. Originally this was achieved (and discovered) by playing a track on two tape decks at the same time, and then slowing down one of the tape decks with your finger. As the delay increased, the swooshing sound is produced. The second tape is then slowed to reduce the delay until the tape is in unison again.

Digital Implementation Edit

I use up to 70 44kHz samples for a maximum delay of 1.6ms. The amount of delay is modulated by an external LFO (low frequency oscillator) module.

A flanger is a comb filter where the notches/peaks are modulated in time. This can be produced in a feedforward or feedback configuration

Feedforward Edit

Most closely resembles analog flanging.

Feedforward comb filter

Flanger diagram

Feedback Edit

Produces a much more pronounced synthy or spacey effect.

Feedback comb filter

Algorithm Edit

I implemented this in Propeller Assembly. Algorithm demonstrated here in Python psuedocode. Obviously watch out for implementation details like off-by-one, integer overflow e.t.c.

while true:
  audio_in = get_next_sample()
  lfo      = get_lfo_value()                 # 1 < lfo < delay_buf_size
  depth    = get_depth_control_knob_value()  # 0 <= depth <= 1
  mode     = get_mode()
  delay = delay_buf_current - lfo
  if delay < 0:
    delay = delay + delay_buf_size
  # linearly interpolate delay
  s1 = delay_buf[int_part(delay)]
  s2 = delay_buf[int_part(delay)+1]
  delay_sample = s1 + frac_part(delay)*(s2 - s1)
  if mode == FEEDFORWARD:
    audio_out = audio_in + depth_gain * delay_sample  
    delay_buf[delay_buf_current] = audio_in
  elif mode == FEEDBACK:
    audio_out = audio_in - depth_gain * delay_sample
    delay_buf[delay_buf_current] = audio_out
  # write output
  delay_buf_current = (delay_buf_current + 1) % delay_buf_size