CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
15 Lorenz::~Lorenz() { }
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 }