CSL  6.0
Clipper.cpp
Go to the documentation of this file.
1 //
2 // Clipper.cpp -- implementation of the Clipper class
3 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 //
5 
6 #include "Clipper.h"
7 #include <math.h>
8 
9 using namespace csl;
10 
11 // Generic Clipper implementation
12 
13 // Constructor takes the input UGen and optionally the flags, min and max.
14 Clipper::Clipper(UnitGenerator & input, float min, float max, ClipperFlags flags)
15  : Effect(input), mFlags(flags), mMin(min), mMax(max) { }
16 
18 
19 void Clipper::dump() {
20  logMsg("a Clipper");
22 }
23 
24 // nextBuffer does the dirty work
25 void Clipper::nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException) {
26 
27  float tempSample;
28  sample * outp = outputBuffer.buffer(outBufNum);
29  unsigned numFrames = outputBuffer.mNumFrames;
30 
31  pullInput(outputBuffer);
32  sample * inPtr = mInputPtr;
33 
34 #ifdef CSL_DEBUG
35  logMsg("Clipper nextBuffer");
36 #endif
37 
38  switch(mFlags) {
39  case kMin:
40  for (unsigned i = 0; i < numFrames; i++) {
41  tempSample = inPtr[i];
42  if (inPtr[i] < mMin )
43  tempSample = mMin;
44 
45  *outp++ = tempSample;
46  }
47  break;
48  case kMax:
49  for (unsigned i = 0; i < numFrames; i++) {
50  tempSample = inPtr[i];
51  if (inPtr[i] > mMax )
52  tempSample = mMax;
53 
54  *outp++ = tempSample;
55  }
56  break;
57  case kBoth:
58  for (unsigned i = 0; i < numFrames; i++) {
59  tempSample = inPtr[i];
60  if (inPtr[i] < mMin )
61  tempSample = mMin;
62  if (inPtr[i] > mMax )
63  tempSample = mMax;
64 
65  *outp++ = tempSample;
66  }
67  break;
68  }
69 
70  return;
71 
72 }
#define max(a, b)
Definition: matrix.h:156
void logMsg(const char *format,...)
These are the public logging messages.
Definition: CGestalt.cpp:292
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
Effect – mix-in for classes that have unit generators as inputs (like filters).
Definition: CSL_Core.h:466
#define min(a, b)
Definition: matrix.h:157
virtual void dump()
pretty-print the receiver
Definition: CSL_Core.cpp:693
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
Definition: Clipper.cpp:25
float sample
(could be changed to int, or double)
Definition: CSL_Types.h:191
Clipper(UnitGenerator &input, float min=-1, float max=1, ClipperFlags flags=kBoth)
Constructor takes the input UGen and optionally the flags, min and max.
Definition: Clipper.cpp:14
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Definition: CSL_Core.h:106
ClipperFlags
Whether to clip using the minimum, maximum or both values.
Definition: Clipper.h:15
forward declaration
Definition: CSL_Core.h:241
void dump()
print the receiver for debugging
Definition: Clipper.cpp:19
Base class of CSL exceptions (written upper-case). Has a string message.