0

though I have come across a couple of those questions in my search earlier they did not really answer my question. Given that I am using the javax.sound.sampled library, how can I write an audio spectrum for that.
This answer basically describes what I am doing so far.
First I want to "acquire time domain data". About that I have the stupid(?) question what the time domain data is. According to Wikipedia it is a graph that "shows how a signal changes with time". Therefore it would be the derivative of a function representing the data? The example animation on the right of the page does not look like that so I scratched that idea.

Afterwards at the last point the answer mentioned to plotting "log magnitude (with appropriate scaling) against frequency" where I wanted to ask, where exactly to get the frequency from.

Finaly the code I got so far:

    int n = (int)Math.pow(2, 9);
    Complex[] timedomain = new Complex[n];
    for (int i = 0; i < n; i++) {
        timedomain[i] = new Complex(Hann(/*get time domain data i*/), 0);
    }
    Complex[] fft = FFT.fft(timedomain);
    fft = FFT.convolve(fft, fft);

    double[] logMag = new double[fft.length];

    for (int i = 0; i < fft.length; i++) {
        double re = fft[i].re();
        double im = fft[i].im();
        logMag[i] = Math.log10(re*re + im*im);
    }


    int l = logMag.length;
    int y = (int)(getHeight()*2.0f/3);


    Polygon poly = new Polygon();
    poly.addPoint(0, y);
    //Note that I am currently plotting the logMag data only!
    float barW = ((float)getWidth())/l;
    for (int x = 0; x < l; x++) {
        g.setColor(new Color(35, 111, 233));
        int h = (int)(logMag[x]);
        poly.addPoint((int)(x*(barW)), y-h);
        poly.addPoint((int)((x+1)*(barW)), y-h);
    }
    poly.addPoint(getWidth(), y);
    g.fillPolygon(poly);

Any help appreciated, thank You in advance!

Community
  • 1
  • 1
Sheldon
  • 117
  • 1
  • 1
  • 9

0 Answers0