Example 1

The following SDF primitive Ramp has no inputs, just an output port. The source primitive generates a linear increasing or decreasing sequence of float particles on its output. The parameter value is initialized to define the value of the first output. Each time the primitive’s go method fires, the value parameter is updated to store the next output value. Hence, the attributes of the value parameter are set, so that the state can be overwritten by the primitive’s methods. By default, the primitive will generate the output sequence 0.0, 1.0, 2.0, etc.

  1. defprimitive
  2. {
  3.   name        { Ramp }
  4.   domain      { SDF }
  5.   desc
  6.   {
  7.     Generate a ramp signal, starting at "value"(default0) and incrementing by step size "step"(default1) on each firing.
  8.   }
  9.  
  10.   output
  11.   {
  12.     name { output }
  13.     type {float}
  14.   }
  15.  
  16.   defparameter
  17.   {
  18.     name        { step }
  19.     type        {float}
  20.     default     {"1.0"}
  21.     desc        {"Increment from one sample to the next."}
  22.   }
  23.  
  24.   defparameter
  25.   {
  26.     name        { value }
  27.     type        {float}
  28.     default     {"0.0"}
  29.     desc        {"Initial (or latest) value output by Ramp."}
  30.     attrib      { A_NONCONSTANT|A_SETTABLE }
  31.   }
  32.  
  33.   location { SDF main library }
  34.  
  35.   go
  36.   {
  37.     double t = value;
  38.     output%0 << t;
  39.     t += step;
  40.     value = t;
  41.   }
  42. }
  43.