【问题标题】:problems with minim and processing最小化和处理问题
【发布时间】:2017-12-27 22:47:42
【问题描述】:

尝试创建一个声音采样器,它可以以不同的频率/速率播放录制的样本,并使用 TickRate 来更改播放速率,类似于 TickRate 示例。当我运行时,我在这里得到一个 NullPointerException player.patch(rateControl).patch(out); 但不知道为什么,有什么想法吗?

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.signals.*;
import ddf.minim.ugens.*;
import ddf.minim.spi.*;

Minim minim;
AudioOutput out;
AudioSample sample1;

AudioInput in;
AudioRecorder recorder;
boolean recorded;
FilePlayer player;
TickRate rateControl;

void setup()
{

  size(512, 200, P3D);
  minim = new Minim(this);

  in = minim.getLineIn(Minim.STEREO, 512);

  recorder = minim.createRecorder(in, "myrecording2.wav");
  rateControl = new TickRate(1.f);
  out = minim.getLineOut(Minim.STEREO, 512);
  player.patch(rateControl).patch(out);


  textFont(createFont("Arial", 12));

}

void draw()
{
  if ( recorder.isRecording() )
  {
    fill(255,255,255);
    text("Now recording, press the r key to stop recording.", 5, 310);
  }
  else if ( !recorded )
  {
    fill(255,255,255);
    text("Press the r key to start recording.", 5, 315);
  }
  else
  {
    fill(255,255,255);
    text("Press the q key to save the recording to disk as a sample.", 5, 315);

  }

    for(int i = 0; i < out.bufferSize() - 1; i++)
  {
    float x1 = map(i, 0, out.bufferSize(), 0, width);
    float x2 = map(i+1, 0, out.bufferSize(), 0, width);
    line(x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
    line(x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
  }

}

void keyReleased()
{
  if ( !recorded && key == 'r' ) 
  {
    if ( recorder.isRecording() ) 
    {
      recorder.endRecord();
      recorded = true;
    }
    else 
    {
      recorder.beginRecord();
    }
  }
  if ( recorded && key == 'q' )
  {
    player = new FilePlayer( recorder.save() );
    sample1 = minim.loadSample( "myrecording.wav" , 512 );
    if ( sample1 == null ) println("didn't get sample");
  }
}

void keyPressed()
{
  if ( key == 's' ) 
  {
    sample1.trigger();
  }

  else if ( key == 'd' )
  {
    rateControl.value.setLastValue(3.0f);
    sample1.trigger();
  }

}

【问题讨论】:

  • player 应该是什么?看起来它仍然是空的。不过我不熟悉这段代码,所以如果这是一个愚蠢的问题,请原谅我的无知:)
  • @DerekHopper player 是我给 FilePlayer 起的名字,我认为它可能仍然为空,但不知道该怎么做。老实说,我自己也不太熟悉。谢谢:)

标签: audio processing audio-recording minim


【解决方案1】:

您只需将player 设置为等于keyReleased() 函数中的某个值。所以当setup() 运行时,player 仍然具有默认的null 值。

退一步,你应该养成debugging your code的习惯。当您收到NullPointerException 时,尝试打印出该行上每个变量的值。你会发现哪个是null,然后你就可以找出原因了。

【讨论】:

  • 哦,好吧。我现在就试试,非常感谢凯文 :)
  • 谢谢凯文。这有助于摆脱 'NullPointerException' 。现在我只需要弄清楚在播放样本时如何让滴答声发挥作用:)
  • @michaeldoherty 只是出于好奇,你有什么理由不接受这个答案吗?
猜你喜欢
  • 1970-01-01
  • 2011-04-06
  • 2023-03-17
  • 2010-09-22
  • 1970-01-01
  • 2013-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多