LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: nomore on August 12, 2003, 17:33:16

Title: OpenAL hates me.... why do I hear just silence ??
Post by: nomore on August 12, 2003, 17:33:16
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
Title: OpenAL hates me.... why do I hear just silence ??
Post by: Matzon on August 12, 2003, 20:23:51
looks pretty sane to me... try removing pitch. Do the org.lwjgl.test.openal.* tests work fine?
Title: OpenAL hates me.... why do I hear just silence ??
Post by: Matzon on August 12, 2003, 20:24:51
How did you create OpenAL - default? AL.create(); ?
Title: OpenAL hates me.... why do I hear just silence ??
Post by: nomore on August 13, 2003, 08:25:32
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 ?
Title: OpenAL hates me.... why do I hear just silence ??
Post by: Matzon on August 13, 2003, 08:34:27
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...
Title: OpenAL hates me.... why do I hear just silence ??
Post by: nomore on August 13, 2003, 08:45:12
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
Title: OpenAL hates me.... why do I hear just silence ??
Post by: nomore on August 13, 2003, 09:13:08
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
Title: OpenAL hates me.... why do I hear just silence ??
Post by: Matzon on August 13, 2003, 10:55:50
hehe, yeah - unless you select synchronous context (which doesn't work on win32?) it is all handled by the native threaded implementation of OpenAL.
Title: OpenAL hates me.... why do I hear just silence ??
Post by: princec on August 13, 2003, 12:41:55
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 :)