Looping audio files with Minim

Hi there,

I'm working on a complex project where a kinect is suspended from the ceiling and picks up objects placed on a base on a table. Depending on the height reading the kinect reads, it plays different sounds. I'm only missing something small and thats how you loop the tracks seem as they're 40secs each but need to play over and over. Heres my code

//import openkinect library
 import org.openkinect.*;
 import org.openkinect.processing.*;

 import ddf.minim.*;

Minim minim;

//A1
AudioPlayer player_01;
AudioPlayer player_02;
AudioPlayer player_03;
AudioPlayer player_04;

//B1
AudioPlayer player_05;
AudioPlayer player_06;
AudioPlayer player_07;
AudioPlayer player_08;

//C1
AudioPlayer player_09;
AudioPlayer player_10;
AudioPlayer player_11;
AudioPlayer player_12;

//D1
AudioPlayer player_13;
AudioPlayer player_14;
AudioPlayer player_15;
AudioPlayer player_16;

// Kinect Library object
Kinect kinect;
boolean rgb = true;
boolean depth = false;
boolean ir = false;

//rotate
float angle;

//font
PFont f;

// Declare variable 'a' of type float
float a = 0;

// Size of kinect image
int w = 640;
int h = 480;

// Calling the grid refs
int a1,b1,c1,d1;

// We'll use a lookup table so that we don't have to repeat the math over and over
float[] depthLookUp = new float[2048];

// Start at 0 degrees
float deg = 0; 

//set up  
void setup() {
  size(1280,480,P3D);

  // Create the font
  //println(PFont.list());
  f = createFont("Georgia", 18);
  textFont(f);

//set up kinect for sketch
  kinect = new Kinect(this);
  kinect.start();
  kinect.enableDepth(true);
  // We don't need the grayscale image in this example
  // so this makes it more efficient
  kinect.processDepthImage(false);
  kinect.enableRGB(rgb);
  kinect.enableIR(ir);

  // tilt ability
  kinect.tilt(deg);

  // Lookup table for all possible depth values (0 - 2047)
  for (int i = 0; i < depthLookUp.length; i++) {
  depthLookUp[i] = rawDepthToMeters(i);
  }

  // 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.

  // SAJ - South American Jungle
  player_01 = minim.loadFile("saj1.mp3");
  player_02 = minim.loadFile("saj2.mp3");
  player_03 = minim.loadFile("saj3.mp3");
  player_04 = minim.loadFile("saj4.mp3");

  // SEA - South East Asia
  player_05 = minim.loadFile("sea1.mp3");
  player_06 = minim.loadFile("sea2.mp3");
  player_07 = minim.loadFile("sea3.mp3");
  player_08 = minim.loadFile("sea4.mp3");

  // SA - South Africa
  player_09 = minim.loadFile("sa1.mp3");
  player_10 = minim.loadFile("sa2.mp3");
  player_11 = minim.loadFile("sa3.mp3");
  player_12 = minim.loadFile("sa4.mp3");

  // IRE - Ireland (South Pres Cork)
  player_13 = minim.loadFile("ire1.mp3");
  player_14 = minim.loadFile("ire2.mp3");
  player_15 = minim.loadFile("ire3.mp3");
  player_16 = minim.loadFile("ire4.mp3");

  }

//draw
void draw() {

  background(0);
  fill(255);
  textMode(SCREEN);
  text("Kinect FR: " + (int)kinect.getDepthFPS() + "\nProcessing FR: " + (int)frameRate,10,16);
  image(kinect.getVideoImage(),0,0);
  // Get the raw depth as array of integers
  int[] depth = kinect.getRawDepth();
  String test = "";

  //draw lines at these intervals
  int skipx = 24;
  int skipy = 24;

    for(int x=225; x<w-327; x+=skipx) {
    for(int y=185; y<h-233; y+=skipy) {

      //central reading point per grid space
      int offset = (x+12)+(y)*w;

      // Convert kinect data to world xyz coordinate
      int rawDepth = depth[offset];
      PVector v = depthToWorld(x,y,rawDepth);

      stroke(255);
      // pushMatrix();
      // Scale up by 200
      float factor = 50;
      //translate(v.x*factor,v.y*factor,factor-v.z*factor);
      ////println(x + " " + y + " " + v.x*factor + " " + v.y*factor + " " + v.z*factor);

      //z = distance from kinect
      //println(int(v.z*factor));
      stroke(255);
      fill(v.z*factor,v.z*factor,v.z*factor,200);
      rect(x, y, skipx, skipy);

      // Draw a point
     //point(0,0);
    //popMatrix();


  //A1-D1 GRID IF STATEMENTS     
      //A1   
      if (x==225&&y==185) {
      a1=int(v.z*factor);
      println("a1 = " + a1);
         if (a1==73){player_01.play();}
         if (a1==68){player_02.play();}
         if (a1==63){player_03.play();}
         if (a1==58){player_04.play();}
     }

     //B1
     if (x==249&&y==185) {
     b1=int(v.z*factor);
     println("b1 = " + b1);
         if (b1==73){player_05.play();}
         if (b1==68){player_06.play();}
         if (b1==63){player_07.play();}
         if (b1==58){player_08.play();}
     }

 //C1
       if (x==273&&y==185) {
       c1=int(v.z*factor);
       println("c1 = " + c1);
         if (c1==73){player_09.play();}
         if (c1==68){player_10.play();}
         if (c1==63){player_11.play();}
         if (c1==58){player_12.play();}
     }

 //D1
       if (x==297&&y==185) {
       d1=int(v.z*factor);
       println("d1 = " + d1);
         if (d1==73){player_13.play();}
         if (d1==68){player_14.play();}
         if (d1==63){player_15.play();}
         if (d1==58){player_16.play();}
     }


  }

  // Rotate
  a += 0.015f;

  }
 }


// These functions come from: http://graphics.stanford.edu/~mdfisher/Kinect.html
float rawDepthToMeters(int depthValue) {
  if (depthValue < 2047) {
    return (float)(1.0 / ((double)(depthValue) * -0.0030711016 + 3.3309495161));
  }
  return 0.0f;
}

PVector depthToWorld(int x, int y, int depthValue) {

  final double fx_d = 1.0 / 5.9421434211923247e+02;
  final double fy_d = 1.0 / 5.9104053696870778e+02;
  final double cx_d = 3.3930780975300314e+02;
  final double cy_d = 2.4273913761751615e+02;

  PVector result = new PVector();
  double depth =  depthLookUp[depthValue]; rawDepthToMeters(depthValue);
  result.x = (float)((x - cx_d) * depth * fx_d);
  result.y = (float)((y - cy_d) * depth * fy_d);
  result.z = (float)(depth);
  return result;
}


//tilt ability by pressing up/down keys
void keyPressed() {
  if (key == 'd') {
    depth = !depth;
    kinect.enableDepth(depth);
  }
  else if (key == 'r') {
    rgb = !rgb;
    if (rgb) ir = false;
    kinect.enableRGB(rgb);
  }
  else if (key == 'i') {
    ir = !ir;
    if (ir) rgb = false;
    kinect.enableIR(ir);
  } 
}

// STOP
public void stop() 
{

  kinect.quit();

  // always close Minim audio classes when you are done with them
  player_01.close();
  player_02.close();
  player_03.close();
  player_04.close();

  player_05.close();
  player_06.close();
  player_07.close();
  player_08.close();

  player_09.close();
  player_10.close();
  player_11.close();
  player_12.close();

  player_13.close();
  player_14.close();
  player_15.close();
  player_16.close();

  super.stop();

}
Tagged:

Answers

  • in Setup

    add Each of your Audio Player names as follows

    player_01.loop();

    Should work Good luck :)

Sign In or Register to comment.