We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey! I'm need help for my project. I'm on a windows and using a kinect v1. The purpose of this is trigger a sound everytime a RightHand or a Left Hand touch the ellipses. and that part is functional, but i can't add more sounds (i only have 2) with a error: "IllegalArgument Exception: unsuported bit depth, use either 8 or 16".
I'm gonna share the code and any help is welcome. Thanks :)
float theta1;
float theta2;
float yval;
float xval;
float raio = 50;
float fila1 = 300;
float fila2 = 600;
float valA = 150;
float valB = 300;
float valC = 450;
import ddf.minim.*;
Minim minim;
AudioSample player;
AudioInput in;
AudioRecorder recorder;
import SimpleOpenNI.*;
SimpleOpenNI context;
color[] userClr = new color[]{ color(random(255), random(255), random(255)),
color(random(255), random(255), random(255)),
color(random(255), random(255), random(255)),
color(random(255), random(255), random(255)),
color(random(255), random(255), random(255))
};
//PVector com = new PVector();
//PVector com2d = new PVector();
void setup()
{
size(960,540);
context = new SimpleOpenNI(this);
context.setMirror(true);
context.enableDepth();
context.enableUser();
background(255,255,255);
stroke(0,255,0);
strokeWeight(5);
smooth();
}
void draw()
{
context.update();
background(255,255,255);
textSize(20);
// se eu passar as elipses para baixo, elas só aparecem quando aparece o esqueleto... Posso colocar aqui o titulo do setup (que vai ficar sempre....
ellipse(fila1,valA,raio,raio); // bola 1
ellipse(fila1,valB,raio,raio); // bola 2
ellipse(fila1,valC,raio,raio); // bola 3
ellipse(fila2,valA,raio,raio); // bola 4
ellipse(fila2,valB,raio,raio); // bola 5
ellipse(fila2,valC,raio,raio); // bola 6
// draw the skeleton if it's available
int[] userList = context.getUsers();
for(int i=0;i<userList.length;i++)
{
if(context.isTrackingSkeleton(userList[i]))
{
stroke(userClr[ (userList[i] - 1) % userClr.length ] );
drawSkeleton(userList[i]);
}
}
}
// draw the skeleton with the selected joints
void drawSkeleton(int userId)
{
// to get the 3d joint data
/*
PVector jointPos = new PVector();
context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_NECK,jointPos);
println(jointPos);
*/
PVector torso = new PVector();
context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_TORSO,torso);
PVector convertedTorso = new PVector();
context.convertRealWorldToProjective(torso, convertedTorso);
PVector rightHand = new PVector();
context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_LEFT_HAND,rightHand);
PVector convertedRightHand = new PVector();
context.convertRealWorldToProjective(rightHand, convertedRightHand);
//float rightEllipseSize = map(convertedRightHand.z, 700, 2500, 50, 1);
ellipse(convertedRightHand.x, convertedRightHand.y, 10, 10);
//text("hand: " + convertedRightHand.x + " " + convertedRightHand.y, 10, 50);
// yval = -(convertedRightHand.y-height/2);
xval = (convertedRightHand.x-convertedTorso.x);
//yval = map(convertedRightHand.y,0,height,1,-1);
//xval = map(convertedRightHand.x,0,width,1,-1);
// if (xval>=0){
// theta1 = acos(yval/sqrt(sq(xval)+sq(yval)));
// }
// else{
// theta1 = -acos(yval/sqrt(sq(xval)+sq(yval)));
// }
theta1 = PVector.angleBetween(new PVector(convertedRightHand.x-convertedTorso.x,convertedRightHand.y-convertedTorso.y,0.0),new PVector(0,convertedTorso.y-height,0.0));
if (xval<0){
theta1*= -1;
}
PVector leftHand = new PVector();
context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_RIGHT_HAND,leftHand);
PVector convertedLeftHand = new PVector();
context.convertRealWorldToProjective(leftHand, convertedLeftHand);
//float leftEllipseSize = map(convertedLeftHand.z, 700, 2500, 50, 1);
ellipse(convertedLeftHand.x, convertedLeftHand.y, 10, 10);
//yval = -(convertedLeftHand.y-height/2);
xval = (convertedLeftHand.x-convertedTorso.x);
//yval = map(convertedLeftHand.y,0,height,1,-1);
//xval = map(convertedLeftHand.x,0,width,1,-1);
theta2 = PVector.angleBetween(new PVector(convertedLeftHand.x-convertedTorso.x,convertedLeftHand.y-convertedTorso.y,0.0),new PVector(0,convertedTorso.y-height,0.0));
if (xval<0){
theta2*= -1;
}
PVector head = new PVector();
context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_HEAD,head);
PVector convertedHead = new PVector();
context.convertRealWorldToProjective(head, convertedHead);
ellipse(convertedHead.x, convertedHead.y, 60, 60);
fill(random(255), random(255), random(255));
PVector leftFoot = new PVector();
context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_RIGHT_FOOT,leftFoot);
PVector convertedLeftFoot = new PVector();
context.convertRealWorldToProjective(leftFoot, convertedLeftFoot);
ellipse(convertedLeftFoot.x, convertedLeftFoot.y, 10, 10);
PVector rightFoot = new PVector();
context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_LEFT_FOOT,rightFoot);
PVector convertedRightFoot = new PVector();
context.convertRealWorldToProjective(rightFoot, convertedRightFoot);
ellipse(convertedRightFoot.x, convertedRightFoot.y, 10, 10);
context.drawLimb(userId, SimpleOpenNI.SKEL_HEAD, SimpleOpenNI.SKEL_NECK);
context.drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_LEFT_SHOULDER);
context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_LEFT_ELBOW);
context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_ELBOW, SimpleOpenNI.SKEL_LEFT_HAND);
context.drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_RIGHT_SHOULDER);
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_RIGHT_ELBOW);
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW, SimpleOpenNI.SKEL_RIGHT_HAND);
context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_TORSO);
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_TORSO);
context.drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_LEFT_HIP);
context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HIP, SimpleOpenNI.SKEL_LEFT_KNEE);
context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_KNEE, SimpleOpenNI.SKEL_LEFT_FOOT);
context.drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_RIGHT_HIP);
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, SimpleOpenNI.SKEL_RIGHT_KNEE);
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_KNEE, SimpleOpenNI.SKEL_RIGHT_FOOT);
// mão esquerda toca na bola 1
if(getDistancia(convertedRightHand.x,convertedRightHand.y,fila1,valA)<raio){
println("Tocaste-me" + convertedRightHand.y);
minim = new Minim(this);
player = minim.loadSample("02.wav", 500);
player.trigger();
}
// mão esquerda toca na bola 2
if(getDistancia(convertedRightHand.x,convertedRightHand.y,fila1,valB)<raio){
println("LINDO" + convertedRightHand.y);
minim = new Minim(this);
player = minim.loadSample("01.wav", 500);
player.trigger();
}
// mão esquerda toca na bola 3
if(getDistancia(convertedRightHand.x,convertedRightHand.y,fila1,valC)<raio){
println("OPA" + convertedRightHand.y);
minim = new Minim(this);
in = minim.getLineIn(Minim.STEREO,896);
player = minim.loadSample("78.wav", 500);
player.trigger();
}
// mão esquerda toca na bola 4
if(getDistancia(convertedRightHand.x,convertedRightHand.y,fila2,valA)<raio){
println("Tocaste-me AGAIN" + convertedRightHand.y);
}
// mão esquerda toca na bola 5
if(getDistancia(convertedRightHand.x,convertedRightHand.y,fila2,valB)<raio){
println("LINDO AGAIN" + convertedRightHand.y);
}
// mão esquerda toca na bola 6
if(getDistancia(convertedRightHand.x,convertedRightHand.y,fila2,valC)<raio){
println("OPA AGAIN" + convertedRightHand.y);
}
// mão direita toca na bola 1
if(getDistancia(convertedLeftHand.x,convertedLeftHand.y,fila1,valA)<raio){
println("DIR TOCOU" + convertedLeftHand.y);
}
// mão direita toca na bola 2
if(getDistancia(convertedLeftHand.x,convertedLeftHand.y,fila1,valB)<raio){
println("Tocou 2x" + convertedLeftHand.y);
}
// mão direita toca na bola 3
if(getDistancia(convertedLeftHand.x,convertedLeftHand.y,fila1,valC)<raio){
println("E consegiu 3" + convertedLeftHand.y);
}
// mão direita toca na bola 4
if(getDistancia(convertedLeftHand.x,convertedLeftHand.y,fila2,valA)<raio){
println("DIR TOCOU AGAIN" + convertedLeftHand.y);
}
// mão direita toca na bola 5
if(getDistancia(convertedLeftHand.x,convertedLeftHand.y,fila2,valB)<raio){
println("Tocou 2x AGAIN" + convertedLeftHand.y);
}
// mão direita toca na bola 6
if(getDistancia(convertedLeftHand.x,convertedLeftHand.y,fila2,valC)<raio){
println("E consegiu 3 AGAIN" + convertedLeftHand.y);
}
// Pé ESQ toca na bola 1
if(getDistancia(convertedRightFoot.x,convertedRightFoot.y,fila1,valA)<raio){
println("Tocaste-me com o pé" + convertedRightFoot.y);
}
// Pé ESQ toca na bola 2
if(getDistancia(convertedRightFoot.x,convertedRightFoot.y,fila1,valB)<raio){
println("LINDO com o pé" + convertedRightFoot.y);
}
// Pé ESQ toca na bola 3
if(getDistancia(convertedRightFoot.x,convertedRightFoot.y,fila1,valC)<raio){
println("OPA com o pé" + convertedRightFoot.y);
}
// pé ESQ toca na bola 4
if(getDistancia(convertedRightFoot.x,convertedRightFoot.y,fila2,valA)<raio){
println("Tocaste-me AGAIN com o pé" + convertedRightFoot.y);
}
// Pé ESQ toca na bola 5
if(getDistancia(convertedRightFoot.x,convertedRightFoot.y,fila2,valB)<raio){
println("LINDO AGAIN com o pé" + convertedRightFoot.y);
}
// Pé ESQ toca na bola 6
if(getDistancia(convertedRightFoot.x,convertedRightFoot.y,fila2,valC)<raio){
println("OPA AGAIN com o pé" + convertedRightFoot.y);
}
// Pé DIR toca na bola 1
if(getDistancia(convertedLeftFoot.x,convertedLeftFoot.y,fila1,valA)<raio){
println("Tocaste-me com a PATA" + convertedLeftFoot.y);
}
// Pé DIR toca na bola 2
if(getDistancia(convertedLeftFoot.x,convertedLeftFoot.y,fila1,valB)<raio){
println("LINDO com a PATA" + convertedLeftFoot.y);
}
// Pé DIR toca na bola 3
if(getDistancia(convertedLeftFoot.x,convertedLeftFoot.y,fila1,valC)<raio){
println("OPA com a PATA" + convertedLeftFoot.y);
}
// pé DIR toca na bola 4
if(getDistancia(convertedLeftFoot.x,convertedLeftFoot.y,fila2,valA)<raio){
println("Tocaste-me AGAIN com a PATA" + convertedLeftFoot.y);
}
// Pé DIR toca na bola 5
if(getDistancia(convertedLeftFoot.x,convertedLeftFoot.y,fila2,valB)<raio){
println("LINDO AGAIN com a PATA" + convertedLeftFoot.y);
}
// Pé DIR toca na bola 6
if(getDistancia(convertedLeftFoot.x,convertedLeftFoot.y,fila2,valC)<raio){
println("OPA AGAIN com a PATA" + convertedLeftFoot.y);
}
// CABEÇA toca na bola 1
if(getDistancia(convertedHead.x,convertedHead.y,fila1,valA)<raio){
println("Tocaste-me na cabeça" + convertedHead.y);
}
// CABEÇA toca na bola 2
if(getDistancia(convertedHead.x,convertedHead.y,fila1,valB)<raio){
println("LINDO na cabeça" + convertedHead.y);
}
// CABEÇA toca na bola 4
if(getDistancia(convertedHead.x,convertedHead.y,fila2,valA)<raio){
println("Tocaste-me na cabeça... Não posso" + convertedHead.y);
}
// CABEÇA toca na bola 5
if(getDistancia(convertedHead.x,convertedHead.y,fila2,valB)<raio){
println("LINDO na cabeça... Não posso" + convertedHead.y);
}
// CABEÇA toca na bola 6
if(getDistancia(convertedHead.x,convertedHead.y,fila2,valC)<raio){
println("OPA na cabeça... Não posso" + convertedHead.y);
}
// CABEÇA toca na bola 3
if(getDistancia(convertedHead.x,convertedHead.y,fila1,valC)<raio){
println("OPA na cabeça... Não posso" + convertedHead.y);
}
translate(convertedTorso.x+320, height);
stroke(0);
}
float getDistancia(float x1, float y1, float x0, float y0){
return sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0));
}
// -----------------------------------------------------------------
// SimpleOpenNI events
void onNewUser(SimpleOpenNI curContext, int userId)
{
println("onNewUser - userId: " + userId);
println("\tstart tracking skeleton");
curContext.startTrackingSkeleton(userId);
}
void onLostUser(SimpleOpenNI curContext, int userId)
{
println("onLostUser - userId: " + userId);
}
void onVisibleUser(SimpleOpenNI curContext, int userId)
{
//println("onVisibleUser - userId: " + userId);
}
void stop() {
//out.close();
//minim.stop();
//kick.close();
//snare.close();
// hat.close();
//crash.close();
//player.close();
super.stop();
}