Sign in

Not a member? | Forgot your Password?

Search code

Search tips

Free PDF Downloads

A Quadrature Signals Tutorial: Complex, But Not Complicated

Understanding the 'Phasing Method' of Single Sideband Demodulation

Complex Digital Signal Processing in Telecommunications

Introduction to Sound Processing

C++ Tutorial

Introduction of C Programming for DSP Applications

Fixed-Point Arithmetic: An Introduction

Cascaded Integrator-Comb (CIC) Filter Introduction

FFT Spectral Analysis Software

See Also

Embedded SystemsFPGA

DSP Code Sharing > Flanger Audio Effect

Flanger Audio Effect

Language: C

Processor: Not Relevant

Submitted by Gabriel Rivas on Apr 22 2011

Licensed under a Creative Commons Attribution 3.0 Unported License

Flanger Audio Effect


This is an implementation of the flanger effect using my previous entry

that is a fractional delay line, as a building block. Basically the flanger effect is

achieved by making the delay vary in time acording to a low frequency control signal.


#include "Delay.h"
#include "Flanger.h"

static short samp_freq;
static double var_delay;
static short counter;
static short counter_limit;
static short control;
static short max_delay;
static short min_delay;
static double mix_vol;
static double delay_step;

This is the initialization function, basically
it passes the initialization parameters to the delay block
and initializes the flanger control variables.

void Flanger_init(short effect_rate,short sampling,short maxd,short mind,double fwv,double stepd,double fbv) {
        samp_freq = sampling;
        counter = effect_rate;
        control = 1;
        var_delay = mind;

        //User Parameters
        counter_limit = effect_rate;
        max_delay =  maxd;
        min_delay = mind;
        mix_vol = 1;
        delay_step = stepd;

/*This is the flanging process task
that uses the delay task inside*/

double Flanger_process(double xin) {
        double yout;

        yout = Delay_task(xin);        
        return yout;

This sweep function creates a slow frequency
ramp that will go up and down changing the
delay value at the same time. The counter
variable is a counter of amount of samples that
the function waits before it can change the delay.

void Flanger_sweep(void) {
        if (!--counter) {                      
            if (var_delay > max_delay) {
                control = -1;

            if (var_delay < min_delay) {
                control = 1;

            counter = counter_limit;

#ifndef __FLANGER_H__
#define __FLANGER_H__

extern void Flanger_init(short effect_rate,short sampling,short maxd,short mind,double fwv,double stepd,double fbv);
extern double Flanger_process(double xin);
extern void Flanger_sweep(void);


/*****USAGE EXAMPLE****************************************/
#include "Flanger.h"

void main(void) {
    double xin;
    double yout;

    while(1) {
        if (new_sample_flag()) {
            /*When there's new sample at your ADC or CODEC input*/
            /*Read the sample*/
            xin = read_sample();
            /*Apply the Flanger_process function to the sample*/
            yout = Flanger_process(0.7*xin);

            /*Send the output value to your DAC or codec output*/
            /*Makes the delay vary*/
Rate this code snippet:
Rating: 0 | Votes: 0
posted by Gabriel Rivas
Gabriel Rivas received a BSc in Electrical Engineering at the Technological University of Panama, republic of Panama in 2006. He has worked as embedded software engineer for about 5 years. As a hobby musician he enjoys doing DSP for audio processing.


No comments yet for this code

Add a Comment
You need to login before you can post a comment (best way to prevent spam). ( Not a member? )