Play more than one Audio sample in Processing

180px-Processing_Logo_Clipped.svg

While trying to play more than one audio sample in processing you may get a error like this…

==== JavaSound Minim Error ====
==== Couldn't open the line: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.

==== JavaSound Minim Error ====
==== Unable to return a SourceDataLine: unsupported format - PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian

Screenshot from 2013-05-10 12:52:19

To fix this error

sudo cp /usr/lib/jvm/java-6-openjdk/jre/lib/i386/libpulse-java.so ~/Desktop/processing-1.5.1/java/lib/i386/
sudo cp /usr/lib/jvm/java-6-openjdk/jre/lib/ext/pulse-java.jar ~/Desktop/processing-1.5.1/java/lib/ext/
sudo cp /etc/java-6-openjdk/sound.properties ~/Desktop/processing-1.5.1/java/lib/

Now try to play usually the problem may get fixed by this..but if the problem persists then its an ownership problem since pulse-java.jar and libpulse-java.so were owned by root.Then do these steps

sudo chown MYUSR:MYUSR ~/Desktop/processing-1.5.1/java/lib/ext/pulse-java.jar
sudo chown MYUSR:MYUSR ~/Desktop/processing-1.5.1/java/lib/i386/libpulse-java.so
chmod +x ~/Desktop/processing-1.5.1/java/lib/i386/libpulse-java.so

replace MYUSR with your current Linux user name.

Substitute ~/Desktop/processing-1.5.1/ with the path were you installed Processing
This will solve the issue happy hacking 🙂

Proocessing to Arduino commnication

The following code describes how processing to arduino serial communication can be done…processing to arduino communication is very helpful when kinect is used along with processing..

Processing code

import processing.serial.*;
Serial port;

void setup() {
size(256, 150);

println("Available serial ports:");
println(Serial.list());

port = new Serial(this, Serial.list()[0], 9600);

}

void draw() {
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
stroke(i);
line(i, 0, i, 150);
}

// write the current X-position of the mouse to the serial port as
// a single byte
port.write(mouseX);
}

Serial.list()[0] uses the first port in this list (number 0) and aud used is 9600 if you know the port you can give it directly..

Arduino code

const int ledPin = 12;

void setup()
{

Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop() {
byte brightness;

if (Serial.available()) {

brightness = Serial.read();
if(brightness > 100){

digitalWrite(ledPin,HIGH);
}
else{
digitalWrite(ledPin,LOW);
}
}
}

First upload the arduino code connect an led to pin no 12 then run the processing code a window will open with black and white gradient..if you move the cursor to white or above 100 then the led becomes high..

Happy Hacking 🙂

Configuring Kinect with processing in ubuntu

Xbox-360-Kinect-Standalone

To configure kinect with processing in ubuntu 12.04..first download openni installer

wget http://simple-openni.googlecode.com/files/OpenNI_NITE_Installer-Linux32-0.27.zip

uncompress the file…there will be four folders like this.

Screenshot from 2013-01-18 16:55:03

Inside kinect folder there will be one more folder named Sensor-Bin-Linux…all folders will be having an install.sh file

open a terminal and cd to each folder and issue the following install command

sudo ./install.sh

Now download processing software i used the stable release processing 1.5

wget http://processing.googlecode.com/files/processing-1.5.1-linux.tgz

extract it

Now download SimpleOpenNI processing library

wget http://simple-openni.googlecode.com/files/SimpleOpenNI-0.27.zip

when you run processing for the first time a folder named sketchbook will be created inside home folder

Copy the ‘SimpleOpenNI.zip’ into this folder:

~/sketchbook/libraries

and extract it

if you don’t have libraries folder then create one inside sketchbook

Now restart porcessing from file menu take Examples>Contributed Libraries>simple openni and select depth image example.

Screenshot from 2013-01-17 03_51_51

Connect the kinect to the system .Now compile and run the code if sucessfulyou will get an output window like this.

Screenshot from 2013-01-17 03_53_50

You need java installed in yur system for the working of processing

Happy Hacking 🙂