WaveData.create and WaveData.class.getClassLoader().getResourceAsStream

Started by stradiotto, December 02, 2011, 18:11:53

Previous topic - Next topic

stradiotto

Hello Mr. Rychlik-Prince (I didn´t know at who I had to speak, so I saw your name in first place on Credits Page (http://lwjgl.org/credits.php) on LWJGL project portal).

1)   My name is César R. K. Stradiotto, and I´m a doctoral student (about ontologies in 3D space, but still not games) in Brazil. My interest is also game prototyping, and for many times I have been looking for a sound library which is easy to use together with some well known 3D library, as OpenGL, DirectX, and actually, Java 3D.

2)   About the sound libraries I had tried, they include:

a.   JOAL (http://java.net/projects/joal),
b.   JOAL-JOGAMP (http://jogamp.org/),
c.   XITH3D (http://xith.org/)
d.   Java Sound (http://www.jsresources.org/links.html)
e.   Java Media Framework (http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html) and
f.   Java 3D Internal methods for Sound (like Soundscape and Auralattributes, with no real results for sound controlling, like pan and reverb, for example)

3)   My working platform is the following (may be it helps for bug tracking):

a.   Intel Core 2 Quad CPU Q6600, 2.40GHz, 2GB RAM
b.   Microsoft Windows XP Professional, Version 2002, Service Pack 3
c.   Audio Device: Realtek High Definition Audio. Driver from Realtek Semiconductor Corp. Data 07/07/2011, version 5.10.0.6410
d.   Java SE 1.6.0_26
e.   NetBeans 7.0.1

4)   To get started with LWJGL, I made the download of library version 2.8.2 from http://sourceforge.net/projects/java-game-lib/files/Official%20Releases/LWJGL%202.8.2/lwjgl-2.8.2.zip/download

5)   I have made also the download of the following sample code files from your demo page [http://lwjgl.org/demos.php]:

a.   MovingSoundTest.java  
b.   PlayTest.java  
c.   PlayTestMemory.java  
d.   StressTest.java  
e.   ALCTest.java

6)   Through testing, I had included only the necessary libraries to compile the codes from the samples above. I removed the libraries presumably unnecessary, and saw if NetBeans shown some red line advising about a missing library. So the remaining libraries to run the samples were

a.      lwjgl.jar
b.      lwjgl_test.jar
b.      lwjgl_util.jar

7)   So, to run the samples, I also included the java compiler the parameter for library path, including the path for the native code:

-Djava.library.path= "C:\Java\Libraries\LWJGL_282\built\lwjgl-2.8.2\native\windows"

for example.

By this way, Java wouldn’t claim for a missing native library to run the LWJGL samples

8)   I didn´t had the sound files given by the authors of the examples (like “Footsteps.wav”, or sounds from Space Invaders sample), so I adapted the file names and paths to point to the absolute paths of sound files which I had downloaded from web to my local machine.

For example, where it was coded

"Footsteps.wav",

I put

"C://sounds//M1F1-float32-AFsp.wav"



9)   About the results for compiling and executing the examples:

a.   ALCTest.java: It worked fine, showing the default sound devices and ALC version

b.   MovingSoundTest.java

i.   Didn´t worked fine because where I tryed to use

WaveData wavefile = WaveData.create("C://sounds//M1F1-uint8-AFsp.wav");

It returned a Exception message:

"Exception in thread "main" java.lang.NullPointerException"

Debugging the code, I just observed that the “wavefile” object is null after its creation.

ii.   It worked fine using URL object, as explained on the library help doc (http://lwjgl.org/javadoc/org/lwjgl/util/WaveData.html#create%28java.net.URL%29):

WaveData wavefile = WaveData.create(new URL("file:C://sounds//M1F1-uint8-AFsp.wav"));


iii.   It was important to consider the use of the prefix “file:”, for strings inside URL objects, and its absence for strings representing only sound files


c.   PlayTest.java

i.   Did not worked fine with

wavefile = WaveData.create(args[0]);

where

args = new String[] {"C://sounds//M1F1-uint8-AFsp.wav"}; instead of "Footsteps.wav"



ii.   But it worked fine with

args = new String[] {"file:C://sounds//M1F1-uint8-AFsp.wav"}; (Observe the "file:" preffix)

and

WaveData wavefile = null;
URL u =null;

try {
 u = new URL(args[0]);
 wavefile = WaveData.create(u);
} catch (MalformedURLException ex) {
 Logger.getLogger(PlayTest.class.getName()).log(Level.SEVERE, null, ex);
}

d.   PlayTestMemory.java

i.   I have exchanged

args = new String[] {"Footsteps.wav"};

by

args = new String[] {"file:C://sounds//M1F1-uint8-AFsp.wav"}; (with "file:" preffix for URL objects)

and also by

args = new String[] {"C://sounds//M1F1-uint8-AFsp.wav"}; (without "file:" preffix)

but inside the method

protected ByteBuffer getData(String filename) {...

the object

WaveData.class.getClassLoader().getResourceAsStream(filename)

Inside the call

BufferedInputStream bis = new BufferedInputStream(WaveData.class.getClassLoader().getResourceAsStream(filename));

returns a null value.

Being that way, when the statement

while((read = bis.read(readBuffer, 0, bufferLength)) != -1) {
   baos.write(readBuffer, 0, read);
}

starts, although the object “bis” is not null, probably it points to an WaveData object which is null, generating an

java.io.IOException: Stream closed

ii.   Inside the method

protected ByteBuffer getData(String filename)

I had dismembered the call

BufferedInputStream bis = new BufferedInputStream(WaveData.class.getClassLoader().getResourceAsStream(filename));

into two parts:

InputStream wd = WaveData.class.getClassLoader().getResourceAsStream(filename);
BufferedInputStream bis = new BufferedInputStream(wd);

And through the debugger, I just verified that for

args = new String[] {"file:C://Java//Libraries//LWJGL_282//built//lwjgl-2.8.2//res//spaceinvaders//shot.wav"};  (with "file:" suffix for URL objects)

and also for

args = new String[] {"C://java//Libraries//LWJGL_282//built//lwjgl-2.8.2//res//spaceinvaders//shot.wav"}; (without "file:" suffix)

the wd object resulting from

InputStream wd = WaveData.class.getClassLoader().getResourceAsStream(filename);

is null, generating the same

java.io.IOException: Stream closed

already explained on item 9) d. i., above, inside the while statement

while((read = bis.read(readBuffer, 0, bufferLength)) != -1) {
   baos.write(readBuffer, 0, read);
}

e.   PositionTest.java

i.   Inside the method

private void setup() throws Exception {…

I had exchanged

WaveData left = WaveData.create("left.wav");

by

WaveData left = WaveData.create("C://java//NetBeans_7_0//Projetos//AudioPlayer02//Sounds//01.wav");

and the NetBeans debugger advices me that

left = null

ii.   After that I have exchanged

WaveData left = WaveData.create("C://java//NetBeans_7_0//Projetos//AudioPlayer02//Sounds//01.wav");

by

WaveData left = WaveData.create(new URL("file:C://Java//NetBeans_7_0//Projetos//AudioPlayer02//Sounds//01.wav")); (Observe “file:” prefix inside string for URL object)

So the Java compiler allocated memory for the “left” object, and all the method after this have worked fine, for sound parameters like pitch, gain and so forth, on the

AL10.alSourcef(...)
…

method sequence.



10)   I also look for some solution about this probable bug in the following topic:

Topic: [FIXED] possible bug in WaveData.create() [http://lwjgl.org/forum/index.php/topic,3210.msg17765.html#msg17765]

from the discussion list inside LWJGL portal, but the answer inform that this possible bug was already corrected for the next version 2.3 of the library, in [http://lwjgl.org/forum/index.php/topic,3210.msg17766.html#msg17766] and [http://lwjgl.org/forum/index.php/topic,3210.msg17767.html#msg17767], and also that this correction is already implemented in the trunk. I don´t know if the referred bug is the same that I´m talking about in this post.



11)   So, after all these experiences over the LWJGL library and its offered samples, I´m worried about the following:

The report that I just have written are helping you for bug identification inside your library, or am I committing some basic error about system configuration, which blocks some methods to work fine?

Or maybe I am committing the error of complicating, or extending my explanation too much, lacking for simplicity to help you.

If this last case happen, please, tell me, and I´ll separate the cases into smaller texts, or maybe I can send the request â€" didactically formatted â€", and also my used WAV files, through an offered e-mail account (by the way, my e-mail is cesar.stradiotto@i3g.org.br).

12)   I also have perceived that the library can read some .WAV files, but not all. I know that´s not a problem at all. To solve this, it´s enough to change some parameters inside the .WAV file, like number of playing channels, frequency, and sampling, among others, to be readable by the library.

Cordially

César R. K. Stradiotto