processing/processing-sound

Add PortAudio libraries with ALSA support for Linux/Raspberry Pi

開放

#8 建立於 2018年9月8日

 (4 則留言) (0 個反應) (0 位負責人)Java (49 個分叉)auto 404
Linux/Raspberry Pienhancementhelp wanted

倉庫指標

星標
 (163 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

I've tried using the FFT example sketch to visualize the monitor output of my computer's sound card. But I've noticed that there is a 2~ second delay between the audio output, and the visualization on the screen.

Any ideas what could be causing this?

I'm using Processing 3.3.7 and version 2.0.1 of processing-sound Using GNU/Linux with ALSA&PulseAudio.

If you need any specific details, please tell me. I can't think of anything else to add.

public class AudioVisualizer extends PApplet {

    private FFT fft;
    private AudioIn in;
    private int bands = 16;
    private float[] spectrum = new float[bands];

    public static void main(String[] args) {
        PApplet.main(AudioVisualizer.class.getCanonicalName());
    }

    @Override
    public void settings() {
        size(512, 360);
    }

    @Override
    public void setup() {
        background(255);

        // Create an Input stream which is routed into the Amplitude analyzer
        fft = new FFT(this, bands);
        in = new AudioIn(this);
        // start the Audio Input
        in.start();
        in.play();

        // patch the AudioIn
        fft.input(in);
    }

    @Override
    public void draw() {
        background(255);
        fft.analyze(spectrum);

        for(int i = 0; i < bands; i++){
            // The result of the FFT is normalized
            // draw the line for frequency band i scaling it up by 5 to get more amplitude.
            line( i, height, i, height - spectrum[i]*height*5 );
        }
    }
}

貢獻者指南