Vibrato and EQ Algorithms

General discussion about writing or understanding source code in audio software that does not fit in the other specific Programming and Development boards.

If you require help using Audacity, or think you have found a "bug", please post on the forum board relevant to your operating system.
Windows
Mac OS X
GNU/Linux and Unix-like

Vibrato and EQ Algorithms

Permanent link to this post Posted by PaulSlocum » Thu Jul 17, 2008 2:28 am

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
PaulSlocum
 
Posts: 7
Joined: Thu Jul 17, 2008 2:23 am

Re: Vibrato and EQ Algorithms

Permanent link to this post Posted by PaulSlocum » Mon Jul 21, 2008 4:05 am

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
PaulSlocum
 
Posts: 7
Joined: Thu Jul 17, 2008 2:23 am

Re: Vibrato and EQ Algorithms

Permanent link to this post Posted by steve » Mon Jul 21, 2008 5:29 pm

PaulSlocum wrote: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.

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/
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 33980
Joined: Sat Dec 01, 2007 11:43 am

Re: Vibrato and EQ Algorithms

Permanent link to this post Posted by PaulSlocum » Tue Jul 22, 2008 1:23 am

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.

Code: Select all
   // 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 );
PaulSlocum
 
Posts: 7
Joined: Thu Jul 17, 2008 2:23 am

Re: Vibrato and EQ Algorithms

Permanent link to this post Posted by steve » Tue Jul 22, 2008 2:03 am

PaulSlocum wrote:Vibrato works

Congratulations.

PaulSlocum wrote:all integer math, and no between sample consideration if you're willing to sacrifice a little sound quality for speed.

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

PaulSlocum wrote:Could probably do it with a sine lookup table

Sounds like a good idea - then the wave would only need calculating once.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 33980
Joined: Sat Dec 01, 2007 11:43 am

Re: Vibrato and EQ Algorithms

Permanent link to this post Posted by PaulSlocum » Tue Jul 22, 2008 2:19 am

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.
PaulSlocum
 
Posts: 7
Joined: Thu Jul 17, 2008 2:23 am

Re: Vibrato and EQ Algorithms

Permanent link to this post Posted by steve » Tue Jul 22, 2008 2:43 am

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?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 33980
Joined: Sat Dec 01, 2007 11:43 am

Re: Vibrato and EQ Algorithms

Permanent link to this post Posted by PaulSlocum » Tue Jul 22, 2008 5:43 am

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
PaulSlocum
 
Posts: 7
Joined: Thu Jul 17, 2008 2:23 am

Re: Vibrato and EQ Algorithms

Permanent link to this post Posted by steve » Tue Jul 22, 2008 6:27 am

PaulSlocum wrote: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.

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/

Good luck with your project.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 33980
Joined: Sat Dec 01, 2007 11:43 am


Return to General Audio Programming



Who is online

Users browsing this forum: No registered users and 6 guests