Author Topic: Sound System error.  (Read 10076 times)

Offline SkyAphid

  • bit
  • Posts: 9
    • View Profile
Sound System error.
« on: March 30, 2013, 10:23:50 PM »
I just downloaded and installed your library into my game engine so that I could use it - and I can't even get your tutorial working. I keep getting null pointer exceptions despite doing everything I'm supposed to do.

Maybe it's a misunderstanding of the library, but here's my code:

Code: [Select] [nofollow]
try{
SoundSystemConfig.addLibrary(LibraryLWJGLOpenAL.class);
SoundSystemConfig.setCodec("wav", CodecWav.class);
}catch(SoundSystemException e){
System.err.println("Sound plug-in link error detected.");
e.printStackTrace();
}

sound = new SoundSystem();
sound.backgroundMusic("TitleTheme", "res/music/titleTheme.wav", true);

The error that is outputted is:

Code: [Select] [nofollow]
Error in class 'CodecWav'
    url null in method 'initialize'
Error in class 'SourceLWJGL OpenAL'
    Audio Format null in method 'play'
Error in class 'CodecWav'
    url null in method 'initialize'
Error in class 'SourceLWJGL OpenAL'
    Audio Format null in method 'play'

I call this method ONCE before I start up the engine. That may be it. Do you require the backgroundMusic method to be called in a loop, or something similar?

Anyway, any help would be appreciated.

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Sound System error.
« Reply #1 on: March 30, 2013, 11:45:56 PM »
Well, you modified the code from the tutorial, that's why  ;D

If you are following along with "3D Sound with SoundSystem", take note of the third paragraph under "Getting Started":

Quote
By default, your sound file must be compiled into the application JAR in a package named “Sounds”

In your code, the SoundSystem is looking for the file at Sounds/res/music/titleTheme.wav (I assume it is actually just in res/music/).  You will need to either call SoundSystemConfig.setSoundFilesPackage( "" ); if you want to use paths outside of Sounds, or put your file in a package called "Sounds", or use one of the methods that takes a URL instance instead of a String.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline SkyAphid

  • bit
  • Posts: 9
    • View Profile
Re: Sound System error.
« Reply #2 on: March 31, 2013, 01:24:19 AM »
Well, you modified the code from the tutorial, that's why  ;D

If you are following along with "3D Sound with SoundSystem", take note of the third paragraph under "Getting Started":

Quote
By default, your sound file must be compiled into the application JAR in a package named “Sounds”

In your code, the SoundSystem is looking for the file at Sounds/res/music/titleTheme.wav (I assume it is actually just in res/music/).  You will need to either call SoundSystemConfig.setSoundFilesPackage( "" ); if you want to use paths outside of Sounds, or put your file in a package called "Sounds", or use one of the methods that takes a URL instance instead of a String.

Oh, I see. Thank you very much for the help! :)

EDIT:

I atleast got it to play a song. But is there anyway to reference music outside of the JAR? I tried the URL thing but it keeps telling me it's unable to open the file.

Here's how I did the URL:

Code: [Select] [nofollow]
public void loadSound(String location){
URL url = getClass().getClassLoader().getResource(location);
sound.loadSound(url, "titleTheme.ogg");
}
« Last Edit: March 31, 2013, 01:59:17 AM by SkyAphid »

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Sound System error.
« Reply #3 on: March 31, 2013, 06:19:37 AM »
GetClassLoader loads resources inside the jar I think.  You'll probably need to get your URL instance from the File class.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline SkyAphid

  • bit
  • Posts: 9
    • View Profile
Re: Sound System error.
« Reply #4 on: March 31, 2013, 02:09:37 PM »
GetClassLoader loads resources inside the jar I think.  You'll probably need to get your URL instance from the File class.
Code: [Select] [nofollow]
public void loadSound(String location){
URL url;
try {
url = new File(location).toURI().toURL();
sound.loadSound(url, "titleTheme.ogg");
} catch (MalformedURLException e) {
e.printStackTrace();
}
}

I did this and managed to avoid getting any errors.

Now my next question is how do I reference the sound I just loaded? You don't seem to be able to give loaded sounds sourcenames, and if I reference them by their filename elsewhere I get a nullpointer exception.

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Sound System error.
« Reply #5 on: March 31, 2013, 03:18:04 PM »
Once you've loaded the clip, you need to create a source to play it.  Use the identifier you came up with (titleTheme.ogg) to reference the clip when you create the source.

From the name, it sounds like you are using a large file.  If this is music or something, you need to stream it instead of loading it entirely into memory with loadSound.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline SkyAphid

  • bit
  • Posts: 9
    • View Profile
Re: Sound System error.
« Reply #6 on: March 31, 2013, 09:26:45 PM »
Once you've loaded the clip, you need to create a source to play it.  Use the identifier you came up with (titleTheme.ogg) to reference the clip when you create the source.

From the name, it sounds like you are using a large file.  If this is music or something, you need to stream it instead of loading it entirely into memory with loadSound.
Yes, but my question is what method do I use to assign the source? I can't find one for it, and referencing the file after I've loaded it in something like backgroundMusic returns a null pointer exception.

Also, yes, I'll try the stream.

Sorry to be such a bother. I can't really find any documentation on here for the API.

EDIT:

Just tried the stream. It didn't throw any errors, but no sound was produced. Here's my code.

Code: [Select] [nofollow]
public void streamSound(String name){
URL url;
try {
url = new File("res/music/").toURI().toURL();
sound.newStreamingSource(false, "TitleTheme", url, name, true, 0, 0, 0,
SoundSystemConfig.ATTENUATION_NONE, SoundSystemConfig.getDefaultRolloff());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}

Note that res/music/titleTheme.ogg is in a folder OUTSIDE of the Jar.

Thanks again for your help so far.
« Last Edit: March 31, 2013, 09:41:11 PM by SkyAphid »

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Sound System error.
« Reply #7 on: April 01, 2013, 08:03:17 AM »
That looks fine for creating the streaming source.  Did you call sound.play( "TitleTheme" ) to play it?

As for your earlier question (for smaller sounds only, not these streaming ones), the method you'd call is either newSource or quickPlay (I prefer the latter for rapid sound effects, because you can just create the source and forget it, letting the SoundSystem manage the sources for you)
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline SkyAphid

  • bit
  • Posts: 9
    • View Profile
Re: Sound System error.
« Reply #8 on: April 01, 2013, 06:16:58 PM »
That looks fine for creating the streaming source.  Did you call sound.play( "TitleTheme" ) to play it?

As for your earlier question (for smaller sounds only, not these streaming ones), the method you'd call is either newSource or quickPlay (I prefer the latter for rapid sound effects, because you can just create the source and forget it, letting the SoundSystem manage the sources for you)

Yes, I called sound.play("TitleTheme"); and got this:

Code: [Select] [nofollow]
Error in class 'SourceLWJGL OpenAL'
    Audio data neither mono nor stereo in method 'play'

Now, the kicker is that if I load the exact same file from the Sounds package, the game loads and plays the sound flawlessly.

Are you sure I'm not streaming it wrong?

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Sound System error.
« Reply #9 on: April 01, 2013, 06:39:16 PM »
Well, could be a problem with the file path I suppose.  If you call the exists() method on your File instance, does it return true?
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Sound System error.
« Reply #10 on: April 01, 2013, 06:40:40 PM »
Let me look up where that particular message gets printed out to see what might cause it.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline SkyAphid

  • bit
  • Posts: 9
    • View Profile
Re: Sound System error.
« Reply #11 on: April 01, 2013, 08:42:57 PM »
Well, could be a problem with the file path I suppose.  If you call the exists() method on your File instance, does it return true?
Well the thing about that is URLs work different from files in the fact that it seperates spaces with %20's and what not, also placing a file:\ at the beginning.

So I'm not sure if this would translate into working for finding files on the computer. The file itself shows up as existent though before I convert it into a URL.

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Sound System error.
« Reply #12 on: April 01, 2013, 09:02:04 PM »
Ok, sorry I just didn't look at your code closely enough.  You aren't using the newStreamingSource method correctly.  See the javadoc here.  The arguments are:

boolean priority,
String sourcename,
URL url,
String identifier,

boolean toLoop,
float x,
float y,
float z,
int attmodel,
float distOrRoll

What you have, for reference:

Code: [Select]
url = new File("res/music/").toURI().toURL();
sound.newStreamingSource(false, "TitleTheme", url, name, true, 0, 0, 0,
SoundSystemConfig.ATTENUATION_NONE, SoundSystemConfig.getDefaultRolloff());

You are pointing the URL to a folder, not a file.  Assuming the "name" argument is the file name (ending in .ogg or whatever format the file is in), change that to:

Code: [Select]
url = new File("res/music/" + name).toURI().toURL();
sound.newStreamingSource(false, "TitleTheme", url, name, true, 0, 0, 0,
SoundSystemConfig.ATTENUATION_NONE, SoundSystemConfig.getDefaultRolloff());
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline SkyAphid

  • bit
  • Posts: 9
    • View Profile
Re: Sound System error.
« Reply #13 on: April 01, 2013, 09:30:16 PM »
Ok, sorry I just didn't look at your code closely enough.  You aren't using the newStreamingSource method correctly.  See the javadoc here [nofollow].  The arguments are:

boolean priority,
String sourcename,
URL url,
String identifier,

boolean toLoop,
float x,
float y,
float z,
int attmodel,
float distOrRoll

What you have, for reference:

Code: [Select] [nofollow]
url = new File("res/music/").toURI().toURL();
sound.newStreamingSource(false, "TitleTheme", url, name, true, 0, 0, 0,
SoundSystemConfig.ATTENUATION_NONE, SoundSystemConfig.getDefaultRolloff());

You are pointing the URL to a folder, not a file.  Assuming the "name" argument is the file name (ending in .ogg or whatever format the file is in), change that to:

Code: [Select] [nofollow]
url = new File("res/music/" + name).toURI().toURL();
sound.newStreamingSource(false, "TitleTheme", url, name, true, 0, 0, 0,
SoundSystemConfig.ATTENUATION_NONE, SoundSystemConfig.getDefaultRolloff());

Oh it worked fantastically! Thank you very much! Take care. =)

Offline SkyAphid

  • bit
  • Posts: 9
    • View Profile
Re: Sound System error.
« Reply #14 on: April 03, 2013, 09:59:27 PM »
Hey again.

I'm having more trouble, but I didn't feel like making a new thread would be appropriate, so I brought my problems back here haha.

Anyway, I'm had a couple of problems. Most of which I've been able to solve with blood sweat and tears.

The one that survived my onslaught of bug murdering though was the problems that have arisen with moving around the listener coordinates and values.

Here's my method for changing the position:

Code: [Select] [nofollow]
public void updatePositioning(InterpolatedEditorCamera c, float vx, float vy, float vz){
sound.setListenerPosition(c.getX(), c.getY(), c.getZ());
sound.setListenerAngle(c.getYaw());
Matrix4f view = c.getViewMatrix();

if (angle < Math.PI){
angle+=0.005f;
}else angle = 0f;

float lookX = (float) Math.cos(angle);
float lookZ = (float) Math.sin(angle);

sound.setListenerOrientation(lookX, 0, lookZ, 0, 1, 0);
sound.setListenerVelocity(vx, vz, vy);
}

Now you'll probably notice I set it up so that the orientation would essentially flip and turn in a circle.

Well, that was part of one of many of my tests. You see, the orientation doesn't seem to be affecting anything, and I assumed it would change which speaker the noises came out and all of that jazz. But it doesn't seem to be working.

So what I'm doing here is setting the position to the camera coordinates, setting the angles, and I also set the velocity to the players movement velocities.

It's also likely worth noting that the grid system the game uses is 1x1 unit floats. So 0.5/0.5 would be in the center of a tile.

Anyway, I noticed a slight latency in the movement of the listener. He always seems a step behind, and the sound still updates its position even when my movement has stopped. It's quite hard to explain.

Also, on top of this, orientation seems to affect nothing and the sound comes equally out of both speakers no matter what.

I should also note I'm using Linear attenuation, and the distance rolloff deal is set to 20f due to how small the coordinate system is.

Here's my method for loading the sound:

Code: [Select] [nofollow]
public void quickPlay(String location, String name, boolean loop, float x, float y, float z){
sound.quickPlay(false, getResourceURL(location + name), name, loop, x, z, y, aModel, rFactor);
}

So to summarize, the listener positions work in a sense, but seem behind. Also, orientation doesn't seem to affect anything.

Also, one more question (while not as important as above) is there anyway to set a volume for quick played sounds?
« Last Edit: April 03, 2013, 10:05:33 PM by SkyAphid »