Problem triggering audio files with kinect!
in
Integration and Hardware
•
2 years ago
Hello!
Okay... having major struggles with this
I am triggering sounds with motion on kinect. The first problem was it using AudioSample which triggered the sound over and over again and didnt stop.
I changed to AudioSnippet which triggered the sound just once, but then would not trigger again.
When using the rewind, play functions does not help (repeats over and over again)...
I then slowed the frameRate down to 0.5 with the rewind and play functions, which gives me the result I want, but the animation slows right down and couldnt find a way to seperate frame rates for sounds and animation
I am new to Processing so im in struggle street, any help will be greatly appreciated..
My Code:
Okay... having major struggles with this
I am triggering sounds with motion on kinect. The first problem was it using AudioSample which triggered the sound over and over again and didnt stop.
I changed to AudioSnippet which triggered the sound just once, but then would not trigger again.
When using the rewind, play functions does not help (repeats over and over again)...
I then slowed the frameRate down to 0.5 with the rewind and play functions, which gives me the result I want, but the animation slows right down and couldnt find a way to seperate frame rates for sounds and animation
I am new to Processing so im in struggle street, any help will be greatly appreciated..
My Code:
import org.openkinect.*;
import org.openkinect.processing.*;
import hypermedia.video.*;
import ddf.minim.*;
import ddf.minim.signals.*;
import javax.sound.sampled.*;
Kinect kinect;
OpenCV opencv;
// Showing how we can farm all the kinect stuff out to a separate class
KinectTracker tracker;
int numFrames = 7; // Number of frames for full animation
int frame = 0;
PImage[] images = new PImage[numFrames];
int numFramesThree = 103; // Number of frames for full animation
int frameThree = 0;
PImage[] imagesThree = new PImage[numFramesThree];
int numFramesHat = 11; // Number of frames for full animation
int frameHat = 0;
PImage[] imagesHat = new PImage[numFramesHat];
int numFramesBhat = 11; // Number of frames for full animation
int frameBhat = 0;
PImage[] imagesBhat = new PImage[numFramesHat];
int numFramesTap = 41; // Number of frames for full animation
int frameTap = 0;
PImage[] imagesTap = new PImage[numFramesTap];
int numFramesKick = 23; // Number of frames for full animation
int frameKick = 0;
PImage[] imagesKick = new PImage[numFramesKick];
// code ref: Minim example - trigger
Minim minim; // Load in sounds/music
AudioSample wave;
AudioSnippet woo;
AudioSnippet scratch;
AudioSnippet mjsong;
AudioSnippet tah;
AudioSnippet eheh;
AudioSnippet yow;
SineWave sine;
PImage thirteen;
void setup() {
size(640, 480, P2D);
frameRate(10);
kinect = new Kinect(this);
kinect.start();
kinect.enableDepth(true);
tracker = new KinectTracker();
opencv = new OpenCV(this);
opencv.allocate(width, height);
minim = new Minim(this);
sine = new SineWave (220,
0.5,
44100);
float[] samples = new float[1024*8];
woo = minim.loadSnippet("woo01.mp3"); // Load in sounds/music
scratch = minim.loadSnippet("scratch.mp3");
mjsong = minim.loadSnippet("billyb.mp3");
tah = minim.loadSnippet("tah.mp3");
eheh = minim.loadSnippet("eheh.mp3");
yow = minim.loadSnippet("yow.mp3");
sine.generate(samples);
AudioFormat format = new AudioFormat (44100,
16,
1,
true,
true);
wave = minim.createSample (samples,
format,
1024);
thirteen = loadImage("13.jpg");
for(int i=0; i<numFrames; i++) { // Code for animation
String imageName = "da_" + nf(i, 2) + ".jpg";
images[i] = loadImage(imageName);
}
for(int i=0; i<numFramesThree; i++) { // Code for animation
String imageName = "mw_" + nf(i, 3) + ".jpg";
imagesThree[i] = loadImage(imageName);
}
for(int i=0; i<numFramesHat; i++) { // Code for animation
String imageName = "hat_" + nf(i, 2) + ".jpg";
imagesHat[i] = loadImage(imageName);
}
for(int i=0; i<numFramesBhat; i++) { // Code for animation
String imageName = "bhat_" + nf(i, 2) + ".jpg";
imagesBhat[i] = loadImage(imageName);
}
for(int i=0; i<numFramesTap; i++) { // Code for animation
String imageName = "tap_" + nf(i, 2) + ".jpg";
imagesTap[i] = loadImage(imageName);
}
for(int i=0; i<numFramesKick; i++) { // Code for animation
String imageName = "kick_" + nf(i, 2) + ".jpg";
imagesKick[i] = loadImage(imageName);
}
}
void draw() {
{frame = (frame+1) % numFrames;}
{frameThree = (frameThree+1) % numFramesThree;}
{frameHat = (frameHat+1) % numFramesHat;}
{frameBhat = (frameBhat+1) % numFramesBhat;}
{frameTap = (frameTap+1) % numFramesTap;}
{frameKick = (frameKick+1) % numFramesKick;}
opencv.copy(kinect.getDepthImage());
// image(opencv.image(), 0, 0);
// code ref: Kinect example - Blob detection
// opencv.threshold(180);
// Run the tracking analysis
tracker.track();
// Show the image
// tracker.display();
// code ref: Kinect example - Blob detection
Blob[] blobs = opencv.blobs(10, width*height/2, 100, true);
// fill(255, 200, 0);
// Let's draw the raw location
PVector v1 = tracker.getPos();
// Let's draw the "lerped" location
PVector v2 = tracker.getLerpedPos();
for( int i = 0; i < blobs.length; i++) {
// beginShape();
{image(imagesThree[frameThree], 0, 0); }
// code ref: Lynneal Santos
//left
if ((v1.x > 0) && (v1.x < width/3) &&
(v1.y > height/3) && (v1.y < (2*height)/3))
{image(imagesKick[frameKick], 0, 0);}
// left - trigger 'woo'
if ((v1.x > 0) && (v1.x < width/3) &&
(v1.y > height/3) && (v1.y < (2*height)/3))
{ mjsong.play();
}
//right
if ((v1.x > (2*width)/3) && (v1.x < width) &&
(v1.y > height/3) && (v1.y < (2*height)/3))
{image(images[frame], 0, 0);}
//right - trigger 'yow
if ((v1.x > (2*width)/3) && (v1.x < width) &&
(v1.y > height/3) && (v1.y < (2*height)/3))
{
yow.play();
yow.rewind();
}
// top
if ((v1.x > width/3) && (v1.x < (2*width)/3) &&
(v1.y > 0) && (v1.y < height/3))
{image(imagesHat[frameHat], 0, 0);}
// topleft
if ((mouseX > 0) && (mouseX < width/3) &&
(mouseY > 0) && (mouseY < height/3))
{image(imagesBhat[frameBhat], 0, 0);}
// bottom
if ((v1.x > width/3) && (v1.x < (2*width)/3) &&
(v1.y > (2*height)/3) && (v1.y < height))
{image(imagesTap[frameTap], 0, 0);}
for(int j = 0; j < blobs[i].points.length; j++) {
vertex(blobs[i].points[j].x, blobs[i].points[j].y);
}
}
}
void stop()
{
// code ref: Minim example - trigger
wave.close();
mjsong.close();
yow.close();
minim.stop();
super.stop();
}
1