Im rewriting my audio program so it can dynamically create a sample processing pipeline . What i mean by this is that im trying to create a virtual sample pipeline, with one input, and one output. In this pipeline i can add dithering, vst's or resampling or whatever, and i can add them in any order possible, or even multiple times (ass long as subsequent input/ouput are compatible).
Currently this pipeline was pretty much static, so i want to make it more dynamic.To explain this a little here is some code of the most important function : SmplProcAddSmpls. This function is called whenever there are some samples which have to be inserted into the "pipeline":
usage of SmplProcAddSmpls:
Code:
ConvertWaveFile()
{
...
for(i=0;i<itCnt && !stopConversion;i++)
{
fread(buf1,bps,nChannels*MAXSMPLSPERITERATION,inFile);
SmplProcAddSmpls(fileProperties, buf1, MAXSMPLSPERITERATION);
}
...
}
This is how it was (a little simplified ofcourse):
Code:
SmplProcAddSmpls()
{
if(toFloatingPoint)
{
ConvertRawSmplsToFloats();
}
if(addDithering)
{
DoDither();
}
if(someVstsEnabled)
{
DoVstEffects();
}
if(findPeak)
{
FindPeakOfSmpls();
}
if(SaveSamples())
{
StoreSamplesToDisk();
}
}
The problem with this is that it is static. If i wanted to i.e. reverse the order of "DoDither" and "FindPeakOfSmpls", this is impossible. So i have rewritten it like this:
Code:
SmplProcAddSmpls2()
{
for(i=0; i<effectCnt; i++)
{
DoEffect[i]((struct parameters*) p);
}
}
DoEffect[0] can be for example the function ConvertRawSmplsToFloats and DoEffect[1] DoDither etc.
So i created a array of functions, and whenever i want to insert some samples these will go through the functions DoEffect[0] -> DoEffect[effectCnt].
I will change this to recursive functions so that DoEffect[0] will call DoEffect[1], DoEffect[1] will call DoEffect[2] etc etc. But i was thinking about a more elegant way to create a "dynamic sample pipeline". Although i know the syntax of c++, i havent used it very much, and i was thinking there might be a elegeant way to solve this problem in c++ using OO stuff. So my question is: How can i create a dynamic sample pipeline in an elegant way? Or are pointers to functions "the way to go"?