Guest User

Untitled

a guest
May 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. /*-------------------------------------------------------------------*
  2. * Logistic: Implements the Logistic Map at audio rate.
  3. * Note that we now also need to import the msp.* classes.
  4. *-------------------------------------------------------------------*/
  5. import com.cycling74.max.*;
  6. import com.cycling74.msp.*;
  7.  
  8. public class KaplanYorke extends MSPPerformer
  9. {
  10. /*-------------------------------------------------------------------*
  11. * x will store our current x.
  12. * r is the logistic map's r parameter.
  13.  
  14. an+1 = 2an (mod b)
  15. xn+1 = an/b
  16. yn+1 ryn + cos(4PIxn)
  17. *-------------------------------------------------------------------*/
  18. public double x,y,b,a,r;
  19.  
  20. public int[] primeNumbers;
  21.  
  22. public KaplanYorke()
  23. {
  24. /*-------------------------------------------------------------------*
  25. * No inlets, one audio-rate outlet.
  26. *-------------------------------------------------------------------*/
  27. declareInlets(new int[] {});
  28. declareOutlets(new int[] { SIGNAL});
  29.  
  30. /*-------------------------------------------------------------------*
  31. * Set our initial r parameter to something interesting.
  32. *-------------------------------------------------------------------*/
  33. r = 0.2;
  34. }
  35.  
  36. public void setR(float _r)
  37. {
  38. /*-------------------------------------------------------------------*
  39. * This is called when the Max patch updates our r parameter.
  40. *-------------------------------------------------------------------*/
  41. if ( _r > 0 && _r < 4) // protect from going outside limits
  42. this.r = _r;
  43. }
  44.  
  45. public void dspsetup(MSPSignal[] in , MSPSignal[] out)
  46. {
  47. /*-------------------------------------------------------------------*
  48. * Called when the object's audio processing is switched on.
  49. *-------------------------------------------------------------------*/
  50. this.y = 0.667751;
  51. this.b = 4111;
  52. this.a = 128873;
  53. }
  54.  
  55. public void reset()
  56. {
  57. }
  58.  
  59. public void perform(MSPSignal[] ins, MSPSignal[] outs)
  60. {
  61. /*-------------------------------------------------------------------*
  62. * This is where the DSP magic happens.
  63. * First, get a pointer to our array of output samples...
  64. *-------------------------------------------------------------------*/
  65. float[] out = outs[0].vec;
  66.  
  67. /*-------------------------------------------------------------------*
  68. * Now, go through the required number of samples, and set the
  69. * each sample to our x variable. At the moment, this just
  70. * sets every sample to our original x.
  71. *-------------------------------------------------------------------*/
  72. for (int i = 0; i < out.length; i++)
  73. {
  74. /*
  75. an+1 = 2an (mod b)
  76. xn+1 = an/b
  77. yn+1 ryn + cos(4PIxn)
  78. */
  79. a = (2*a) % b;
  80. x = (a/b);
  81. y = r * y + Math.cos(4 * Math.PI * x);
  82. out[i] = (float) y;
  83. }
  84. }
  85. }
Add Comment
Please, Sign In to add comment