Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-------------------------------------------------------------------*
- * Logistic: Implements the Logistic Map at audio rate.
- * Note that we now also need to import the msp.* classes.
- *-------------------------------------------------------------------*/
- import com.cycling74.max.*;
- import com.cycling74.msp.*;
- public class KaplanYorke extends MSPPerformer
- {
- /*-------------------------------------------------------------------*
- * x will store our current x.
- * r is the logistic map's r parameter.
- an+1 = 2an (mod b)
- xn+1 = an/b
- yn+1 ryn + cos(4PIxn)
- *-------------------------------------------------------------------*/
- public double x,y,b,a,r;
- public int[] primeNumbers;
- public KaplanYorke()
- {
- /*-------------------------------------------------------------------*
- * No inlets, one audio-rate outlet.
- *-------------------------------------------------------------------*/
- declareInlets(new int[] {});
- declareOutlets(new int[] { SIGNAL});
- /*-------------------------------------------------------------------*
- * Set our initial r parameter to something interesting.
- *-------------------------------------------------------------------*/
- r = 0.2;
- }
- public void setR(float _r)
- {
- /*-------------------------------------------------------------------*
- * This is called when the Max patch updates our r parameter.
- *-------------------------------------------------------------------*/
- if ( _r > 0 && _r < 4) // protect from going outside limits
- this.r = _r;
- }
- public void dspsetup(MSPSignal[] in , MSPSignal[] out)
- {
- /*-------------------------------------------------------------------*
- * Called when the object's audio processing is switched on.
- *-------------------------------------------------------------------*/
- this.y = 0.667751;
- this.b = 4111;
- this.a = 128873;
- }
- public void reset()
- {
- }
- public void perform(MSPSignal[] ins, MSPSignal[] outs)
- {
- /*-------------------------------------------------------------------*
- * This is where the DSP magic happens.
- * First, get a pointer to our array of output samples...
- *-------------------------------------------------------------------*/
- float[] out = outs[0].vec;
- /*-------------------------------------------------------------------*
- * Now, go through the required number of samples, and set the
- * each sample to our x variable. At the moment, this just
- * sets every sample to our original x.
- *-------------------------------------------------------------------*/
- for (int i = 0; i < out.length; i++)
- {
- /*
- an+1 = 2an (mod b)
- xn+1 = an/b
- yn+1 ryn + cos(4PIxn)
- */
- a = (2*a) % b;
- x = (a/b);
- y = r * y + Math.cos(4 * Math.PI * x);
- out[i] = (float) y;
- }
- }
- }
Add Comment
Please, Sign In to add comment