A class template is included with the code for the SndObj library (on the ./src/templates directory). The template code is divided into two files: class_template.h and class_template.cpp. The first contains the class declaration and the second, its implementation.
General compilation instructions & tips are also included in this documentation.
The class template, MyClass provides the essential elements for a SndObj-derived class:
class MyClass: public SndObj {
protected:
// Place your variable declarations here
// as well as any internal-operation methods
public:
// constructors / destructor
MyClass();
MyClass(SndObj* input,
/* place any other construction parameters here */
int vecsize=DEF_VECSIZE, float sr=DEF_SR);
~MyClass();
// add any other public methods, if necessary....
// you need to re-define at least these
short DoProcess();
char* ErrorMessage();
};
In order to declare a SndObj-derived class, the user will add any necessary protected member variables to this template, include any contructions parameters needed to initialise these variables. Users should also define any other public methods which might be needed to access or update/initialise class members (typically 'Get...()' and/or 'Set...()'-type functions). The comments in the template code show where these additions should be placed.
Of course, users should not forget to change all instances of the string 'MyClass' (including the #ifdef and #define ones) to the chosen class name.
On implementing the derived classes three steps are normally involved:
short MyClass::DoProcess(){
if(!m_error){
if(m_input){
The processing itself is wrapped up on a loop which will fill the output buffer. The m_enable variable is checked insided the loop, to see whether processing should be bypassed or not.
for(m_vecpos = 0; m_vecpos < m_vecsize; m_vecpos++) {
if(m_enable) {
(...)
} else m_output[m_vecpos] = 0.f;
In order to obtain the signal input, the Output() method should be invoked on the input object:
m_input->Output(m_vecpos);
The ultimate objective of this method is to fill the output buffer with the resulting processed samples, as in:
m_output[m_vecpos] = ...
ErrorMessage() will return a string related to an error code defined by the user (normally > 10 for derived classes). This is implemented under a simple switch() statement.SndObj Library version 2.0
© Victor Lazzarini, 2001
Music Technology Laboratory
NUI Maynooth