# Vibrato and EQ Algorithms

I’m writing audio code in C/C++ using SDL. I’m looking for simple algorithms for vibrato and a very basic EQ with treble/bass/mid. The functions will be applied to 16-bit audio buffers. Thanks in advance for any help.

-paul

update, I found a document that tells how to do a parametric EQ:
http://epubl.luth.se/1402-1773/2003/044/LTU-CUPP-03044-SE.pdf

And I think I’ve figured out how to do vibrato – just resample, distributing the samples earlier/later using a sine wave to control the time displacement. I’ll post the code if I can get it working.

-paul

That should work - you could (optionally) also modulate the amplitude at the same sine wave frequency for a variation of the effect (or on its own for a tremolo effect).

Audacity does not natively support VST, so you might like to consider porting it as a LADSPA effect (which Audacity does support natively). http://www.ladspa.org/

Vibrato works. Here’s the code, a little rough but you get the idea. Could probably do it with a sine lookup table, all integer math, and no between sample consideration if you’re willing to sacrifice a little sound quality for speed.

``````	// vibrato
for( i=0; i<(length/2); i++ )  // note: length/2 because my length is in bytes but sample is 16 bit
{
rawDataShiftPos = i + sin(i/44100.0)*100.0; // 44100.0=vibrato rate  100.0=depth
dataShiftPos = (long)rawDataShiftPos;
dataShiftPercent = rawDataShiftPos - dataShiftPos;
if( (dataShiftPos>=0) && (dataShiftPos<(length/2)) )
{
// accounts for offsets that fall between sample points -- distribute them between the two points
tempBuffer[dataShiftPos]+=(int16_t)((float)inputWave[i]*(1.0-dataShiftPercent));
tempBuffer[dataShiftPos+1]+=(int16_t)((float)inputWave[i]*dataShiftPercent);
}
}

memcpy( inputWave, tempBuffer, length );
``````

Congratulations.

Would using floating point for the modulation wave definitely make it slower? If so, how much slower?

Sounds like a good idea - then the wave would only need calculating once.

Floating point ops are generally slower. Probably wouldn’t make much difference on recent home computers unless you’re running on a massive amount of tracks. Would make a difference if it were run on an embedded device or something. Some embedded CPUs don’t even have a FPU (like my MP3 player) so in that case it makes a gigantic difference.

I will probably end up running this on many tracks at once, so I can see what the performance is and see about optimizing it. I may have to.

I don’t know anything about C/C++, but I just mentioned it because I know that in certain situations floating point calculations can actually be faster than integer calculations, since modern processors are able to do the floating point calculations in the fpu, while the regular processor is doing something else (working in parallel).

So now that you have the code, how do you use it?

I’ll experiment with the FP stuff and see how the performance works out.

I’m using it for the software at the link below that I’m developing. An effect I use often in my music is to have a very slow, very subtle vibrato on most tracks, which is what I’ll be using it for.

http://www.qotile.net/blog/wp/?p=530

-paul

That looks really cool.
Have you thought of making so that it supports LADSPA plug-ins? There’s a lot of good effects (and instruments) available, and they are not subject to the type of restrictive license that VST has. Although they are mostly used in Linux, they can be compiled to run in Windows. Also, they can be written in C+.

You may also be interested in the Computer Music Toolkit: http://www.ladspa.org/cmt/