Problem with WaveData.create()

Started by jacekcichy, October 21, 2009, 18:07:41

Previous topic - Next topic

jacekcichy

Hi I have some problem with this method. When I'm trying to compile my program I have list of errors:

java.lang.NullPointerException
	at org.lwjgl.util.WaveData.create(WaveData.java:95)
	at org.lwjgl.util.WaveData.create(WaveData.java:112)
	at Sound.loadALData(Sound.java:59)
	at Sound.execute(Sound.java:121)
	at Sound.<init>(Sound.java:41)
	at TestKolizji.initGame(TestKolizji.java:93)
	at TestKolizji.main(TestKolizji.java:77)
java.lang.NullPointerException
	at Sound.loadALData(Sound.java:61)
	at Sound.execute(Sound.java:121)
	at Sound.<init>(Sound.java:41)
	at TestKolizji.initGame(TestKolizji.java:93)
	at TestKolizji.main(TestKolizji.java:77)


Fragment of my code:

private int loadALData() {
		// Load wav data into a buffer.
		AL10.alGenBuffers(buffer);

		if(AL10.alGetError() != AL10.AL_NO_ERROR){
			return AL10.AL_FALSE;
		}				
		
		WaveData waveFile = WaveData.create("data/di.wav");
		
		AL10.alBufferData(buffer.get(0), waveFile.format, waveFile.data, waveFile.samplerate);
		waveFile.dispose();
				
		// Bind the buffer with the source.
		AL10.alGenSources(source);

		if (AL10.alGetError() != AL10.AL_NO_ERROR){
			return AL10.AL_FALSE;
		}
		      

		AL10.alSourcei(source.get(0), AL10.AL_BUFFER,   buffer.get(0) );
		AL10.alSourcef(source.get(0), AL10.AL_PITCH,    1.0f          );
		AL10.alSourcef(source.get(0), AL10.AL_GAIN,     1.0f          );
		AL10.alSource (source.get(0), AL10.AL_POSITION, sourcePos     );
		AL10.alSource (source.get(0), AL10.AL_VELOCITY, sourceVel     );
		    
		// Do another error check and return.
		if (AL10.alGetError() == AL10.AL_NO_ERROR){
			return AL10.AL_TRUE;
		} else {
			return AL10.AL_FALSE;
		}	   
	}


Thanks for help Jacek :)

Ciardhubh

Java could not find your audio file. Try "./data/di.wav" or "/data/di.wav" or "/absolutepathtobasedir/data/di.wav", depending on where the file actually is.

jacekcichy

unfortunatelly still the same error  :-[

Matzon

check the path its trying to access - make sure its on the classpath. NPEs are best debugged locally

Ciardhubh

Alternatively, create an InputStream (e.g. new FileInputStream(...) or SomeClass.class.getResourceAsStream(...)) yourself and pass it to WaveData.create(is). That should be easier to debug (and is more flexible later on).

jacekcichy

I was trying Ciardhub method so I made FileInputStream and it works fine cause java didn't return FileNotFounException but when I was trying to put it into my SoundLoad method the same error appeared. I think it is something that Matzon say but my english is not good and I'm also novice in OpenGL and OpenAL programing so if You have some time Matzon please look at my eclipse Project http://www.sendspace.com/file/djq5ut and write me what I should add to my code or classpath.

Thanks a lot
Jacek  :)

broumbroum

you must be running on your SoundTest root folder to get access to the data/files. And Buffers must be .rewind()'ed before to reuse them after a put() or get() call. Either you can rewind all buffers or use the common Buffer.wrap(array[]) function.
I got your files and built a netbeans project which will run the test main() method, then you can here the sound playing.
Then I made the attached .rar, lwjgl jars and the di.wav data are missing so you must copy them into bin/ and data/ resp.


jacekcichy

Thanks broumbroum for Your effort  :) I did what You suggest to do and I compiled it in eclipse. No errors but I still dont hear music  :-\ I absolutelly don't know what is wrong.. I always attached all lwjgl jars to project and set VM arguments. And all my openGL application was running without any problems.. So its strange...