11#include " SC_PlugIn.h"
22
3+ // InterfaceTable contains pointers to functions in the host (server).
34static InterfaceTable *ft;
45
6+ // declare struct to hold unit generator state
57struct BoringMixer : public Unit {
8+ // this is blank because this particular ugen is stateless.
9+ // in more advanced examples we'll have stuff here.
610};
711
8- static void BoringMixer_next (BoringMixer *unit, int inNumSamples);
12+ // in some older plugins these function declarations are wrapped in 'extern "C" { ... }'
13+ // no need to do that these days.
14+ static void BoringMixer_next (BoringMixer* unit, int inNumSamples);
915static void BoringMixer_Ctor (BoringMixer* unit);
1016
17+ // the constructor function is called when a Synth containing this ugen is played.
18+ // it MUST be named PluginName_Ctor.
19+ // in later examples, this function will initialize state variables.
1120void BoringMixer_Ctor (BoringMixer* unit) {
21+ // set a calculation function.
22+ // in later examples, we will have multiple calculation functions depending on input and output rates.
1223 SETCALC (BoringMixer_next);
24+ // calculate one sample of output.
25+ // this allows plugging into other ugens with initial-rate inputs
1326 BoringMixer_next (unit, 1 );
1427}
1528
29+ // the calculation function can have any name, but this is conventional.
30+ // this function is called every control period (64 samples is typical)
1631void BoringMixer_next (BoringMixer* unit, int inNumSamples) {
1732
18- float *left = IN (0 );
19- float *right = IN (1 );
20- float *out = OUT (0 );
33+ // IN and OUT are helper macros that return audio-rate input and output buffers.
34+ // in SC source code, these buffers are often called "wire bufs" since they are how ugens communicate.
35+ float *left = IN (0 ); // first input
36+ float *right = IN (1 ); // second input
37+ float *out = OUT (0 ); // first output
2138
39+ // loop through samples
2240 for (int i = 0 ; i < inNumSamples; i++) {
2341 out[i] = (left[i] + right[i]) * 0.5 ;
2442 }
2543}
2644
45+ // the entry point is called by the host when the plug-in is loaded
2746PluginLoad (BoringMixerUGens) {
28- ft = inTable;
47+ // InterfaceTable *inTable implicitly given as argument to the load function
48+ ft = inTable; // store pointer to InterfaceTable
49+ // DefineSimpleUnit is one of four macros defining different kinds of ugens.
50+ // In later examples involving memory allocation, we'll see DefineDtorUnit.
2951 DefineSimpleUnit (BoringMixer);
30- }
52+ }
0 commit comments