Quantcast
Channel: Processing Forum
Viewing all 1768 articles
Browse latest View live

Porting GLGraphics Bloom example to Processing 2.0b0.7

$
0
0
Hi!

While I've started reading on GLSL again (third try, maybe this time it'll stick :) ), I do not yet know how it works internally...

For many of my sketches, I just used the beautiful bloom effect from the GLGraphics examples, and now I'm looking to port that to Processing 2.0.

While I've found one to one mappings between a lot of the old and new code, there's two calls that confuse me as to how I should re-write them for b0.7; the apply and filter calls in the snippet below:

  1. // Extracting the bright regions from input texture.
            extractBloom.set("bright_threshold", fx);
            extractBloom.apply(glg1, tex0);

            // Downsampling with blur.
            tex0.filter(blur, tex2);
            tex2.filter(blur, tex4);
            tex4.filter(blur, tex8);
            tex8.filter(blur, tex16);

            // Blending downsampled textures.
            blend4.apply(    new PGraphics[] { tex2, tex4, tex8, tex16 },
                            new PGraphics[] { bloomMask });

            // Final tone mapping into destination texture.
            toneMap.set("exposure", fy);
            toneMap.set("bright", fx);
           
            toneMap.apply(    new PGraphics[] { glg1, bloomMask },
                            new PGraphics[] { destTex });
Note I've here optimistically assumed that PGraphics can stand in for the old GLGraphics GLTexture class, and that PShader can straight-up replace the old GLTextureFilter :)

Seeing that low-lever OpenGL and GLSL is being revamped as we speak for the next release, maybe I'm asking too early... but if there are counterparts to the above calls for P 2.0b0.7 I'd sure love to know about them!

...Now off to reading about GLSL in my new book :D

Thanks!

[VIDEO] Problem displaying big panoramic video

$
0
0
Hi

I made a panoramic video (using PTGui pro), which generated a 5500 x 768 .mov file

When I try using this in a sketch, it loads fine (no errors being shown) but it just doesn't display anything.
Is there some resolution limitation? Problem with memory perhaps? I've already upped the setting to the max but alas.

I've also tried getting the quality down, lowering fps, and such.. Doesn't seem to be helping. The file I just tried was 15fps and 1.9 Gb big. Running 4gb ram on a macosx 10.6, latest processing version.

I'll be trying this on a pc later today but its pretty important that it works on mac.

Any ideas? Much appreciated

Webcam - Cube

$
0
0
Hey guys,
i have a big problem. I tried to create a cube whit the surface of the webcam-pictures. I want to click six times and every time the picture of the webcam will save in the folder, but the cube doesn´t connect to the pictures....:/

float drehen = 0.3;
import processing.video.*;
Capture myCapture;
PImage img7,img8,img9,img10,img11,img12;
Capture cam;


void setup() {
img7 = loadImage("image0.0.jpg");
img8 = loadImage("image2.0.jpg");
img9= loadImage("image3.0.jpg");
img10 = loadImage("image4.0.jpg");
img11 = loadImage ("image5.0.jpg");
img12 = loadImage("image6.0.jpg");


  rectMode(CENTER);
size(800, 800, P3D);
  background(255);

  //noStroke();          //uncomment this line to remove the stroke
  frameRate(10000);       // Set framerate
  smooth();            // Antialiasing
  myCapture = new Capture(this, 300,300);


  String[] cameras = Capture.list();
  
  if (cameras.length == 30) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 20; i < cameras.length; i++) {
      println(cameras[i]);
    }

    // The camera can be initialized directly using an 
    // element from the array returned by list():
    cam = new Capture(this,  160, 120);
    cam.start(); 

  }      
}

float saveincr;
void mousePressed() 
{
 saveincr++;
save("image"+saveincr+".jpg");

PImage img7,img8,img9,img10,img11,img12;
img7 = loadImage("image1.0.jpg");
img8 = loadImage("image1.0.jpg");
img9= loadImage("image1.0.jpg");
img10 = loadImage("image1.0.jpg");
img11 = loadImage ("image1.0.jpg");
img12 = loadImage("image1.0.jpg");
}

void draw() {

beginShape(); //definiere Polygon
texture(img7); //Screenshot on surface of the cube
vertex(300, 0, 0, 1, 0); 
vertex(300, 300, 0, 1, 1);
vertex(0, 300, 0, 0, 1); 
vertex(0, 0, 0, 0, 0); 
endShape();//End Polygons

beginShape();//define Polygon
texture(img8);//Screenshot on surface of the cube
vertex(300, 0, -300, 1, 0); 
vertex(300, 300, -300, 1, 1); 
vertex(0, 300, -300, 0, 1); 
vertex(0, 0, -300, 0, 0);
endShape(); //End Polygons

beginShape();//define Polygon
texture(img9); //Screenshot on surface of the cube
vertex(300, 0, -300, 1, 0); 
vertex(300, 300, -300, 1, 1); 
vertex(300, 300, 0, 0, 1); 
vertex(300, 0, 0, 0, 0); 
endShape(); //end Polygon 

beginShape(); //define Polygon
texture(img10); //Screenshot on surface of the cube
vertex(0, 0, 0, 1, 0); 
vertex(0, 300, 0, 1, 1); 
vertex(0, 300, -300, 0, 1); 
vertex(0, 0, -300, 0, 0);
endShape(); //End Polygons

beginShape(); //define Polygon
texture(img11); //Screenshot on surface of the cube
vertex(0, 0, 0, 1, 0); 
vertex(300, 0,0, 1, 1); 
vertex(300, 0, -300, 0, 1); 
vertex(0, 0, -300, 0, 0); 
endShape();//End Polygons

beginShape(); //define Polygon
texture(img12); //Screenshot on surface of the cube
vertex(300, 300, -300, 1, 0);
vertex(300, 300, 0, 1, 1); 
vertex(0, 300, 0, 0, 1); 
vertex(0, 300, -300, 0, 0); 
endShape();//End Polygons



  background(111);
  if (cam.available() == true) {
    cam.read();

  }
    image(cam,300, 300);
noFill();
translate(300,300);
rotate(radians(drehen),0,1,0);
drehen++;
box(300);
}

Re : Webcam - Cube

$
0
0
You want to map images onto a cube? Or do you want to map the webcam image onto it?

Please use the "Insert Code" button next time!

Re : Webcam - Cube

$
0
0
Oh sorry for that!
Well, i want to map the webcam images onto the cube, but it doesn´t work...:(

minim- extract all audio data from wav/mp3 at once

$
0
0
I'm trying to use processing to extract all the data from a wav or mp3 file at once.  similar to the getArray() method in minim, but I want to perform this on the entire audio file, not just the part loaded into the buffer.  This is not for a realtime audio application, so I'm not worried about speed, playback, or stuff like that, I just want to extract all the floats from the audio file into an array.
Is there something in minim or maybe some other library that can extract this data?
thanks in advance!
amanda

Re : Strange XML structrue after Facebook call.

$
0
0
Thanx PhiLho! that did it!

what is the difference here?

Re : [VIDEO] Problem displaying big panoramic video

$
0
0
There is a resolution limit in the compression codec.

For example H.264 is constrained to 4096×2048.

Try Theora. It's virtually limitless in terms of resolution and has wide multi-platform support.

It works with GSVideo so perhaps also Processing 2.0's video library.


Re : Strange XML structrue after Facebook call.

$
0
0
I don't have the 1.5 code at hand right now, but I think the difference is that the XMLElement constructor with a string isn't designed to parse an XML string...
IIRC, it is actually made to create a new single node with the given string as tag name.

Re : [VIDEO] Problem displaying big panoramic video

$
0
0
Thanks for the reply, I'll see where that takes me.

I kept on trying to solve it and I got it to work with the following setup:
Processing 1.5 , while specifying size(5500,768,P2D)

It runs on both mac and windows this way, but crashes with an outofmemory exception on windows after a while.
Mac throws some errors like
java(224,0xb8aff000) malloc: *** error for object 0x1722d0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
but luckily it keeps on running

Now, the problem is I need Processing 2.0 because I couldnt get Most Pixels Ever to work without it.
I'll let you know if Theora works!

issue about P3D

$
0
0
Hi! I`m new to processing.When i try to use the P3D mode i get this exceptions:
  1. java.lang.NoClassDefFoundError: javax/media/opengl/GLAutoDrawable
  2. at processing.opengl.PGraphicsOpenGL.<init>(PGraphicsOpenGL.java:519)
  3. at processing.opengl.PGraphics3D.<init>(PGraphics3D.java:37)
  4. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  5. at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
  6. at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  7. at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
  8. at processing.core.PApplet.makeGraphics(PApplet.java:1744)
  9. at processing.core.PApplet.size(PApplet.java:1596)
  10. at processing.core.PApplet.size(PApplet.java:1567)
  11. at my.test.drawer.setup(drawer.java:7)
  12. at processing.core.PApplet.handleDraw(PApplet.java:2117)
  13. at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:193)
  14. at processing.core.PApplet.run(PApplet.java:2020)
  15. at java.lang.Thread.run(Thread.java:722)
  16. Caused by: java.lang.ClassNotFoundException: javax.media.opengl.GLAutoDrawable
  17. at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
  18. at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  19. at java.security.AccessController.doPrivileged(Native Method)
  20. at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  21. at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
  22. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  23. at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
  24. ... 14 more
  25. Exception in thread "Animation Thread" java.lang.RuntimeException: javax/media/opengl/GLAutoDrawable
  26. at processing.core.PApplet.makeGraphics(PApplet.java:1769)
  27. at processing.core.PApplet.size(PApplet.java:1596)
  28. at processing.core.PApplet.size(PApplet.java:1567)
  29. at my.test.drawer.setup(drawer.java:7)
  30. at processing.core.PApplet.handleDraw(PApplet.java:2117)
  31. at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:193)
  32. at processing.core.PApplet.run(PApplet.java:2020)
  33. at java.lang.Thread.run(Thread.java:722)
Which jars i must import to make it work?When i import gluegen-rt-natives-linux-i586.jar and jogl-all-natives-linux-i586.jar i still get exceptions!Please help!

Using sound in processing?

$
0
0
So I'll admit I am a complete beginner when it comes to processing and the other day I was browsing some of the works on openprocessing.com and I came across an amazing program by Anton Pugh called Sound Waterfall (here is the link: http://openprocessing.org/sketch/46460) So I was wondering if it would be possible to somehow record myself playing my guitar and use that sound file in this program and have the program respond to the sound of my guitar instead of the song that playing.

Here's the code that I'm talking about
  1. /* Created by Anton Pugh */
     
    /* Music Visualizer that samples the short-time fft of a song and */
    /* plots the sampled points (|fft| => brightness of point).       */
     
    // Note: If your machine has OpenGL capabilities, uncomment the
    // following line and change 'P3D' to 'OPENGL' on line 34
    //import processing.opengl.*;
    import ddf.minim.analysis.*;
    import ddf.minim.*;
    //import fullscreen.*;
     
    /* MAX_SPOTS is the maximum number of points the sketch can plot  */
    /* NUM_ITERATIONS determines how often fft is sampled into points */
    /*   - Higher number => less often
    /*   - 1 == as often as possible
    /* SPEED determines how fast points rotate                        */
    int MAX_SPOTS = 1000000;
    int NUM_ITERATIONS = 1;
    float SPEED = 4;
     
    // Declare a new Minim object which will allow us to play and
    // analyze music. If you want to use the computer sound card
    // output, leave code as is, otherwise comment out the AudioInput
    // line and uncomment the AudioPlayer line. Additionally, you
    // will need to change how the sketch gets data, so look in
    // the setup loop for song = minim.loadFile
    Minim minim;
    //AudioInput song;
    AudioPlayer song;
    FFT fft;
    //SoftFullScreen fs;
     
    Spot[] spots = new Spot[MAX_SPOTS];
    int numSpots, index, colorSwitch;
    color spotColor, barCol1, barCol2;
    float band, rBar, gBar, bBar;
     
    void setup() {
      // Set size of window and rendering mode
      // Note: If your machine has OpenGL capabilities, change
      // 'P3D' to 'OPENGL' and uncomment the first line
      size(800, 500, P3D);
                            
      minim = new Minim(this);
      //fs = new SoftFullScreen(this);
       
      //fs.enter();
       
      //
      // MODIFY STRING TO CHANGE THE SONG THAT IS LOADED
      // (SONG MUST BE IN soundWaterfall/data/)
      song = minim.loadFile("annArborPart2.mp3", 512);
      song.loop();
      //song = minim.getLineIn(minim.MONO, 2048);
       
      fft = new FFT(song.bufferSize(), song.sampleRate());
      fft.window(FFT.HAMMING);
       
      numSpots = 0;
      barCol1 = color(0,0,128,255);
      barCol2 = color(0,0,128,150);
      index = 0;
      colorSwitch = 0;
      rBar = 0;
      gBar = 0;
      bBar = 0;
    }
     
    void draw() {
      smooth();
      background(0);
     
      fft.forward(song.mix);
      for(int i = 0; i < 150; i+=2) {
        // GET MAGNITUDE OF FFT AT BAND i
        band = fft.getBand(i);
        spotColor = color(0,0,min(100*band,255));
         
        // Draw a bar for FFT Band i as well as a reflection of the bar
        stroke(barCol1);
        strokeWeight(4);
        line(width/30 + 5*i, 23*height/26,-width/10, width/30 + 5*i, 23*height/26 - 5*band,-width/10);
        stroke(barCol2);
        strokeWeight(3);
        line(width/30 + 5*i, 93*height/104, -width/10, width/30 + 5*i - 2*band, 93*height/104 + 2*band, band/15 - width/10);
     
        // Make a spot if the magnitude of the band is big enough
        if((numSpots < MAX_SPOTS) && (index == NUM_ITERATIONS) && (band > 1)) {
          spots[numSpots] = new Spot(5  *width/61 + 5*i, max(2*height/7,103*height/168 - int(4*band)), spotColor);
          numSpots++;
        }
      }
       
      // RESET INDEX IF IT'S TIME TO GET ANOTHER FFT SAMPLE
      if(index == NUM_ITERATIONS) {
        index = 0;
      }
      else {
        index++;
      }
       
      // Update the color and position of all spots
      for(int i=0; i < numSpots; i++) {
        spots[i].update();
        if(index == NUM_ITERATIONS) {
          spots[i].colorChange();
          rBar += spots[i].r;
          gBar += spots[i].g;
          bBar += spots[i].b;
        }
      }
       
      // Update the color of the bars
      if(index == NUM_ITERATIONS) {
        rBar = rBar/(numSpots - 1);
        gBar = gBar/(numSpots - 1);
        bBar = bBar/(numSpots - 1);
        barCol1 = color(rBar,gBar,bBar,255);
        barCol2 = color(rBar,gBar,bBar,150);
        rBar = 0;
        gBar = 0;
        bBar = 0;
      }
       
      if(numSpots > 80000) {
        numSpots -= 500;
        for(int i=0; i < numSpots; i++) {
          spots[i] = spots[i+499];
        }
      }
    }
     
    void stop() {
      song.close();
      minim.stop();
       
      super.stop();
    }
     
    void mousePressed() {
      numSpots = 0;
    }
     
    class Spot {
      int x,y,z;
      color c;
      float r, g, b;
       
       
      Spot(int tempX, int tempY, color tempC) {
        c = tempC;
        x = tempX;
        y = tempY;
        z = width/15;
        r = red(tempC);
        g = green(tempC);
        b = blue(tempC);
      }
       
      void update() {
        z -= SPEED/2;
        y += SPEED/20;
         
        stroke(c);
        strokeWeight(1);
        point(x,y,z);
        //line(y,12*height/21,x,y,z,x);
      }
       
      void colorChange() {
        if(b > 0 && g == 0) {
          colorSwitch = 0;
        }
        else if(r > 0 && b == 0) {
          colorSwitch = 1;
        }
        else if(g > 0 && r == 0) {
          colorSwitch = 2;
        }
         
        if(colorSwitch == 0) {
          r++;
          b--;
        }
        else if(colorSwitch == 1) {
          g++;
          r--;
        }
        else if(colorSwitch == 2) {
          b++;
          g--;
        }
        c = color(r,g,b,255);
      }
    }

Re : Using sound in processing?

$
0
0
Yes, Anton was so kind to include the code for this already with comments //

I've made the required changes yellow in the adapted code below.

Some forum-related remarks. I've moved this thread to Core Library Questions because it uses Minim. You can post code in a more user-friendly manner as done below. Then it has line numbers and people can use the Copy Code button. For this and other information check out:
https://forum.processing.org/topic/where-to-place-threads-and-other-forum-practices

Adapted Code
  1. /* Created by Anton Pugh */
  2. /* Music Visualizer that samples the short-time fft of a song and */
  3. /* plots the sampled points (|fft| => brightness of point).       */
  4. // Note: If your machine has OpenGL capabilities, uncomment the
  5. // following line and change 'P3D' to 'OPENGL' on line 34
  6. //import processing.opengl.*;
  7. import ddf.minim.analysis.*;
  8. import ddf.minim.*;
  9. //import fullscreen.*;
  10. /* MAX_SPOTS is the maximum number of points the sketch can plot  */
  11. /* NUM_ITERATIONS determines how often fft is sampled into points */
  12. /*   - Higher number => less often
  13. /*   - 1 == as often as possible
  14. /* SPEED determines how fast points rotate                        */
  15. int MAX_SPOTS = 1000000;
  16. int NUM_ITERATIONS = 1;
  17. float SPEED = 4;
  18. // Declare a new Minim object which will allow us to play and
  19. // analyze music. If you want to use the computer sound card
  20. // output, leave code as is, otherwise comment out the AudioInput
  21. // line and uncomment the AudioPlayer line. Additionally, you
  22. // will need to change how the sketch gets data, so look in
  23. // the setup loop for song = minim.loadFile
  24. Minim minim;
  25. AudioInput song;
  26. //AudioPlayer song;
  27. FFT fft;
  28. //SoftFullScreen fs;
  29. Spot[] spots = new Spot[MAX_SPOTS];
  30. int numSpots, index, colorSwitch;
  31. color spotColor, barCol1, barCol2;
  32. float band, rBar, gBar, bBar;
  33. void setup() {
  34.   // Set size of window and rendering mode
  35.   // Note: If your machine has OpenGL capabilities, change
  36.   // 'P3D' to 'OPENGL' and uncomment the first line
  37.   size(800, 500, P3D);
  38.   minim = new Minim(this);
  39.   //fs = new SoftFullScreen(this);
  40.   //fs.enter();
  41.   //
  42.   // MODIFY STRING TO CHANGE THE SONG THAT IS LOADED
  43.   // (SONG MUST BE IN soundWaterfall/data/)
  44.   //song = minim.loadFile("annArborPart2.mp3", 512);
  45.   //song.loop();
  46.   song = minim.getLineIn(minim.MONO, 2048);
  47.   fft = new FFT(song.bufferSize(), song.sampleRate());
  48.   fft.window(FFT.HAMMING);
  49.   numSpots = 0;
  50.   barCol1 = color(0, 0, 128, 255);
  51.   barCol2 = color(0, 0, 128, 150);
  52.   index = 0;
  53.   colorSwitch = 0;
  54.   rBar = 0;
  55.   gBar = 0;
  56.   bBar = 0;
  57. }
  58. void draw() {
  59.   smooth();
  60.   background(0);
  61.   fft.forward(song.mix);
  62.   for (int i = 0; i < 150; i+=2) {
  63.     // GET MAGNITUDE OF FFT AT BAND i
  64.     band = fft.getBand(i);
  65.     spotColor = color(0, 0, min(100*band, 255));
  66.     // Draw a bar for FFT Band i as well as a reflection of the bar
  67.     stroke(barCol1);
  68.     strokeWeight(4);
  69.     line(width/30 + 5*i, 23*height/26, -width/10, width/30 + 5*i, 23*height/26 - 5*band, -width/10);
  70.     stroke(barCol2);
  71.     strokeWeight(3);
  72.     line(width/30 + 5*i, 93*height/104, -width/10, width/30 + 5*i - 2*band, 93*height/104 + 2*band, band/15 - width/10);
  73.     // Make a spot if the magnitude of the band is big enough
  74.     if ((numSpots < MAX_SPOTS) && (index == NUM_ITERATIONS) && (band > 1)) {
  75.       spots[numSpots] = new Spot(5  *width/61 + 5*i, max(2*height/7, 103*height/168 - int(4*band)), spotColor);
  76.       numSpots++;
  77.     }
  78.   }
  79.   // RESET INDEX IF IT'S TIME TO GET ANOTHER FFT SAMPLE
  80.   if (index == NUM_ITERATIONS) {
  81.     index = 0;
  82.   }
  83.   else {
  84.     index++;
  85.   }
  86.   // Update the color and position of all spots
  87.   for (int i=0; i < numSpots; i++) {
  88.     spots[i].update();
  89.     if (index == NUM_ITERATIONS) {
  90.       spots[i].colorChange();
  91.       rBar += spots[i].r;
  92.       gBar += spots[i].g;
  93.       bBar += spots[i].b;
  94.     }
  95.   }
  96.   // Update the color of the bars
  97.   if (index == NUM_ITERATIONS) {
  98.     rBar = rBar/(numSpots - 1);
  99.     gBar = gBar/(numSpots - 1);
  100.     bBar = bBar/(numSpots - 1);
  101.     barCol1 = color(rBar, gBar, bBar, 255);
  102.     barCol2 = color(rBar, gBar, bBar, 150);
  103.     rBar = 0;
  104.     gBar = 0;
  105.     bBar = 0;
  106.   }
  107.   if (numSpots > 80000) {
  108.     numSpots -= 500;
  109.     for (int i=0; i < numSpots; i++) {
  110.       spots[i] = spots[i+499];
  111.     }
  112.   }
  113. }
  114. void stop() {
  115.   song.close();
  116.   minim.stop();
  117.   super.stop();
  118. }
  119. void mousePressed() {
  120.   numSpots = 0;
  121. }
  122. class Spot {
  123.   int x, y, z;
  124.   color c;
  125.   float r, g, b;
  126.   Spot(int tempX, int tempY, color tempC) {
  127.     c = tempC;
  128.     x = tempX;
  129.     y = tempY;
  130.     z = width/15;
  131.     r = red(tempC);
  132.     g = green(tempC);
  133.     b = blue(tempC);
  134.   }
  135.   void update() {
  136.     z -= SPEED/2;
  137.     y += SPEED/20;
  138.     stroke(c);
  139.     strokeWeight(1);
  140.     point(x, y, z);
  141.     //line(y,12*height/21,x,y,z,x);
  142.   }
  143.   void colorChange() {
  144.     if (b > 0 && g == 0) {
  145.       colorSwitch = 0;
  146.     }
  147.     else if (r > 0 && b == 0) {
  148.       colorSwitch = 1;
  149.     }
  150.     else if (g > 0 && r == 0) {
  151.       colorSwitch = 2;
  152.     }
  153.     if (colorSwitch == 0) {
  154.       r++;
  155.       b--;
  156.     }
  157.     else if (colorSwitch == 1) {
  158.       g++;
  159.       r--;
  160.     }
  161.     else if (colorSwitch == 2) {
  162.       b++;
  163.       g--;
  164.     }
  165.     c = color(r, g, b, 255);
  166.   }
  167. }

Re : Using sound in processing?

$
0
0
Thank you for all the help amnon, however, even after commenting out the correct lines of coding, I can't seem to get the program to run in processing (the original program with the original sound file.) I am getting a NullPointerException error on line #44

Do you know whether it is possible or not to put minim and video together in one sketch?

$
0
0
well.. it's been about 4 months to learn   'Processing'

and I have to admit that I'm not good at understanding 'array' and 'class'

however, I wanted to mix video and audio effect so I has been trying to make a sketch for about a week but nothing left

actually, I has been referring and examining the 'mirror' and 'minim' from the example. 

so, finally I got an idea to  make it.

after making audio class, applied the class to the video sketch, however it didn't work.

so now I'm facing my limit... as designer    m,m

somebody help me!! 





Re : Using sound in processing?

$
0
0
The original code does it's thing based on an audio file.
The adapted code (as posted above) does it's thing based on real-time input.

Both codes work as-is. Please clarify what you want.

Do you want to use an audio file (code 1) or play in real-time (code 2).

Ad 1
If all you wanted was to play an audio file, then place your audio file in the /data subdirectory of the sketch. And make sure the name of your file and the loaded file in the code are equal in the line:
  1.   song = minim.loadFile("nameOfYourFile.mp3", 512);

Ad 2
Press Copy Code button, paste the code in Processing, press run.

Re : Do you know whether it is possible or not to put minim and video together in one sketch?

$
0
0
To answer the question in the title of your post: yes.

I can recommend the book Learning Processing by Daniel Shiffman if you want to learn more about arrays and classes. Of course there are also other books, see: http://processing.org/learning/books/

If you want help, I would advise you to include one or more of the following in your post:
  • Your code attempt.
  • The problem(s).
  • What you want to achieve.
  • Concrete questions.

XMLElement Problem in Processing 2.0b7

Re : Do you know whether it is possible or not to put minim and video together in one sketch?

$
0
0
Thank you for answering me !!  I didn't know how to make a question m.m 

Here is First code
-






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

Minim minim;
AudioInput voice;
FFT fft;
float volume;
float dampedVolume;
float daming = 0.005;
boolean debug = false;
float filtering = 100;
float volumeThreshold = 100;

void setup()
{
  size(512, 512);
  minim = new Minim(this);
  voice = minim.getLineIn(Minim.STEREO, 2048);
  fft = new FFT(voice.bufferSize(), voice.sampleRate());
  smooth();
}

void draw()
{
  background(0);
  stroke(255);
  fft.forward(voice.mix);
  volume = 0;
  for(int i = 0; i < filtering; i++){
    if(debug)  {line(i, height, i, height - fft.getBand(i)*4);}
    volume += fft.getBand(i);
  }
  volume *= 0.25;
  dampedVolume = dampedVolume + (volume - dampedVolume)*daming;

  
  ellipse(width/2, height/2, dampedVolume, dampedVolume);
}

void keyPressed() {
   if(key == 'a')  debug = !debug; 
}

void stop()
{
  voice.close();
  minim.stop();
  super.stop();
}









-
This code works!
and
with this code, I want to apply this code to every pixel on the video!
so I tried like this.
(Second trial  :  First code + 'Mirror' from the example)
-








Balloon [] balloons;

 
import processing.video.*;


int cellSize = 5;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;


void setup() {
  size(640, 480, P2D);
  frameRate(30);
  cols = width / cellSize;
  rows = height / cellSize;
  colorMode(RGB, 255, 255, 255, 100);

  // Uses the default video input, see the reference if this causes an error
  video = new Capture(this, width, height, 20);
  
  background(0);
  
  balloons = new Balloon [width*height/cellSize];
  for (int i = 0; i < balloons.length; i++) {
    balloons[i] = new Balloon((video.width - x - 1) + y*video.width;  );
  }
}
  



void draw() { 
  if (video.available()) {
    video.read();
    video.loadPixels();
    
    // Not bothering to clear background
    // background(0);
  
    // Begin loop for columns
    for (int i = 0; i < cols; i++) {
      // Begin loop for rows
      for (int j = 0; j < rows; j++) {
      
        // Where are we, pixel-wise?
        int x = i*cellSize;
        int y = j*cellSize;
        int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image
      
        float r = red(video.pixels[loc]);
        float g = green(video.pixels[loc]);
        float b = blue(video.pixels[loc]);
        // Make a new color with an alpha component
        color c = color(r, g, b, 75);
      
        // Code for drawing a single rect
        // Using translate in order for rotation to work properly
       
        rectMode(CENTER);
        fill(c);
        noStroke();
        // Rects are larger than the cell for some overlap
        rect(0, 0, cellSize+6, cellSize+6);
       
      }
    }
  }
    for(int i=0; i< 640/5 + 480/5; i++){
   balloon.drawdraw i;
}
}





class Balloon{
  
 
  import ddf.minim.*;
  import ddf.minim.analysis.*;

  Minim minim;
  AudioInput voice;
  FFT fft;
  float volume; 
  float dampedVolume;
  float daming = 0.005;
  boolean debug = false;
  float filtering = 100;
  float volumeThreshold = 100;
  int a;
  int b;
  
  
  
  Balloon (int xpos, int ypos){
    a = xpos;
    b = ypos;
  }
  

void setupsetup()
{
  minim = new Minim(this);
  voice = minim.getLineIn(Minim.STEREO, 2048);
  fft = new FFT(voice.bufferSize(), voice.sampleRate());
  smooth();
}

void drawdraw()
{
  noStroke();
  fft.forward(voice.mix);
  volume = 0;
  for(int i = 0; i < filtering; i++){
    volume += fft.getBand(i);
  }
  volume *= 0.25;
  dampedVolume = dampedVolume + (volume - dampedVolume)*daming;

  
  ellipse(a, b, dampedVolume, dampedVolume);
}


void stop()
{
  voice.close();
  minim.stop();
  super.stop();
}
}











It didn't work... even for me, It wasn't strange that this code doesn't work.

So, I decided to make a small step - Making just array with the First code.

like this

(third trial : just array the First code)

-











Balloon[] balloons;

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

  Minim minim;
  AudioInput voice;
  FFT fft;

void setup(){
  size(600,600);
  
  minim = new Minim(this);
  voice = minim.getLineIn(Minim.STEREO, 2048);
  fft = new FFT(voice.bufferSize(), voice.sampleRate());
  smooth();

}

void draw(){
  background(255);
  
  for(int i=0; i<balloons.length; i++){
    balloons[i].live(i*50,100);
  }
}


void stop()
{
  voice.close();
  minim.stop();
  super.stop();
}
  
  



class Balloon{


float volume;
float dampedVolume;
float daming = 0.005;
float filtering = 100;
float volumeThreshold = 100;


void live(int a,int b)
{
  
  fft.forward(voice.mix);
  volume = 0;
  for(int i = 0; i < filtering; i++){
    
    volume += fft.getBand(i);
  }
  volume *= 0.25;
  dampedVolume = dampedVolume + (volume - dampedVolume)*daming;

  ellipse(a, b, dampedVolume, dampedVolume);
}




}












the outcome was just full gray box...
with this message :    NullPointerException


well... my Final goal was to mix the first code with video(Mirror)code.
however, now I just want to know how to array the minim code,
and If possible, how to apply the First code to pixel in the picture(PImage).

Please...
 Masters help... m





issue with integer division of zero padded integers

$
0
0
Processing 2.0b6 on Linux Ubuntu 12.04

While
println(3456/10);
gives : 345

println(03456/10);
answers : 183

and the same with :
println(003456/10); ->183
and
println(0003456/10); ->183

and same problem with integer numerator and float denominator:
println(03456/10.0); ->183.8

while 0 padded float division seams OK :
println(03456.0/10.0); -> 345.6

Even stranger with
println(08765/10);
giving following error:
unexpected token: 8765

Any reason for this amazing behavior ?
Viewing all 1768 articles
Browse latest View live