如何调整处理/最小波形标度?

问题描述

我是一个完全的初学者,所以如果我问这可能是愚蠢的或不恰当的,请原谅我。 我正在尝试制作我自己的处理中的虚拟示波器。我真的不知道如何解释它,但我想从我获得波形峰值的地方“缩小”,也就是窗口大小。我不确定我在这里做错了什么或我的代码有什么问题。我尝试更改缓冲区大小,并更改 x/y 的乘数。我的草图改编自一个最小的示例草图。 非常感谢所有帮助。

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,fade);
      rect (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);
  }
}

谢谢

解决方法

编辑:这里不需要推送和弹出矩阵。猜猜我对它的理解也缺乏。您可以使用翻译。

您可以使用矩阵来创建相机对象,您可以阅读大量材料以了解其背后的数学原理并在任何地方实现它。

但是,这里可能有更简单的解决方案。您可以将 pushMatrixpopMatrixtranslate 结合使用。推入和弹出矩阵将操纵矩阵堆栈 - 您创建一个新的“框架”,您可以在其中玩转翻译,然后弹出原始框架(这样您就不会因在每个框架上应用新翻译而迷路)。

推动矩阵,在绘制您想要缩小的所有内容之前平移一次 z 坐标,弹出矩阵。您可以为翻译设置一个变量,以便您可以用鼠标控制它。

这是一个粗略的示例(我没有所有这些库,因此无法将其添加到您的代码中):

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);
  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,scroll);
  
  //Draw zoomed elements
  fill(0,255,400,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();
}