When creating a new class, you must define two functions:
action | This function defines what the object is supposed to do in order to generate a new sample. For example in the Add class, the action function would add all of the inputs and store the result. |
output | This function returns the current output which was generated by first calling the action function. You may need to define a storage variable which gets read when the output function is called. It is bad programming style to do any calculation to generate a sample when this function is called -- the output should already have been generated by the action function call. |
Those two functions must be defined in order for the class to compile without error, since the functions were declared as undefined virtual functions in the Signal class.
There are a few additional functions which you don't have to define, but it would be elegant programming style if you did so:
clear | This function can be called to initalize the state of the object to make it ready for use. For example, you may want to set the initial output of your object to be zero when it is first created, or you may want to set any delaylines to zero to avoid unwanted noise glitches when starting a signal stream up. |
printState | This function prints important information about an object and is intended to be used to debug. This function would be very nice to have defined |
When I want to create a new (Filter) class, I usually just copy the Add class and replace the contents of the functions in the new class with different definitions. The Add class is very simple and hardly does anything at all. Here is the header file and the source file which I start with when making a new class.
Here is a technical note: there is a Signal class variable called brandname which can be set to be either FILTER or GENERATOR. This variable is used by the Action class in determining the tickFrozenState array. For examples, the DownSample class pretends to be a generator to the Action class in that case. Avoid using the Action.tickFrozenState if you masquerade a Filter as a Generator when that class is used in feedback -- I don't know what would happen as I havent tried a case like that yet. When masquerading as a Generator, a Filter class prevents the Action.freezeState function from following any upstream connections on the class.