delayline.hh File Reference

#include <string>
#include "sigtype.hh"
#include "klass.hh"
Include dependency graph for delayline.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void vectorLoop (Klass *k, const string &tname, const string &dlname, const string &cexp)
 Generate the code for a (short) delay line.
void dlineLoop (Klass *k, const string &tname, const string &dlname, int delay, const string &cexp)
 Generate the code for a (short) delay line.

Function Documentation

void dlineLoop ( Klass k,
const string &  tname,
const string &  dlname,
int  delay,
const string &  cexp 
)

Generate the code for a (short) delay line.

Parameters:
k the c++ class where the delay line will be placed.
l the loop where the code will be placed.
tname the name of the C++ type (float or int)
dlname the name of the delay line (vector) to be used.
delay the maximum delay
cexp the content of the signal as a C++ expression

Definition at line 51 of file delayline.cpp.

References Klass::addDeclCode(), Klass::addExecCode(), Klass::addFirstPrivateDecl(), Klass::addInitCode(), Klass::addPostCode(), Klass::addPreCode(), Klass::addSharedDecl(), Klass::addZone1(), Klass::addZone2(), gMaxCopyDelay, gSchedulerSwitch, gVecSize, pow2limit(), subst(), and T().

Referenced by VectorCompiler::generateDelayLine().

00052 {
00053     if (delay < gMaxCopyDelay) {
00054 
00055         // Implementation of a copy based delayline
00056 
00057         // create names for temporary and permanent storage  
00058         string  buf = subst("$0_tmp", dlname);          
00059         string  pmem= subst("$0_perm", dlname);
00060         
00061         // constraints delay size to be multiple of 4
00062         delay = (delay+3)&-4;
00063             
00064         // allocate permanent storage for delayed samples
00065         string  dsize   = T(delay);
00066         k->addDeclCode(subst("$0 \t$1[$2];", tname, pmem, dsize));
00067             
00068         // init permanent memory
00069         k->addInitCode(subst("for (int i=0; i<$1; i++) $0[i]=0;", pmem, dsize)); 
00070             
00071         // compute method
00072             
00073         // -- declare a buffer and a "shifted" vector
00074         k->addSharedDecl(buf);
00075       
00076         // -- variables moved as class fields...
00077         if (gSchedulerSwitch) {
00078             k->addDeclCode(subst("$0 \t$1[$2+$3];", tname, buf, T(gVecSize), dsize));
00079         } else {
00080             k->addZone1(subst("$0 \t$1[$2+$3];", tname, buf, T(gVecSize), dsize));
00081         }
00082 
00083         k->addFirstPrivateDecl(dlname);
00084         k->addZone2(subst("$0* \t$1 = &$2[$3];", tname, dlname, buf, dsize));
00085 
00086         // -- copy the stored samples to the delay line
00087         k->addPreCode(subst("for (int i=0; i<$2; i++) $0[i]=$1[i];", buf, pmem, dsize));
00088                     
00089         // -- compute the new samples
00090         k->addExecCode(subst("$0[i] = $1;", dlname, cexp));
00091             
00092         // -- copy back to stored samples
00093         k->addPostCode(subst("for (int i=0; i<$2; i++) $0[i]=$1[count+i];", pmem, buf, dsize));
00094 
00095     } else {
00096 
00097         // Implementation of a ring-buffer delayline
00098 
00099         // the size should be large enough and aligned on a power of two
00100         delay   = pow2limit(delay + gVecSize);
00101         string  dsize   = T(delay);
00102         string  mask    = T(delay-1);
00103 
00104         // create names for temporary and permanent storage  
00105         string  idx = subst("$0_idx", dlname);
00106         string  idx_save = subst("$0_idx_save", dlname);
00107             
00108         // allocate permanent storage for delayed samples
00109         k->addDeclCode(subst("$0 \t$1[$2];", tname, dlname, dsize));
00110         k->addDeclCode(subst("int \t$0;", idx));
00111         k->addDeclCode(subst("int \t$0;", idx_save));
00112             
00113         // init permanent memory
00114         k->addInitCode(subst("for (int i=0; i<$1; i++) $0[i]=0;", dlname, dsize)); 
00115         k->addInitCode(subst("$0 = 0;", idx));
00116         k->addInitCode(subst("$0 = 0;", idx_save));
00117 
00118         // -- update index
00119         k->addPreCode(subst("$0 = ($0+$1)&$2;", idx, idx_save, mask));
00120                     
00121         // -- compute the new samples
00122         k->addExecCode(subst("$0[($2+i)&$3] = $1;", dlname, cexp, idx, mask));
00123 
00124         // -- save index
00125         k->addPostCode(subst("$0 = count;", idx_save));
00126     }
00127 }

Here is the call graph for this function:

Here is the caller graph for this function:

void vectorLoop ( Klass k,
const string &  tname,
const string &  vecname,
const string &  cexp 
)

Generate the code for a (short) delay line.

Parameters:
k the c++ class where the delay line will be placed.
l the loop where the code will be placed.
tname the name of the C++ type (float or int)
dlname the name of the delay line (vector) to be used.
delay the maximum delay
cexp the content of the signal as a C++ expression

Definition at line 25 of file delayline.cpp.

References Klass::addDeclCode(), Klass::addExecCode(), Klass::addSharedDecl(), Klass::addZone1(), gSchedulerSwitch, gVecSize, subst(), and T().

Referenced by VectorCompiler::generateDelayLine(), and VectorCompiler::generateVariableStore().

00026 {  
00027     // -- declare the vector
00028     k->addSharedDecl(vecname);
00029       
00030     // -- variables moved as class fields...
00031     if (gSchedulerSwitch) {
00032         k->addDeclCode(subst("$0 \t$1[$2];", tname, vecname, T(gVecSize)));
00033     } else {
00034         k->addZone1(subst("$0 \t$1[$2];", tname, vecname, T(gVecSize)));
00035     }
00036        
00037     // -- compute the new samples
00038     k->addExecCode(subst("$0[i] = $1;", vecname, cexp));
00039 }

Here is the call graph for this function:

Here is the caller graph for this function:

Generated on Wed Apr 28 23:45:46 2010 for FAUST compiler by  doxygen 1.6.3