简体   繁体   English

处理最小值中的逆 FFT

[英]Inverse FFT in Processing Minim

I'm trying to output my computer microphone input to the speakers output using Minim in Processing.我正在尝试使用 Minim in Processing 将 output 我的计算机麦克风输入到扬声器 output。 The aim of the project is to analyze an input (the microphone, a sound file, etc), make some alterations to its frequency spectrum, and finally output it to the speakers or save the stuff on a file (I still don't know how to implement this last feature).该项目的目的是分析输入(麦克风,声音文件等),对其频谱进行一些更改,最后将 output 发送到扬声器或将内容保存在文件中(我仍然不知道如何实现最后一个功能)。

I referred to mots' answer in this post https://forum.processing.org/beta/num_1256413038.html to make it, but I can't let it work: nothing is being played through the speakers.我在这篇文章https://forum.processing.org/beta/num_1256413038.html中提到了 mots 的答案,但我不能让它工作:没有通过扬声器播放。

This is the code I'm using:这是我正在使用的代码:

import ddf.minim.*;
import ddf.minim.analysis.*;


private FFT fftIn, fftOut;
private AudioInput input;
private AudioOutput output;
private Minim minim;

void setup() {
  size(300, 200);

  minim = new Minim(this);

  input = minim.getLineIn();
  input.addListener(new Listener());

  output = minim.getLineOut();
  output.addSignal(new Signal());
  
  fftOut = fftIn = new FFT(input.bufferSize(), input.sampleRate());
}

class Listener implements AudioListener {
  public void  samples(float[] sample) {
    fftIn.forward(sample);
  }
  public void samples(float[] left, float[] right) {
    samples(left);
  }
}


private class Signal implements AudioSignal {
  public void generate(float[] sample) {
    boolean mode = false;
    
    if (mode) {
      fftIn.inverse(sample);
    } else {
      for (int i = 0; i < input.bufferSize() / 2; i++) {
        fftOut.setBand(i, fftIn.getBand(i));
      }                
      fftOut.inverse(sample);
    }
  }

  public void generate(float[] left, float[] right) {
    generate(right);
  }
}

Any reply is accepted,接受任何回复,

Simone西蒙娜

I debugged the code that you posted and it should now run without error.我调试了您发布的代码,它现在应该可以正常运行。 I'm not sure how the demo actually works, but it does produce a scratchy output from my macOS speakers, which is consistent with comments by the original author.我不确定演示实际上是如何工作的,但它确实从我的 macOS 扬声器中产生了一个沙哑的 output,这与原作者的评论一致。 Note that the 'println' calls indicate that 'fftIn' is indeed equal to 'fftOut'.请注意,“println”调用表明“fftIn”确实等于“fftOut”。 output.AddSignal() had to be moved down a couple of lines because it relies upon values for fftIn and fftOut. output.AddSignal()必须向下移动几行,因为它依赖于 fftIn 和 fftOut 的值。 It was also necessary to separate 'fftIn' from 'fftOut', even though they are equal.也有必要将 'fftIn' 和 'fftOut' 分开,即使它们是相等的。 Revisions are notated in the source code.修订在源代码中注明。 An empty draw() was added in order to get it to run (won't run without it).添加了一个空的 draw() 以使其运行(没有它就不会运行)。

import ddf.minim.*;
import ddf.minim.analysis.*;

private FFT fftIn, fftOut;
private AudioInput input;
private AudioOutput output;
private Minim minim;

void setup() {
  size(300, 200);
  minim = new Minim(this);
  // Added Minim.MONO
  input = minim.getLineIn(Minim.MONO);
  input.addListener(new Listener());
  output = minim.getLineOut();
  // Separated fftIn from fftOut
  fftIn = new FFT(input.bufferSize(), input.sampleRate());
  println("fftIn =",fftIn);
  fftOut = fftIn;
  // moved this down here because it needs fftIn, fftOut
  output.addSignal(new Signal());
}

class Listener implements AudioListener {
  public void  samples(float[] sample) {
    fftIn.forward(sample);
  }
  public void samples(float[] left, float[] right) {
    samples(left);
  }
}

private class Signal implements AudioSignal {
  public void generate(float[] sample) {
    boolean mode = false;
    println("fftOut =",fftOut);
    if (mode) {
      fftIn.inverse(sample);
    } else {
      for (int i = 0; i < input.bufferSize() / 2; i++) {
        fftOut.setBand(i, fftIn.getBand(i));
      }                
      fftOut.inverse(sample);
    }
  }

  public void generate(float[] left, float[] right) {
    generate(right);
  }
}

// Won't run without adding this
void draw() {  
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM