Translating music waves to form

Hi everyone,

I am trying to define a scripting that calculates the sound wave and then whenever it is more than an amount, it creates random points and then it connects the points with line. I developed the scripting and was wondering if anyone has any idea about the error that I am getting.

</**
  * This sketch demonstrates how to play a file with Minim using an AudioPlayer. <br />
  * It's also a good example of how to draw the waveform of the audio. Full documentation 
  * for AudioPlayer can be found at http://code.compartmental.net/minim/audioplayer_class_audioplayer.html
  * <p>
  * For more information about Minim and additional features, 
  * visit http://code.compartmental.net/minim/
  */

import ddf.minim.*;

Minim minim;
AudioPlayer player;

ArrayList stpoints=new ArrayList();
stpoint.add(new PVecor(xp,yp,zp));
float hvalue;
float threshold;
float xr;
float yr;
float zr;



void setup()
{
  size(512, 200, P3D);
  
  // we pass this to Minim so that it can load files from the data directory
  minim = new Minim(this);
  // loadFile will look in all the same places as loadImage does.
  // this means you can find files that are in the data folder and the 
  // sketch folder. you can also pass an absolute path, or a URL.
  player = minim.loadFile("rec20190723151425-46119.mp3");}}  
}
void Draw(){
  background(0);
  pushMatrix();
  ///simulated camera//////////////////
  translate(width/2,height/2);
  rotateY(PI*2*mouseX/width);
  rotateX(PI*2*mouseY/height);
  
  ///end camera//
  
  stroke(255);
  for(int i = 0; i < player.mix. size () - 1; i++)
  {
    if(hvalue <abs(player.mix.get(i))){hvalue = abs(player.mix.get(i));
  }
  if(hvalue>threshold){
    float xp = random(-300,300);
    float yp = random(-300,300);
    float zp=random(-300,300);
    stpoints.add(new PVector(xp,yp,zp));
    
 //The processing script reads the audio file and calculates the sound-wave. A height threshold was applied to the wave lenghts, if the sound-wave exceeded the limit, a vector point was created.
 //vector connects the points into a larger tessellation.
  {
  PVector newcoor=stpoints.get(i); 
         xr=xr+newcoor.x;
         yr=yr+newcoor.y;
         zr=zr+newcoor.z;
  }   
for (int j=0; j<stpoints.size();j++){
  PVector coor1=stpoints.get(j);
  PVector coor2=stpoints.get(j);
  line (coor1.x,coor1.y,coor1.z,coor2.x,coor2.y,coor2.z);
   }
}
```>

Please format code in your forum posts with the </> button so that people can read it more easily.

Do you mean the volume, or the pitch?

What error are you getting?

The pitch actually. The error is saying there is one bracket is missing although is not and when I add that, another error comes up.

This code has multiple problems, but one in particular is preventing you from seeing some of the others.

  1. This line:

     player = minim.loadFile("rec20190723151425-46119.mp3");}}
    

…has two invalid }} at the end of it. That is breaking everything. Delete them. You are also missing two }} at the end of your file. Add them.

  1. the main loop must be called draw not Draw

  2. you have bare code in your header, outside setup: don’t do that, move it to setup.

    stpoint.add(new PVecor(xp, yp, zp));

  3. also, that line refers to an object that doesn’t exist - you declared it as stpoints, not stpoint.

  4. here is no such thing as PVecor – it is called PVector

  5. ou pass xp, yp, zp, but you declared xr, yr, zy (and then didn’t assign them).

Start by fixing the brackets, then move through the error messages one at a time and resolve them. Ask on this thread if you run into problems and need help!

In the future, it is much MUCH easier to start with a working sketch, change one thing at a time, and resolve errors one at a time. If you keep editing while things are broken, errors can hiding other errors, and they get harder to solve because the sketch doesn’t start working again when you fix one.

Thanks a lot for your description. I am working on that. I another hand, I wrote another sketch that does not have that error but I want to connect it in grasshopper to generate a 3D shape of it or a mesh. Are you able to guide on that area as well? It has the same idea of music and form

If you have another question about different code, post it to the forum as a new thread – if somebody has an idea, you should get an answer.