We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › Surround Sound / OpenAL
Page Index Toggle Pages: 1
Surround Sound / OpenAL (Read 7651 times)
Surround Sound / OpenAL
Nov 21st, 2006, 11:26pm
 
I search for a measure to make surround sound (3d sound) in processing. I can't found that in the forum and the internet (google).

It exist only a java library with the name "joal" (based on OpenAL). But I don't know, how I can use it with processing. Can you help me, please?

I need it for a interactive project.

(Sorry for my very bad English. I am from Germany)
Re: Surround Sound / OpenAL
Reply #1 - Nov 22nd, 2006, 2:47am
 
In order to use JOAL you'll also need to install the OpenAL runtime library (get it from here) on the client machine. Also, you'll obviously only get true surround sound using a 5.1 soundcard. If your setup is stereo only it provides a simulation (still amazing possibilities though). Another important limitation is that only mono samples can be positioned/animated in 3D space. Stereo will always play as static source w/o any filtering.

I've used JOAL previously for 5 different installation pieces, however not from within a straight Processing setup (used Eclipse). It should be enough to create a folder structure like this inside the Processing "libraries" folder and then use code like the one below:

Code:
libraries/
+-joal/
+-library/
+-joal.jar
+-joal.dll
+-joal_native.dll


Code:
import net.java.games.sound3d.*;
import net.java.games.joal.*;
import net.java.games.joal.util.*;

OALUtil audioSys;
Source audioLoop;
Listener user;

void setup() {
size(200,200);
audioSys = new OALUtil();
try {
Buffer b = audioSys.loadBuffer("c:/temp/bass_mono.wav");
audioLoop = audioSys.createSource(b);
audioLoop.setLooping(true);
audioLoop.setGain(1);
audioLoop.setReferenceDistance(width/4);
}
catch (Exception e) {
e.printStackTrace();
}
user = audioSys.getListener();
user.setGain(1);
audioLoop.play();
}

void draw() {
if (user!=null) {
user.setPosition(width/2-mouseX,height/2-mouseY,0);
}
}

public void stop() {
if (audioLoop != null) {
audioLoop.delete();
audioLoop = null;
}
if (audioSys != null) {
audioSys.cleanup();
audioSys = null;
}
}


This tiny demo is making use of a little convenience library which you should put in its own tab for now:

Code:
/* 
* Copyright (c) 2006 Karsten Schmidt
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* http://creativecommons.org/licenses/LGPL/2.1/
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

import javax.sound.sampled.UnsupportedAudioFileException;

public class OALUtil {

private AL al;
private ALC alc;

public OALUtil() {
try {
initOpenAL();
}
catch (ALException e) {
throw new RuntimeException("OpenAL could not be initialized: "
+ e.getMessage());
}
}

private void initOpenAL() throws ALException {
AudioSystem3D.init();

alc = ALFactory.getALC();
al = ALFactory.getAL();

ALCdevice device;
ALCcontext context;
String deviceID;

// Get handle to default device.
device = alc.alcOpenDevice(null);
if (device == null) {
throw new ALException("Error opening default OpenAL device");
}

deviceID = alc.alcGetString(device, ALC.ALC_DEVICE_SPECIFIER);
if (deviceID == null) {
throw new ALException(
"Error getting specifier for default OpenAL device");
}

System.out.println("Using device " + deviceID);

// Create audio context.
context = alc.alcCreateContext(device, null);
if (context == null) {
throw new ALException("Can't create OpenAL context");
}
alc.alcMakeContextCurrent(context);

if (alc.alcGetError(device) != ALC.ALC_NO_ERROR) {
throw new ALException("Unable to make context current");
}
}

public void cleanup() {
ALCcontext curContext;
ALCdevice curDevice;

curContext = alc.alcGetCurrentContext();
curDevice = alc.alcGetContextsDevice(curContext);
alc.alcMakeContextCurrent(null);
alc.alcDestroyContext(curContext);
alc.alcCloseDevice(curDevice);

al = null;
alc = null;
}

public Buffer loadBuffer(InputStream is) throws UnsupportedAudioFileException, IOException {
Buffer[] buf = AudioSystem3D.generateBuffers(1);
WAVData wd = WAVLoader.loadFromStream(is);
buf[0].configure(wd.data, wd.format, wd.freq);
return buf[0];
}

public Buffer loadBuffer(String fileName) throws IOException, UnsupportedAudioFileException {
return AudioSystem3D.loadBuffer(fileName);
}

public Source loadSource(InputStream stream) throws UnsupportedAudioFileException, IOException {
return AudioSystem3D.generateSource(loadBuffer(stream));
}

public Listener getListener() {
return AudioSystem3D.getListener();
}

public Source createSource(Buffer buffer) {
return AudioSystem3D.generateSource(buffer);
}
}


hth!
Re: Surround Sound / OpenAL
Reply #2 - Dec 8th, 2006, 5:20pm
 
I can't get this to work on OS X 10.4.8.

I added
--libraries/joal/
---- library/joal.jar
---- library/libjoal_native.jnilib
---- library/gluegen-rt.jar
---- library/libgluegen-rt.jnilib

and then used Sketch->Import Library->joal

but I get "Error getting specifier for default OpenAL device" and the default sound device is always null.  I think there's a missing step here, to link the OpenAL framework (from /Library/Frameworks/) to JOAL, but I can't figure that part out.  Anyone have any ideas?

Thanks
Evan
Re: Surround Sound / OpenAL
Reply #3 - Jan 29th, 2007, 5:54am
 
Toxi, you didn't have to include gluegen at all in your buildpath (in eclipse)? I'm trying to compile your sample code, but I get this error:

Code:
java.lang.SecurityException: class "com.sun.gluegen.runtime.NativeLibrary"'s signer information does not match signer information of other classes in the same package 


This is on Mac OS 10.4 Intel BTW. That probably has something to do with it, but I downloaded the correct distro.
Re: Surround Sound / OpenAL
Reply #4 - Jan 29th, 2007, 6:10am
 
Hm turns out it works flawlessly in Processing but still not in eclipse for some reason..
Re: Surround Sound / OpenAL
Reply #5 - Jan 29th, 2007, 7:22am
 
Ah.. the problem is JOGL. It works fine without any of the openGL stuff loaded. I'll post here if I can get it working.
Re: Surround Sound / OpenAL
Reply #6 - Jan 29th, 2007, 9:00pm
 
Okay! I got it working. The solution was to download the most current Jogl build from the Jogl site (https://jogl.dev.java.net/) and replace the jogl.jar in the opengl library with the jars in the distro.

Now it works great!
Re: Surround Sound / OpenAL
Reply #7 - Mar 16th, 2007, 5:17pm
 
Great code sample. Helped me a lot to get started with OpenAL.

One question:
I'm able to move the sound from left to right, and to put everything on the front channels, but I not able to move everything to the rear channels(or even isolate the sound on only one channel). I don't understand why. I check my setup (Windows + Audigy 2Z audio card + 5.1 speaker set) and everything works fine. The Creative set up tool is able to move sound around the room (and to isolate the sound on each speaker). Any ideas ?

I have then tried to move the audio source instead of the listener, by replacing that line of code Code:
user.setPosition(width/2-mouseX,height/2-mouseY,0); 


by
Code:
audioLoop.setPosition(width/2-mouseX,height/2-mouseY,0); 



but I get the same result.
Re: Surround Sound / OpenAL
Reply #8 - Jun 14th, 2008, 12:35am
 
Hello all,

I know this is a really old post but I'm trying to get 5.1 running in processing with a Macbook. Is anyone able to give a simple step by step approach as to how to get this working? I've looked into joal, toxiclib and other things but can't put two and two together. Most my problems seem to be with OALUtil but not sure what that means/ where to get it from/ where to put it??? If anyone can help it will be very much appreciated. I'm relatively new to processing but know a fair amount.
I have an exhibition using lighting and sound using processing and arduino opening on Tuesday and would really really like to get it working fully in 5.1!!

If anyone can give any help this would be incredibly, amazingly helpful.

Thank you!

Tim
Re: Surround Sound / OpenAL
Reply #9 - Dec 20th, 2008, 1:34pm
 
Juat for reference and to close this thread off, the above code has been extended & wrapped up in a library now. More info about it is over here:

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Sound;action=display;num=1229742216
Page Index Toggle Pages: 1