OpenAL hates me.... why do I hear just silence ??

Started by nomore, August 12, 2003, 17:33:16

Previous topic - Next topic

nomore

Hi there,

the OpenAL C-testing programs are all working fine. Now, I'm using the java binding but I hear absolutly nothing.

Here's the code:

package de.bytelords.thor;

import java.nio.*;
import de.bytelords.thor.util.Buffer;
import org.lwjgl.openal.AL;

/**
 * @author nomore
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class Sample implements SoundFile {
	
	IntBuffer soundBuffer;
	IntBuffer soundSource;
	
	public Sample(String file)
	{
		int lastError = 0;
		
		soundBuffer = Buffer.createIntBuffer(1);
		soundSource = Buffer.createIntBuffer(1);
		
		AL.alGenBuffers(1,soundBuffer);
		if((lastError = AL.alGetError()) != AL.AL_NO_ERROR)
		{
			System.out.println(AL.alGetString(lastError));
			return;
		}
				
		AL.alGenSources(1,soundSource);
		if((lastError = AL.alGetError()) != AL.AL_NO_ERROR)
		{
			System.out.println(AL.alGetString(lastError));
			return;
		}
				
		load(file);
	}
	
	public boolean load(String file)
	{
		int lastError = 0;
		
		de.bytelords.thor.util.WaveData wavefile = de.bytelords.thor.util.WaveData.create(file);

		AL.alBufferData(soundBuffer.get(0), wavefile.format, wavefile.data, wavefile.data.capacity(), wavefile.samplerate);
		if((lastError = AL.alGetError() )!= AL.AL_NO_ERROR)
		{
			System.out.println(AL.alGetString(lastError));
			return false;
		}
		
		AL.alSourcei(soundSource.get(0), AL.AL_BUFFER, soundBuffer.get(0));
		if((lastError = AL.alGetError()) != AL.AL_NO_ERROR)
		{
			System.out.println(AL.alGetString(lastError));
			return false;
		}

		wavefile.dispose();
		return true;
	}

	public void play(boolean loop)
	{
		int lastError = 0;
		
		AL.alSourcei(soundSource.get(0),AL.AL_LOOPING, AL.AL_FALSE);
		if((lastError = AL.alGetError()) != AL.AL_NO_ERROR)
		{
				System.out.println(AL.alGetString(lastError));
				return;
		}
				
		AL.alSourcef(soundSource.get(0),AL.AL_PITCH,1);
		AL.alSourcePlay(soundSource.get(0));
		if((lastError = AL.alGetError()) != AL.AL_NO_ERROR)
		{
				System.out.println(AL.alGetString(lastError));
				return;
		}
	}
	
	public void release()
	{
		stop();
		AL.alDeleteSources(1,soundSource);
		AL.alDeleteBuffers(1,soundBuffer);
	}
	
	public void stop()
	{
		AL.alSourceStop(soundSource.get());
	}
}


I get no error messages from the code above while running!
Does anyone know an error in the code ?? I've examined the c-samples and I didn't find a real difference. Any help would be really great !

Bye,

Alex

Matzon

looks pretty sane to me... try removing pitch. Do the org.lwjgl.test.openal.* tests work fine?

Matzon

How did you create OpenAL - default? AL.create(); ?

nomore

well... yeah I use the default initialization method AL.create().

I've tried now one of the samples under WinXP and I'm getting this error(the same under linux with the same example)

C:\Entwicklung\lwjgl-pre0.7>java -cp .;lwjgl_test.jar;lwjgl.jar; org.lwjgl.test.
openal.PlayTest c:/test.wav
java.io.IOException: Stream closed
        at java.io.BufferedInputStream.ensureOpen(Unknown Source)
        at java.io.BufferedInputStream.read(Unknown Source)
        at java.io.DataInputStream.readInt(Unknown Source)
        at com.sun.media.sound.WaveFileReader.getFMT(Unknown Source)
        at com.sun.media.sound.WaveFileReader.getAudioInputStream(Unknown Source
)
        at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
        at org.lwjgl.test.openal.WaveData.create(Unknown Source)
        at org.lwjgl.test.openal.PlayTest.execute(Unknown Source)
        at org.lwjgl.test.openal.PlayTest.main(Unknown Source)
Exception in thread "main" java.lang.NullPointerException
        at org.lwjgl.test.openal.PlayTest.execute(Unknown Source)
        at org.lwjgl.test.openal.PlayTest.main(Unknown Source)


Any suggestions ?

Matzon

yeah, it's not finding the file!

place test.wav in C:\Entwicklung\lwjgl-pre0.7\ and do a:

java -cp .;lwjgl_test.jar;lwjgl.jar; org.lwjgl.test.openal.PlayTest test.wav

ought to work...

nomore

hey again,


the samples of openal are working now... didn't know that the wav-files have to be in the classpath....... but my example isn't working

nomore

my code works now too.... didn't know that openal plays it's samples in a separate thread... so... releasing the soundfile directly after playing it without a Thread.sleep(5000) for example isn't so great.... :wink:

thanx for your help people !

Bye, Alex

Matzon

hehe, yeah - unless you select synchronous context (which doesn't work on win32?) it is all handled by the native threaded implementation of OpenAL.

princec

Yes, annoyingly synchronous contexts on Win32 simply lock the application up :/ I had words with the OpenAL devs about this; we should re-open it and get them to implement synchronous mode properly.

Cas :)