How to make a track attachment visualization?

i have 2 codes
1)

import processing.dxf.*;
import ddf.minim.analysis.*;
import ddf.minim.*;

FFT fftLin;
FFT fftLog;

Waveform audio3D;

Minim minim;
AudioInput microphone;

boolean record;

PFont font;

float camzoom;
float maxX = 0;float maxY = 0;float maxZ = 0;
float minX = 0;float minY = 0;float minZ = 0;

void setup()
{
  size(1250,750,P3D); //screen proportions
  noStroke();
  minim = new Minim(this);
  microphone = minim.getLineIn(Minim.STEREO, 4096); //repeat the song

  background(255);

  fftLog = new FFT(microphone.bufferSize(),microphone.sampleRate());
  fftLog.logAverages(1,2);  //adjust numbers to adjust spacing;
  float w = float (width/fftLog.avgSize());
  float x = w;
  float y = 0;
  float z = 50;
  float radius = 10;
  audio3D = new Waveform(x,y,z,radius);
}
void draw()
{
  background(0);
  directionalLight(126,126,126,sin(radians(frameCount)),cos(radians(frameCount)),1);
  ambientLight(102,102,102);

  if (frameCount>200)
  {
    for(int i = 0; i < fftLog.avgSize(); i++){
      float zoom = 1;
      float jitter = (fftLog.getAvg(i)*2);
      //println(jitter);
      PVector foc = new PVector(audio3D.x+jitter, audio3D.y+jitter, 0);
      PVector cam = new PVector(zoom, zoom, -zoom);
      camera(foc.x+cam.x+50,foc.y+cam.y+50,foc.z+cam.z,foc.x,foc.y,foc.z,0,0,1);
    }
  }
  //play the song
  fftLog.forward(microphone.mix);

  audio3D.update();
  audio3D.textdraw();

  if(record)
  {
    beginRaw(DXF, "output.dxf");
  }
  audio3D.plotTrace();

  if(record)
  {
    endRaw();
    record = false;
    println("It's Done Bitches! Find your DXF!");
  }
}
void stop()
{
  // always close Minim audio classes when you finish with them
  microphone.close();
  // always stop Minim before exiting
  minim.stop();
  super.stop();
}
class Waveform
{
  float x,y,z;
  float radius;

  PVector[] pts = new PVector[fftLog.avgSize()];

  PVector[] trace = new PVector[0];

  Waveform(float incomingX, float incomingY, float incomingZ, float incomingRadius)
  {
    x = incomingX;
    y = incomingY;
    z = incomingZ;
    radius = incomingRadius;
  }
  void update()
  {
    plot();
  }
  void plot()
  {
    for(int i = 0; i < fftLog.avgSize(); i++)
    {
      int w = int(width/fftLog.avgSize());

      x = i*w;
      y = frameCount*5;
      z = height/4-fftLog.getAvg(i)*4; //change multiplier to reduces height default '10'

      stroke(0);
      point(x, y, z);
      pts[i] = new PVector(x, y, z);
      //increase size of array trace by length+1
      trace = (PVector[]) expand(trace, trace.length+1);
      //always get the next to last
      trace[trace.length-1] = new PVector(pts[i].x, pts[i].y, pts[i].z);
    }
  }
  void textdraw()
  {
    for(int i =0; i<fftLog.avgSize(); i++){
      pushMatrix();
      translate(pts[i].x, pts[i].y, pts[i].z);
      rotateY(PI/2);
      rotateZ(PI/2);

      fill(255,200);
      text(round(fftLog.getAvg(i)*100),0,0,0);
      popMatrix();
    }
  }
  void plotTrace()
  {
    stroke(255,80);
    int inc = fftLog.avgSize();

    for(int i=1; i<trace.length-inc; i++)
    {
      if(i%inc != 0)
      {
        beginShape(TRIANGLE_STRIP);

        float value = (trace[i].z*100);
        float m = map(value, -500, 20000, 0, 255);
        fill(m*2, 125, -m*2, 140);
        vertex(trace[i].x, trace[i].y, trace[i].z);
        vertex(trace[i-1].x, trace[i-1].y, trace[i-1].z);
        vertex(trace[i+inc].x, trace[i+inc].y, trace[i+inc].z);
        vertex(trace[i-1+inc].x, trace[i-1+inc].y, trace[i-1+inc].z);
        endShape(CLOSE);
      }
    }
  }
}
void keyPressed()
{
  if (key == 'r') record = true;
}

from https://kylejanzen.wordpress.com/2011/09/29/3d-spectrogram-with-processing-and-microphone/
and 2)

import ddf.minim.*;
import ddf.minim.effects.*;

Minim minim;
AudioPlayer track;

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

minim = new Minim(this);
track = minim.loadFile("track.mp3", 2048);
}

void draw()
{
background(0);

stroke(255);

for (int i = 0; i < track.bufferSize() - 1; i++)
{
line(i, 50 + track.left.get(i)*50, i+1, 50 + track.left.get(i+1)*50);
line(i, 150 + track.right.get(i)*50, i+1, 150 + track.right.get(i+1)*50);
}
}

void keyPressed()
{
if ( key == 'k' ) track.loop();
}

I want visualize like 1-st looks like,but with my track, is not micro. I don’t know how to do it. I tried to combine them,but nothing works. If u know another code,tell me):wink: Plz)
P.S. i’m a novice,sorry if i am so stupid:disappointed: and sorry for my eng)

1 Like

Please format your Code correctly.

https://kylejanzen.wordpress.com/2011/09/29/3d-spectrogram-with-processing-and-microphone/ first
second:

import ddf.minim.*;
import ddf.minim.effects.*;

Minim minim;
AudioPlayer track;

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

minim = new Minim(this);
track = minim.loadFile("track.mp3", 2048);
}

void draw()
{
background(0);

stroke(255);

for (int i = 0; i < track.bufferSize() - 1; i++)
{
line(i, 50 + track.left.get(i)*50, i+1, 50 + track.left.get(i+1)*50);
line(i, 150 + track.right.get(i)*50, i+1, 150 + track.right.get(i+1)*50);
}
}

void keyPressed()
{
if ( key == 'k' ) track.loop();
}

Again, please format your code correctly. Noone will look through all that Code to help you, if you don‘t even take the time to format it correctly…

You already have ~ 1/20 of your Code formatted, so you should know how to do it. If not, it‘s the </> symbol. It should look like this :

Your Code goes here...
2 Likes
import processing.dxf.*;
import ddf.minim.*; 
import ddf.minim.effects.*;
FFT fftLin;
FFT fftLog;
Minim minim;
PFont font;

float camzoom;
float maxX = 0;float maxY = 0;float maxZ = 0;
float minX = 0;float minY = 0;float minZ = 0;
AudioPlayer track;
int frequency=0;
void setup() 
{
size(512, 200, P3D);
  minim = new Minim(this); 
track = minim.loadFile("track.aiff", 2048);
fftLog = new FFT("track.aiff", 2048);
fftLog.logAverages(1,2);
} 
void draw()
{
  background(200);
  if (frequency>2)
  { 
line(50,0, 40,0);}
else {
line(40,0, 30,0);
} 
} 
 void keyPressed() 
{ 
if ( key == 'k' ) track.loop(); 
}


i tried to make such a code,but it doesn’t work

Were you able to resolve your problem?

I’m not sure I understand what you are asking here. If you still have a problem, perhaps you could explain more and give more details? What does it do now; what do you want it to do instead?