Author Topic: PaulsCode SoundSystem  (Read 7429 times)

Offline joaogl

  • bit
  • Posts: 8
    • View Profile
PaulsCode SoundSystem
« on: July 17, 2013, 11:18:01 AM »
Hello,

I'm having a problem, I just copied the example two of PaulsCode SoundSystem tutorial and its giving me this error:

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

Error in class 'LibraryLWJGLOpenAL'
Unable to open file 'sounds\explosion.wav' in method 'loadSound'
Error in class 'LibraryLWJGLOpenAL'
Sound buffer was not created for sounds\explosion.wav
Error in class 'LibraryLWJGLOpenAL'
Source 'Source_-776755289_-2094588583' not found in method 'play'

My Code:
Code: [Select] [nofollow]
public static void mytest() {
try {
SoundSystemConfig.addLibrary(LibraryLWJGLOpenAL.class);
SoundSystemConfig.addLibrary(LibraryJavaSound.class);
SoundSystemConfig.setCodec("wav", CodecWav.class);
SoundSystemConfig.setCodec("ogg", CodecJOgg.class);
} catch (SoundSystemException e) {
System.err.println("error linking with the pluggins");
}
SoundSystem mySoundSystem = new SoundSystem();
mySoundSystem.backgroundMusic("Cool Music", GameValues.dir + "sounds\\beats.ogg", true);
mySoundSystem.setMasterVolume(0.5f);
sleep(2000);
for (int x = 0; x < 15; x++) {
if (x % 2 == 0) mySoundSystem.quickPlay(false, GameValues.dir + "sounds\\explosion.wav", false, 20, 0, 0, SoundSystemConfig.ATTENUATION_ROLLOFF, SoundSystemConfig.getDefaultRolloff());
else mySoundSystem.quickPlay(false, GameValues.dir + "sounds\\explosion.wav", false, -20, 0, 0, SoundSystemConfig.ATTENUATION_ROLLOFF, SoundSystemConfig.getDefaultRolloff());
sleep(125);
}
sleep(10000);
mySoundSystem.cleanup();
}


Why is this?

I have:
lwjgl_util
lwjgl
SoundSystem
SoundSystemJPCT
SoundSystemUtils
imports...

Do I need them all? do I need more?

What I want is a 2D Sound Engine for a 2D Game...

Please help?
« Last Edit: July 17, 2013, 11:25:25 AM by joaogl »

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: PaulsCode SoundSystem
« Reply #1 on: July 17, 2013, 07:41:06 PM »
You only need SoundSystem, one or more library plugins (recommend LibraryLWJGLOpenAL), and one or more codecs (recommend CodecJOrbis if you are using OGG files).

WRT the error message, make sure you have a package called Sounds in your jar, and the audio files are in there.  In
 your example it looks like you are trying to use sound files that are outside of the JAR.  In that case you want to switch to the versions of the methods that take URL plus identifier, rather than filename.
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 joaogl

  • bit
  • Posts: 8
    • View Profile
Re: PaulsCode SoundSystem
« Reply #2 on: July 17, 2013, 07:49:20 PM »
to use LibraryLWJGLOpenAL I need to use LWJGL also right?

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: PaulsCode SoundSystem
« Reply #3 on: July 17, 2013, 07:55:59 PM »
Yes.  To avoid that you could use LibraryJavaSound, but it is not very compatible anymore since Oracle removed the default mixer from Java.  Best to use LWJGL or JOAL.
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 joaogl

  • bit
  • Posts: 8
    • View Profile
Re: PaulsCode SoundSystem
« Reply #4 on: July 17, 2013, 08:02:03 PM »
Its now says:

Code: [Select] [nofollow]
Starting up SoundSystem...
Initializing LWJGL OpenAL
    (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
OpenAL initialized.

Error in class 'SourceLWJGL OpenAL'
    Decoder null in method 'play'
Error in class 'SourceLWJGL OpenAL'
    Decoder null in method 'play'

SoundSystem shutting down...
    Author: Paul Lamb, www.paulscode.com


Starting up SoundSystem...
Initializing LWJGL OpenAL
    (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
OpenAL initialized.

Error in class 'SourceLWJGL OpenAL'
    Decoder null in method 'play'
Error in class 'SourceLWJGL OpenAL'
    Decoder null in method 'play'

SoundSystem shutting down...
    Author: Paul Lamb, www.paulscode.com
« Last Edit: July 17, 2013, 08:33:20 PM by joaogl »

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: PaulsCode SoundSystem
« Reply #5 on: July 17, 2013, 09:19:28 PM »
You'll need a codec for whatever file format you are trying to play.
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 joaogl

  • bit
  • Posts: 8
    • View Profile
Re: PaulsCode SoundSystem
« Reply #6 on: July 18, 2013, 03:40:03 AM »
I have a codec set:
Code: [Select] [nofollow]
try {
SoundSystemConfig.addLibrary(LibraryLWJGLOpenAL.class);
SoundSystemConfig.setCodec("wav", CodecWav.class);
SoundSystemConfig.setCodec("ogg", CodecJOgg.class);
} catch (SoundSystemException e) {
System.err.println("error linking with the pluggins");
}
SoundSystem mySoundSystem = new SoundSystem();
try {
mySoundSystem.backgroundMusic("Ambient", new URL("file:\\" + GameValues.dir + "\\sounds\\theme.wav"), "a", true);
} catch (MalformedURLException e) {
e.printStackTrace();
}
imports;
CodecJOgg
CodecWav
LibraryLWJGLOpenAL
lwjgl_util
lwjgl
SoundSystem


Btw I also tried to change the file from ogg to wav and nothing...
« Last Edit: July 18, 2013, 03:50:47 AM by joaogl »

Offline joaogl

  • bit
  • Posts: 8
    • View Profile
Re: PaulsCode SoundSystem
« Reply #7 on: July 18, 2013, 04:44:18 AM »
Code: [Select] [nofollow]
mySoundSystem.backgroundMusic("Ambient", "theme.wav", true);
this one works just fine.
Code: [Select] [nofollow]
try {
mySoundSystem.backgroundMusic("Ambient", new URL("file:\\" + GameValues.dir + "\\sounds\\theme.wav"), "a", true);
} catch (MalformedURLException e) {
e.printStackTrace();
}
This one gives me the error...

Code: [Select] [nofollow]
Error in class 'SourceLWJGL OpenAL'
    Decoder null in method 'play'
Error in class 'SourceLWJGL OpenAL'
    Decoder null in method 'play'
Error in class 'SourceLWJGL OpenAL'
    Decoder null in method 'play'
Error in class 'LibraryLWJGLOpenAL'
    No codec found for file 'boom' in method 'loadSound'
Error in class 'LibraryLWJGLOpenAL'
    Sound buffer was not created for boom

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: PaulsCode SoundSystem
« Reply #8 on: July 18, 2013, 07:07:04 AM »
From the JavaDoc:
Quote
The third parameter 'identifier' should look like a filename, and it must have the correct extension so SoundSystem knows what codec to use for the file referenced by the URL instance.
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 joaogl

  • bit
  • Posts: 8
    • View Profile
Re: PaulsCode SoundSystem
« Reply #9 on: July 18, 2013, 08:00:08 AM »
Can I load a file on the beginning and play it when I want?

I tried this:

Code: [Select] [nofollow]
public static void setupSound() {
try {
mySoundSystem.loadSound(new URL("file:\\" + GameValues.dir + "res\\sounds\\explosion.wav"), "explosion.wav");
mySoundSystem.loadSound(new URL("file:\\" + GameValues.dir + "res\\sounds\\beats.ogg"), "beats.ogg");
} catch (MalformedURLException e) {
e.printStackTrace();
}
}

public static void playSound() {
mySoundSystem.play("beats.wav");
}

but doesnt work..

Code: [Select] [nofollow]
Error in class 'LibraryLWJGLOpenAL'
    Source 'explosion.wav' not found in method 'play'

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: PaulsCode SoundSystem
« Reply #10 on: July 18, 2013, 04:47:42 PM »
"explosion.wav" is the identifier for a sample, not a source name.  You would need to create one or more sources from that sample, which you can then play whenever you like.  Be sure to take a look at the quickPlay methods, which will take care of source management so you won't need to hold onto any source names.  This method is useful for a lot of situations (not every situation, but worth looking at).

I recommend reading the guide I wrote, 3D Sound with SoundSystem which will get you more familiar with the terminology used by the library (some of it is important to understand, such as the distinction between samples, sources, and channels)
« Last Edit: July 18, 2013, 04:52:22 PM by Paul »
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