CSL  6.0
Lorenz.cpp
Go to the documentation of this file.
1 //
2 // Lorenz.cpp -- Implementation file for the Lorenz chaotic oscillator
3 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 //
5 
6 #include "Lorenz.h"
7 #include <iostream>
8 #include <stdio.h>
9 
10 using namespace csl;
11 
12 // Constructors
13 Lorenz::Lorenz(float tx, float ty, float tz) : UnitGenerator(), mX(tx), mY(ty), mZ(tz) { }
14 
16 
17 // Dump = pretty-print something about the receiver object
18 void Lorenz::dump() {
19  logMsg("Lorenz Frame-Rate: %d, x: %g\n", mFrameRate, mX);
20 }
21 
22 // The default next_buffer function just plays one variable of the Lorenz Strange Attractor between +1 and -1
23 void Lorenz::nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException) {
24  sample *bufferPtr = outputBuffer.buffer(outBufNum);
25  unsigned numFrames = outputBuffer.mNumFrames;
26  float xx , yy, zz;
27  static float max;
28 
29 #ifdef CSL_DEBUG
30  logMsg("Lorenz oscillator's nextBuffer");
31 #endif
32 
33  for(unsigned i = 0; i < numFrames; i++ ) {
34  xx = mX + 0.01 * (-10. * mX + 10. * mY );
35  yy = mY + 0.01 * (20. * mX - mY - mX * mZ );
36  zz = mZ + 0.01 * (-8. * mZ / 3. + mX * mY );
37  max = (mX > max) ? mX : max;
38  *bufferPtr++ = mX / 17.f - 0.1f;
39  mX = xx;
40  mY = yy;
41  mZ = zz;
42  }
43 // printf("max:\t%g\t\t",max);
44 }
#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
unsigned mFrameRate
trigger ignored here
Definition: CSL_Core.h:288
float mX
Definition: Lorenz.h:37
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: Lorenz.cpp:23
float sample
(could be changed to int, or double)
Definition: CSL_Types.h:191
void dump()
pretty-print the receiver
Definition: Lorenz.cpp:18
Lorenz(float x=0.02, float y=20., float z=20.)
Constructor.
Definition: Lorenz.cpp:13
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.