0

I'm a total beginner so forgive me if this is probably silly or improper of me to ask. I'm trying to make my own virtual oscillograph in processing. I don't really know how to explain it, but I want to "zoom out" from where I am getting the peaks in waveforms, which is the window size. I'm not sure what I'm doing wrong here or what's wrong with my code. I've tried changing the buffer size, and changing the multiplier for x/y. My sketch is adapted from a minim example Sketch. All Help is greatly appreciated.

import ddf.minim.*;

Minim minim;
AudioInput in;

int frames;
int refresh = 7;
float fade = 32;

void setup()
{
  size(800, 800, P3D);
  
  minim = new Minim(this);
  
  ellipseMode(RADIUS);
  // use the getLineIn method of the Minim object to get an AudioInput
  in = minim.getLineIn(Minim.STEREO);
  println (in.bufferSize());
  //in.enableMonitoring();
  frameRate(1000);
  background(0);
}
 
void draw()
{
  frames++; //same saying frames = frames+1
  if (frames%refresh == 0){
      fill (0, 32, 0, fade);
      rect (0, 0, width, height);
    }
  
  float x;
  float y;
  stroke (0, 0);
  fill (0,255,0);
  // draw the waveforms so we can see what we are monitoring
  for(int i = 0; i < in.bufferSize() - 1; i++)
  {
    x = width/2 + in.left.get(i)  * height/2;
    y = height/2- in.right.get(i) * height/2;
      
    ellipse(x, y, .5, .5);
  }
}

Thanks

Kaneo
  • 1
  • 1

1 Answers1

0

Edit: you don't need push and pop matrix here. Guess my understanding of it is lacking too. You can just use translate.

You can use matrices to create a camera object, there is tons of material out there that you can read up on to understand the math behind this and implement it anywhere.

However, there might be an easier solution here. You can use pushMatrix and popMatrix in combination with translate. Push and popping the matrix will manipulate the matrix stack - you create a new "frame" where you can play around with translations, then pop back the original frame (so you don't get lost by applying new translations on each frame).

push the matrix, translate the z coordinate once before drawing everything you want zoomed out, pop the matrix. You can set up a variable for the translation so that you can control this with your mouse.

Here's a crude example (I don't have all those libraries so couldn't add it to your code):

float scroll = 0;
float scroll_multiplier = 10;

void setup()
{
  size(800, 800, P3D);
  frameRate(1000);
  background(0);
}
 
void draw()
{
  background(0);
  
  //draw HUD - things that don't zoom.
  fill(255,0,0);
  rect(400,300,100,100);
  
  //We don't want to mess up our coordinate system, we push a new "frame" on the matrix stack
  pushMatrix();
  //We can now safely translate the Y axis, creating a zoom effect. In reality, whatever we pass to translate gets added to the coordinates of draw calls.
  translate(0,0,scroll);
  
  //Draw zoomed elements
  fill(0,255,0);
  rect(400,400,100,100);
  
  //Pop the matrix - if we don't push and pop around our translation, the translation will be applied every frame, making our drawables dissapear in the distance.
  popMatrix();
  
}



void mouseWheel(MouseEvent event) {
  scroll += scroll_multiplier * event.getCount();
}
fstam
  • 669
  • 4
  • 20