Minim Waveform problem

edited December 2016 in Library Questions

Hi all !

i've been coding in processing for a few month now and i'm starting to use minim to add sound in my sketches yet i'm totally new to this library and afters hours of strugling i can't find a way to solve my problem: here is my basic code

import ddf.minim.*;
Minim minim;
AudioPlayer groove;
float x, y, a, b, c, d, z;
PFont police;
PFont polisse;
String DISASTERPEACE;
String HLD;

void setup() { 
  size(600, 600);
  minim = new Minim(this);
  groove = minim.loadFile("groove.mp3", 1024);
  groove.loop();
  background(0); 
  textAlign(CENTER);
  emissive(0, 26, 51);
 police=createFont("drifter.ttf", 32);
 polisse=createFont("DF.ttf", 25);
   textFont(police);
 HLD="Hyper Light Drifter";
  DISASTERPEACE="DISASTERPEACE";
  smooth();
  stroke(random(0, 255), random(0, 255), random(0, 255));

  for (int i=0; i<40; i++)
  { 
    fill(random(0, 255), random(0, 255), random(0, 255));
    ellipse(x, y, z, z);
    ellipse(a, b, z, z);
    ellipse(c, d, z, z);
    line(x, y, a, b);  
    line(x, y, c, d); 
    line(c, d, a, b);    
    x=random(0, 600);
    y=x+20;
  a=x-20;
    b=random(0, 600);
   c=b+20;
    d=b-20;
    z=3;
  }
  fill(255);
    textSize(12);
  text(HLD, 300, 275);
   textSize(30);
  text(DISASTERPEACE, 300, 313);
  //save("ESSAIS10.jpg");
}

so i simply want the line to react to the playing music, i've read a ton of minim releated stuff and saw all the exemples about it and yet i can't manage to make thoose line vibrate to the music

i've tried many things but nothing worked.

thanks for your help

Tagged:

Answers

  • don't quote your code.

    edit post, highlight code, press ctrl-o

  • tried but can't make that work too ^^

  • done

    i've been coding in processing for a few month now

    so i guess you've written code with both a setup() and a draw() before now. where's the draw() in this code?

  • edited December 2016

    thx, thats where i'm struggling, i know i need a draw to play the song, yet i've tried things such as moving the line from the setup to a draw but since i have a ton different coordinate ( all created randomly) for the ellipses and the line this is not working.

    the problem is that i can't find a way to get enough lines without having to create a ton of value because i know i need the different value of each line in order to add the soundwave movement to them.

  • i've tried things such as moving the line from the setup to a draw

    which line?

    because i know i need the different value of each line in order to add the soundwave movement to them

    no real idea what you're talking about here. it's not obvious what you want the final thing to look like.

  • edited December 2016

    i meant the lines, sorry english is not my birth language

    however, if you tried my code, you can see multiples lines and ellipses, well i just want the existing lines to react to the playing music using something like this ( it's the code from the minim package called DrawWaveFormAndLevel in the " basics" file )

    for(int i = 0; i < groove.bufferSize() - 1; i++) { float x1 = map( i, 0, groove.bufferSize(), 0, width ); float x2 = map( i+1, 0, groove.bufferSize(), 0, width ); line( x1, 50 + groove.left.get(i)*50, x2, 50 + groove.left.get(i+1)*50 ); line( x1, 150 + groove.right.get(i)*50, x2, 150 + groove.right.get(i+1)*50 ); }

    my problem is that all my lines are generated using random values and since they are generated in a setup() using for() they don't have specific locations

  • @Spoll=== try to create 2 arrays[] (for the x and b values, other can be found from them) and add your random values to the arrays in setup(); in draw you work with the stored values and can make the lines interact with line get in from minim.

  • edited December 2016

    thanks @akenaton=== so here is what i get

    import ddf.minim.*;
    Minim minim;
    AudioPlayer groove;
    float  y, a, b, c, d, z;
    PFont police;
    PFont polisse;
    String DISASTERPEACE;
    String HLD;
    
    void setup() { 
      size(600, 600);
      minim = new Minim(this);
      groove = minim.loadFile("groove.mp3", 1024);
      groove.loop();
      background(0); 
      textAlign(CENTER);
      emissive(0, 26, 51);
      police=createFont("drifter.ttf", 32);
      polisse=createFont("DF.ttf", 25);
      textFont(police);
      HLD="Hyper Light Drifter";
      DISASTERPEACE="DISASTERPEACE";
      smooth();
      stroke(random(0, 255), random(0, 255), random(0, 255));
      float x []  = { random(30, 570), random(30, 570), random(30, 570), random(30, 570), random(30, 570), random(30, 570), random(30, 570) }; // Declare, create, assign
      float b []  = { random(30, 570), random(30, 570), random(30, 570), random(30, 570), random(30, 570), random(30, 570), random(30, 570) };
      for (int i=0; i<3; i++)
      { 
        for ( int e=0; e<7; e++) {
          for ( int f=0; f<7; f++) {
          fill(random(0, 255), random(0, 255), random(0, 255));
          ellipse(x[e], y, z, z);
          ellipse(a, b[f], z, z);
          ellipse(c, d, z, z);
          line(x[e], y, a, b[f]);  
          line(x[e], y, c, d); 
          line(c, d, a, b[f]);    
          y=x[e]+20;
          a=x[e]-20;      
          c=b[f]+30;
          d=b[f]-10;
          z=3;
        }
        }
      }
      fill(255);
      textSize(12);
      text(HLD, 300, 275);
      textSize(30);
      text(DISASTERPEACE, 300, 313);
      //save("ESSAIS10.jpg"); }  </pre>
    
    //i've tried to move everything from setup to draw but the lines and ellipses won't stop //being created until the whole windows is full
    //i've tried to move certain part of code ( the lines) into draw() but processing can't get //the value of x and b from the setup()
    
  • i'm really having a hard time with that ><

  • @Spoll===

    something like that???- of course i have not added the minim getLineIn stuff but that is easy.

        import ddf.minim.*;
        Minim minim;
        AudioPlayer groove;
        float x, y, a, b, c, d, z;
        PFont police;
        PFont polisse;
        String DISASTERPEACE;
        String HLD;
        float[]X;
        float []B;
    
        void setup() { 
          size(600, 600);
          minim = new Minim(this);
          //groove = minim.loadFile("groove.mp3", 1024);
          //groove.loop();
          background(0); 
          X = new float[40];
          B =new float [40];
          textAlign(CENTER);
          emissive(0, 26, 51);
        // police=createFont("drifter.ttf", 32);
        // polisse=createFont("DF.ttf", 25);
        //   textFont(police);
         HLD="Hyper Light Drifter";
          DISASTERPEACE="DISASTERPEACE";
          smooth();
          stroke(random(0, 255), random(0, 255), random(0, 255));
    
          for (int i=0; i<40; i++)
          { 
            fill(random(0, 255), random(0, 255), random(0, 255));
            ellipse(x, y, z, z);
            ellipse(a, b, z, z);
            ellipse(c, d, z, z);
            line(x, y, a, b);  
            line(x, y, c, d); 
            line(c, d, a, b);    
            x=random(0, 600);
            X[i] =x;
            y=x+20;
          a=x-20;
            b=random(0, 600);
            B[i] = b;
           c=b+20;
            d=b-20;
            z=3;
          }
          fill(255);
            textSize(12);
          text(HLD, 300, 275);
           textSize(30);
          text(DISASTERPEACE, 300, 313);
          //save("ESSAIS10.jpg");
        };
    
        void draw(){
    
          background(0);
    
          smooth();
          stroke(random(0, 255), random(0, 255), random(0, 255));
    
          for (int i=0; i<40; i++)
          { 
            fill(random(0, 255), random(0, 255), random(0, 255));
            ellipse(X[i], X[i]+20, z, z);
            ellipse(X[i]-20, B[i], z, z);
            ellipse(B[i]+20, B[i]-20, z, z);
            line(X[i], X[i]+20, X[i]-20, B[i]);  
            line(X[i], X[i]+20, B[i]+20, B[i]-20); 
            line(B[i]+20, B[i]-20, X[i]-20, B[i]);    
    
    
    
          }
          fill(255);
            textSize(12);
          text(HLD, 300, 275);
           textSize(30);
          text(DISASTERPEACE, 300, 313);
          //save("ESSAIS10.jpg");
        };
    
  • edited December 2016

    hey, thanks for your answer it helps me a lot, but now i have no idea how to make the lines react to the music ( resulting in a waveform)

    sorry for bothering you

  • edited December 2016

    this is killing me, i don't understand anything about the library, i've made a few test with your code @akenaton=== this really helps me out, but i can't manage to get the lines to react properly to the music all i want is :

    but the only reaction i get is

    here is the code i modified, tell me if i do something wrong, thanks :

    import ddf.minim.*;
    Minim minim;
    AudioPlayer groove;
    float x, y, a, b, c, d, z;
    PFont police;
    PFont polisse;
    String DISASTERPEACE;
    String HLD;
    float[]X;
    float []B;
    
    void setup() { 
      size(600, 600);
      minim = new Minim(this);
      groove = minim.loadFile("groove.mp3", 1024);
      groove.loop();
      background(0); 
      X = new float[40];
      B =new float [40];
      textAlign(CENTER);
      emissive(0, 26, 51);
      police=createFont("drifter.ttf", 32);
      polisse=createFont("DF.ttf", 25);
      textFont(police);
      HLD="Hyper Light Drifter";
      DISASTERPEACE="DISASTERPEACE";
      smooth();
      stroke(random(0, 255), random(0, 255), random(0, 255));
    
      for (int i=0; i<40; i++)
      { 
    
        ellipse(x, y, z, z);
        ellipse(a, b, z, z);
        ellipse(c, d, z, z);
        line(x, y, a, b);  
        line(x, y, c, d); 
        line(c, d, a, b);    
        x=random(0, 600);
        X[i] =x;
        y=x+20;
        a=x-20;
        b=random(0, 600);
        B[i] = b;
        c=b+20;
        d=b-20;
        z=3;
      }
    
      textSize(12);
      text(HLD, 300, 275);
      textSize(30);
      text(DISASTERPEACE, 300, 313);
    };
    
    void draw() {
    
      background(0);
    
      smooth();
    
    
      for (int i=0; i<40; i++)
      { 
        for (int j = 0; j < groove.bufferSize() - j; j++)
        {
    
          ellipse(X[i], X[i]+20+ groove.left.get(j)*50, z, z);
          ellipse(X[i]-20+ groove.left.get(j)*50, B[i], z, z);
          ellipse(B[i]+20 + groove.right.get(j)*50, B[i]-20 + groove.right.get(j)*50, z, z);
          line(X[i], X[i]+20+ groove.left.get(j)*50, X[i]-20+ groove.left.get(i)*50, B[i]);  
          line(X[i], X[i]+20 + groove.right.get(j)*50, B[i]+20 + groove.right.get(j)*50, B[i]-20 + groove.right.get(j)*50); 
          line(B[i]+20, B[i]-20, X[i]-20, B[i]);
        }
      }
      fill(255);
      textSize(12);
      text(HLD, 300, 275);
      textSize(30);
      text(DISASTERPEACE, 300, 313);
    };
    
  • @Spoll=== in order to show (as i dont know what you exactly want...)

        import ddf.minim.*;
        Minim minim;
        AudioPlayer groove;
        AudioInput in;
        float x, y, a, b, c, d, z;
        PFont police;
        PFont polisse;
        String DISASTERPEACE;
        String HLD;
        float[]X;
        float []B;
    
        void setup() { 
          size(600, 600);
          minim = new Minim(this);
          in = minim.getLineIn();
          //groove = minim.loadFile("groove.mp3", 1024);
          //groove.loop();
          background(0); 
          X = new float[40];
          B =new float [40];
          textAlign(CENTER);
          emissive(0, 26, 51);
        // police=createFont("drifter.ttf", 32);
        // polisse=createFont("DF.ttf", 25);
        //   textFont(police);
         HLD="Hyper Light Drifter";
          DISASTERPEACE="DISASTERPEACE";
          smooth();
          stroke(random(0, 255), random(0, 255), random(0, 255));
    
          for (int i=0; i<40; i++)
          { 
            fill(random(0, 255), random(0, 255), random(0, 255));
            ellipse(x, y, z, z);
            ellipse(a, b, z, z);
            ellipse(c, d, z, z);
            line(x, y, a, b);  
            line(x, y, c, d); 
            line(c, d, a, b);    
            x=random(0, 600);
            X[i] =x;
            y=x+20;
          a=x-20;
            b=random(0, 600);
            B[i] = b;
           c=b+20;
            d=b-20;
            z=3;
          }
          fill(255);
            textSize(12);
          text(HLD, 300, 275);
           textSize(30);
          text(DISASTERPEACE, 300, 313);
          //save("ESSAIS10.jpg");
        }
    
        void draw(){
          background(0);
          smooth();
    
    
    
          float lineing =  in.right.level()*5000;//this 5000 can be modified
    
             float lineind = in.left.level()*5000;// the same
    
        //these values can be mapped if needed
    
          stroke(random(0, 255), random(0, 255), random(0, 255));
    
          for (int i=0; i<40; i++)
          { 
            fill(random(0, 255), random(0, 255), random(0, 255));
            ellipse(X[i], X[i]+20+lineind, z, z);
            ellipse(X[i]-20+lineind, B[i], z, z);
            ellipse(B[i]+20+lineing, B[i]-20, z, z);
            line(X[i], X[i]+20+lineind, X[i]-20, B[i]);  
            line(X[i], X[i]+20+lineing, B[i]+20, B[i]-20); 
            line(B[i]+20, B[i]-20+lineing, X[i]-20, B[i]);    
    
    
    
    
    
    
          }
          fill(255);
            textSize(12);
          text(HLD, 300, 275);
           textSize(30);
          text(DISASTERPEACE, 300, 313);
          //save("ESSAIS10.jpg");
        }
    
  • edited December 2016

    @akenaton=== sorry if i can't make myself easily understandable

    well you see all the lines :

     line(X[i], X[i]+20+lineind, X[i]-20, B[i]);  
        line(X[i], X[i]+20+lineing, B[i]+20, B[i]-20); 
        line(B[i]+20, B[i]-20+lineing, X[i]-20, B[i]); 

    i just want them to act as the soundwave of the music

    like that

    as the song play, i would like them to vibrate with the music

    you know, something like that

  • edited January 2017 Answer ✓

    The example that you are giving at the bottom uses a standing wave concept for visualizing harmonics -- it looks like it achieves different heights at different fixed distances by adding together each harmonic measurement (Notice also that activity in your example is symmetrical).

    So that visualization is probably taking a measurement for the first, second, third, fourth harmonic etc., adding the values together, and drawing one line.

    Here are some related readings to help you understand the concepts. The implementation would be to generate measures for each frequency (harmonic), then render the visualization graph as the addition of multiple curves (each harmonic function).

Sign In or Register to comment.