CSL  5.2
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), mMin(min), mMax(max), mFlags(flags) { }
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 }