New to this, any help would be largely appreciated.

So im trying to create something like this:

what ive got so far works as a spectrogram but its not in a circular shape or turning. Any help would be really appreciated! and so far ive got this:

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

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

Minim minim;
AudioInput in;
FFT fft;
int colmax = 500;
int rowmax = 256;
int[][] sgram = new int[rowmax][colmax];
int col;
int rightedge;


float r = 75;
float theta = PI / 1;
float x = r * cos(theta);
float y = r * sin(theta);


void setup(){

  size(500, 500);
  background(0);

  minim = new Minim(this);

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

  fft = new FFT(in.bufferSize(), in.sampleRate());
  fft.window(FFT.HAMMING);
}

void draw(){
  x = r * cos(theta);
  y = r * sin(theta);

noStroke();
fill(100);
ellipse(x+width/1, y+height/1, 200, 216);

theta += 500;

// perform a forward FFT on the samples in the input buffer
fft.forward(in.mix);

for (int i = 0; i < rowmax /* fft.specSize() */; i++)
{
  // fill in the new column of spectral values
  sgram[i][col] = (int)Math.round(Math.max(0, 2*20*Math.log10(1000*fft.getBand(i))));
}

// next time will be the next column
col = col + 1; 
// wrap back to the first column when we get to the end
if (col == colmax) { 
  col = 0;
}

// Draw points.  
// leftedge is the column in the ring-filled array that is drawn at the extreme left
// start from there, and draw to the end of the array
for (int i = 0; i < colmax-rightedge; i++) {
  for (int j = 0; j < rowmax; j++) {
    stroke(sgram[j][i+rightedge]);
    point(i, height-j);
  }
}

// Draw the rest of the image as the beginning of the array (up to leftedge)
for (int i = 0; i < rightedge; i++) {
  for (int j = 0; j < rowmax; j++) {
    stroke(sgram[j][i]);
    point(i+colmax-rightedge, height-j);
  }
}
// Next time around, we move the left edge over by one, to have the whole thing
// scroll left
rightedge = rightedge + 10; 
// Make sure it wraps around
if (rightedge == colmax) { 
  rightedge = 50;
}
}


void stop()
{
  // always close Minim audio classes when you finish with them
  in.close();
  minim.stop();

  super.stop();
}

Answers

  • that's way over my head

    • but maybe you could use background(0); at the beginning of draw()

    also remember that draw() just stores everything that happens on the canvas and puts it out at its end at once

    that means that you won't see any movement when using a for-loop inside draw(). It just adds up internally and will be shown after the for-loop at the end of draw()

    so maybe you want to use the loop of draw() itself?

    As said I don't understand your code...

    ;-)

  • if it helps, here is the code i borrowed from: import ddf.minim.analysis.*; import ddf.minim.*;

    Minim minim; AudioInput in; FFT fft; int colmax = 500; int rowmax = 256; int[][] sgram = new int[rowmax][colmax]; int col; int leftedge;

    void setup() { size(512, 256, P3D);

    minim = new Minim(this);

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

    fft = new FFT(in.bufferSize(), in.sampleRate()); fft.window(FFT.HAMMING); }

    void draw() { background(0); stroke(255);

    // perform a forward FFT on the samples in the input buffer fft.forward(in.mix);

    for(int i = 0; i < rowmax /* fft.specSize() /; i++) { // fill in the new column of spectral values sgram[i][col] = (int)Math.round(Math.max(0,220Math.log10(1000fft.getBand(i)))); }

    // next time will be the next column col = col + 1; // wrap back to the first column when we get to the end if (col == colmax) { col = 0; }

    // Draw points.
    // leftedge is the column in the ring-filled array that is drawn at the extreme left // start from there, and draw to the end of the array for (int i = 0; i < colmax-leftedge; i++) { for (int j = 0; j < rowmax; j++) { stroke(sgram[j][i+leftedge]); point(i,height-j); } }

    // Draw the rest of the image as the beginning of the array (up to leftedge) for (int i = 0; i < leftedge; i++) { for (int j = 0; j < rowmax; j++) { stroke(sgram[j][i]); point(i+colmax-leftedge,height-j); } } // Next time around, we move the left edge over by one, to have the whole thing // scroll left leftedge = leftedge + 1; // Make sure it wraps around if (leftedge == colmax) { leftedge = 0; } }

    void stop() { // always close Minim audio classes when you finish with them in.close(); minim.stop();

    super.stop(); }

Sign In or Register to comment.