【问题标题】:How do I adjust Processing/Minim waveform scale?如何调整处理/最小波形比例?
【发布时间】:2025-12-27 19:50:06
【问题描述】:

我是一个完全的初学者,所以如果我问这个问题可能很愚蠢或不恰当,请原谅我。 我正在尝试制作自己的虚拟示波器进行处理。我真的不知道如何解释它,但我想从我得到波形峰值的位置“缩小”,即窗口大小。我不确定我在这里做错了什么或我的代码有什么问题。我尝试更改缓冲区大小,并更改 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, 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);
  }
}

谢谢

【问题讨论】:

    标签: java audio processing waveform minim


    【解决方案1】:

    编辑:这里不需要推送和弹出矩阵。估计我对它的理解也欠缺。你可以只使用翻译。

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

    但是,这里可能有一个更简单的解决方案。您可以将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,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();
    }
    

    【讨论】: