Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : help with minim & P3D

$
0
0

since nobody answers, let me make a comment

I don't have serial and so on, but afaik you can just call perspective(); to use the standard
perspective.
Both perspectives seem to work parallel within draw()

And I gave the line of the waveform a z-value.

In my example you see both waveform and cube.

Hope this helps.

Greetings, Chrisir   



  1. //
  2. //import fullscreen.*;
  3. //import processing.serial.*;
  4. import ddf.minim.*;
  5. import ddf.minim.effects.*;
  6. Minim minim;
  7. AudioPlayer player;
  8. BandPass bpf;
  9. //FullScreen fs;
  10. //Serial port;
  11. String X_data = "";
  12. String Y_data = "";
  13. String data = "";
  14. int index= 0;
  15. int x = 0;
  16. int y = 220;
  17. void setup()
  18. {
  19.   size(1300, 700, P3D);
  20.   minim = new Minim(this);
  21.   String audioFile = selectInput();
  22.   //fs = new FullScreen(this);
  23.   ///fs.enter();
  24.   //port = new Serial(this, "COM3", 9600);
  25.   // port.bufferUntil('.');
  26.   player = minim.loadFile(audioFile);
  27.   player.loop();
  28.   bpf = new BandPass(440, 20, player.sampleRate());
  29.   player.addEffect(bpf);
  30.   //smooth();
  31. }
  32. void draw()
  33. {
  34.   lights();
  35.   background(0);
  36.   //
  37.   //graph  *********************************************************

  38.   //camera();

  39.   perspective();
  40.   stroke(255);
  41.   for (int i = 0; i < player.right.size()-1; i++)
  42.   {
  43.     float x1 = map(i, 0, player.bufferSize(), 0, width);
  44.     float x2 = map(i+1, 0, player.bufferSize(), 0, width);
  45.     //line(x1, height/4 - player.left.get(i)*50, x1, height/4 - player.left.get(i+1)*50);
  46.     line(x1, 3*height/4 - player.right.get(i)*50, -550.0,
  47.     x2, 3*height/4 - player.right.get(i+1)*50, -550.0 );
  48.   }
  49.   // map the blob position to the range [100, 10000], an arbitrary range of passBand frequencies
  50.   float passBand = map(x, 0, width, 100, 2000);
  51.   bpf.setFreq(passBand);
  52.   float bandWidth = map(y, 0, height, 50, 500);
  53.   bpf.setBandWidth(bandWidth);
  54.   // prints the new values of the coefficients in the console
  55.   bpf.printCoeff();
  56.   //translation of cube *************************************************************
  57.   float cameraY = height/2.0;
  58.   float fov = y/float(width) * PI/2;
  59.   float cameraZ = cameraY / tan(fov / 2.0);
  60.   float aspect = float(width)/float(height);

  61.   perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);

  62.   translate(width/2+30, height/2, 0);
  63.   rotateX(-PI/6);
  64.   rotateY(PI/3 + x/float(height) * PI);
  65.   stroke(255, 0, 8, 60);
  66.   strokeWeight(3);
  67.   noFill();
  68.   box(45);
  69.   translate(0, 0, -50);
  70. }
  71. //void serialEvent (Serial port)
  72. //{
  73. //  data = port.readStringUntil('.');
  74. //  data = data.substring(0, data.length() - 1);
  75. //
  76. //  index = data.indexOf(",");
  77. //
  78. //  X_data = data.substring(0, index);
  79. //  X_data = trim(X_data);
  80. //  x = int(X_data);
  81. //
  82. //  Y_data = data.substring(index+1, data.length());
  83. //  Y_data = trim(Y_data);
  84. //  y = int(Y_data);
  85. //}
  86. void stop()
  87. {
  88.   player.close();
  89.   minim.stop();
  90.   super.stop();
  91. }


Viewing all articles
Browse latest Browse all 1768

Trending Articles