CSL  6.0
Variable.cpp
Go to the documentation of this file.
1 //
2 // Variable.cpp -- the abstract external variable (plug) class
3 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 //
5 
6 #include "Variable.h"
7 #include <iostream> // To be able to use cout
8 
9 using namespace csl;
10 
11 // Fill the first channel of the buffer with the constant value
12 
13 void StaticVariable:: nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException) {
14  SampleBuffer buffer = outputBuffer.buffer(outBufNum);
15  unsigned numFrames = outputBuffer.mNumFrames;
16 
17  for (unsigned i = 0; i < numFrames; i++)
18  *buffer++ = mValue;
19 }
20 
21 // Dynamic values grab their input and scale it
22 
23 void DynamicVariable:: nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException) {
24  Effect::pullInput(outputBuffer);
25  unsigned numFrames = outputBuffer.mNumFrames;
26  unsigned i;
27  SampleBuffer outp = outputBuffer.buffer(outBufNum);
28  switch(mMode) {
29  case kOpTimes:
30  for (i = 0; i < numFrames; i++) *outp++ *= mValue;
31  break;
32  case kOpDivided:
33  for (i = 0; i < numFrames; i++) *outp++ /= mValue;
34  break;
35  case kOpPlus:
36  for (i = 0; i < numFrames; i++) *outp++ += mValue;
37  break;
38  case kOpMinus:
39  for (i = 0; i < numFrames; i++) *outp++ -= mValue;
40  break;
41  case kOpNegated:
42  for (i = 0; i < numFrames; i++) *outp++ += (1.0f - mValue);
43  break;
44  default:
45  // ?????????????????
46  // just return the voice's values...
47  break;
48  }
49 }
50 
51 // I have to override this here
52 
53 //void DynamicVariable::nextBuffer(Buffer & outputBuffer) throw (CException) {
54 // Effect::pullInput(outputBuffer);
55 // UnitGenerator::nextBuffer(outputBuffer);
56 //}
57 
58 #ifdef USE_RANDOMS
59 
60 //v1 and v2 are arguments passed along to the newran functions...see the newran documentation for more info
61 
62 RandomVariable::RandomVariable(Distribution d, float mean, float variance, float v1, float v2)
63  : UnitGenerator(), mVar(0), mDist(d), mMean(mean), mVariance(variance) {
64  try {
65  //Initial Setup of seeding, etc.
66 #ifdef CSL_WINDOWS
67  Random::SetDirectory("C:\\_libraries\\newran\\"); // set directory for seed control
68 #else
69  Random::SetDirectory("./"); // set directory for seed control
70 #endif
71  Random::Set(urng); // set urng as generator to be used
72 #ifndef MSVS6
73  if (copySeedFromDisk)
74  Random::CopySeedFromDisk(true); // get seed information from disk
75 #endif
76  //Figure out which type of random variable the user wants and make it
77  switch(mDist) {
78  case kUniform:
79  mVar = new Uniform();
80  break;
81  case kExponential:
82  mVar = new Exponential();
83  break;
84  case kCauchy:
85  mVar = new Cauchy();
86  break;
87  case kNormal:
88  mVar = new Normal();
89  break;
90  case kChiSq:
91  mVar = new ChiSq((int)v1,v2);
92  break;
93  case kGamma:
94  mVar = new Gamma(v1);
95  break;
96  case kPareto:
97  mVar = new Pareto(v1);
98  break;
99  case kPoisson:
100  mVar = new Poisson(v1);
101  break;
102  case kBinomial:
103  mVar = new Binomial((int)v1,v2);
104  break;
105  case kNegativeBinomial:
106  mVar = new NegativeBinomial(v1,v2);
107  break;
108  default:
109  mVar = new Uniform();
110  break;
111  }
112  } catch (std::exception& e) { // Used to be Catch(CException) -- ?? STP
113  cerr << "\nRandomVariable exception: " << e.what() << "\n";
114  }
115 }
116 
117 RandomVariable::~RandomVariable() {
118 #ifndef MSVS6
119  try {
120  if (copySeedFromDisk)
121  Random::CopySeedToDisk(); // write out seed
122  } catch (CException & e) {
123  cerr << "\nRandomVariable exception: " << e.mMessage << "\n";
124  }
125 #endif
126 }
127 
128 // Random Variables generate a stream of random values
129 
130 void RandomVariable:: nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException) {
131  unsigned numFrames = outputBuffer.mNumFrames;
132  SampleBuffer outp = outputBuffer.buffer(outBufNum];
133 
134  for (unsigned i = 0; i < numFrames; i++)
135  *outp++ = nextFrame(outputBuffer);
136 }
137 
138 #endif
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
Definition: CSL_Types.h:194
void pullInput(Buffer &outputBuffer)
Definition: CSL_Core.cpp:1122
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
versions of nextBuffer
Definition: Variable.cpp:13
#define kOpTimes
Definition: Variable.h:80
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
my main operations
Definition: Variable.cpp:23
#define kOpMinus
Definition: Variable.h:81
#define kOpDivided
Definition: Variable.h:82
#define kOpNegated
Definition: Variable.h:83
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Definition: CSL_Core.h:106
forward declaration
Definition: CSL_Core.h:241
Base class of CSL exceptions (written upper-case). Has a string message.
#define kOpPlus
Definition: Variable.h:79