The source code of all examples is included in the KinectJLib distribution.
Example 3: Kinect Sound Direction Finder
The Kinect microphone array uses 4 microphones in a line and enables the user to perform acoustic localization of the sound source in a horizontal plane. The algorithm to deliver the angle to the sound source is by far not trivial. It is implemented in Microsoft's Kinect native library installed with the Kinect SDK. Java gets access to the code via the JNI based framework JAW. JKinectLib shields the Java programmer completely from the complexity of the underlying code: After enabling the sound direction scanning machine with enableSoundDirection(true), the angle to the sound source is polled by calling getSoundDirection(). This method retrieves the last direction together with a confidence level from the native detection machine.
For a more profound discussion of how the Kinect microphone array works, consult this post or this scientific paper.
We demonstrate the Kinect sound direction finder by the following program where the direction to the sound source is displayed as a beam line in a circle centered a the Kinect device. The line is updated only if the confidence level exceeds a given value (here 30%). Of course the sound direction finder can be combined with a native video window and a skeleton detection. For simplicity we use the GPanel class from the ch.aplu.util package to display the graphics.
- Windows 7 or higher (32- or 64-bit)
- Installation of the Kinect SDK from http://kinectforwindows.org
- Kinect for Xbox 360 or Kinect for Windows
(both devices are supported)
(If you install the KinectRuntime and not the full SDK, only the Kinect for Windows is supported.)
public class KinectEx3 extends GPanel
private final int confidenceLevel = 30; // Minimum confidence level
private final String dllPath =
Kinect.is64bit() ? "KinectHandler64" : "KinectHandler";
private final String title = "Kinect Video Frame";
super(-1, 1, 1, -1);
title("Sound Direction Finder Demo");
Kinect kinect = new Kinect(dllPath, title, 10, 20, 320, 240,
NativeHandler.WS_BORDER | NativeHandler.WS_VISIBLE);
setStatusText("Audio Direction Finder ready. Please speak now!");
SoundDirection ad = kinect.getSoundDirection();
if (ad.confidence >= confidenceLevel)
setStatusText("New position: " + ad.position
+ " degrees (Confidence: " + ad.confidence + "%)");
setStatusText("Confidence: " + ad.confidence + "% < " +
confidenceLevel + "% (too small)");
private void drawLine(int angle)
double a = Math.toRadians(angle);
line(0, 0, 0.9 * Math.sin(a), 0.9 * Math.cos(a));
private void showCircle()
public static void main(String args)
Execute the program locally using WebStart.