audio - 最小化和处理问题

标签 audio processing audio-recording minim

试图创建一个可以以不同的频率/速率播放录制的样本并使用TickRate更改播放速率的声音采样器,类似于TickRate示例。当我运行时,我在这里得到了一个N​​ullPointerException 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设置为等于keyReleased()函数中的值。因此,当setup()运行时,player仍具有默认的null值。

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

关于audio - 最小化和处理问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47999511/

相关文章:

javascript - p5.j​​s 使用数组为每个矩形着色

java - 如何了解我的平板电脑支持的采样率?

api - Lua:ProteaAudio API混淆-如何使用?

c - 如何正确设置 ALSA 设备

performance - 处理帧率非常低且无法更改

java - 如何获取 JBox2d 主体尺寸

audio - 解复用 UDP/RTP 多节目传输流

java - 将 CSV 列解析为数组 - 处理

Android MediaRecorder 在某些设备上不工作

java - Android 在后台使用代码录制视频