Author Topic: SoundSystem - Simultaneous Clips Hanging  (Read 3508 times)

Offline easalmon

  • bit
  • Posts: 4
    • View Profile
SoundSystem - Simultaneous Clips Hanging
« on: November 20, 2013, 05:37:22 PM »
Library: LibraryJavaSound
Codec: JOrbis

I'm having a problem getting sounds to overlap. My background music plays fine, but if I call another clip, the program hangs. In looking for answers I saw Paul mention that Java removed the default mixer--is that the issue here?

Thanks for any help!

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3495
  • Developer
    • View Profile
    • PaulsCode.Com
Re: SoundSystem - Simultaneous Clips Hanging
« Reply #1 on: November 20, 2013, 05:47:51 PM »
Could you post example code?  I'm pretty sure this is the mixer problem you referred to, but can check for other possible causes.
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 easalmon

  • bit
  • Posts: 4
    • View Profile
Re: SoundSystem - Simultaneous Clips Hanging
« Reply #2 on: November 20, 2013, 06:38:13 PM »
Yeah, definitely. Thanks for looking!

I stopped the hang by moving the call to quickplay elsewhere, so I'm not sure what the problem is. I also tried switching to the lwjgl library and it hasn't helped so it's probably just a problem with my code.

In my singleton SoundManager wrapper class, I just initialize everything and set the library and codec, then I have these methods:

Code: newbielink:javascript:void(0); [nonactive]
/**
* Play's the given clip as backgroundMusic
* @param clip
*/
public void playBackground(File clip)
{
try {
mySoundSystem.backgroundMusic("bg",clip.toURI().toURL(), clip.getName(), true);
} catch (MalformedURLException e) {
e.printStackTrace();
}

}

/**
* Play's the given clip
* @param clip
*/
public void play(File clip)
{
try {
mySoundSystem.quickPlay(true, clip.toURI().toURL(), clip.getName(), false, 0, 0, 0, SoundSystemConfig.ATTENUATION_NONE, SoundSystemConfig.getDefaultRolloff());
} catch (MalformedURLException e) {
e.printStackTrace();
}


Elsewhere when the program first starts, but after the SoundSystem is initialized:
Code: newbielink:javascript:void(0); [nonactive]
//works perfectly
SoundManager.getInstance().playBackground(new File("background.ogg"));
//no new sound is played
SoundManager.getInstance().play(new File("explosion.ogg"));

and finally later in an  method that's called every time two of my objects enter combat
Code: newbielink:javascript:void(0); [nonactive]
//bacground music continues playing, but game logic hangs and no new sound is played.
SoundManager.getInstance().play(new File("explosion.ogg"));/code]


I'm going to make a small example project and see if I get things working in that, but I feel like I'm just missing something obvious here.

Thanks again,

eas

Offline easalmon

  • bit
  • Posts: 4
    • View Profile
Re: SoundSystem - Simultaneous Clips Hanging
« Reply #3 on: November 20, 2013, 07:13:21 PM »
Here's a better example without my code in the way. You'll have to fill in a good background track and a sound effect (or other short clip).

Code: newbielink:javascript:void(0); [nonactive]
import java.io.File;
import java.net.MalformedURLException;

import paulscode.sound.SoundSystem;
import paulscode.sound.SoundSystemConfig;
import paulscode.sound.SoundSystemException;
import paulscode.sound.codecs.CodecJOgg;
import paulscode.sound.libraries.LibraryJavaSound;
import paulscode.sound.libraries.LibraryLWJGLOpenAL;

public class MultipleSounds {

public static void main(String[] args) {
try {
SoundSystemConfig.addLibrary(LibraryJavaSound.class);
SoundSystemConfig.setCodec("ogg", CodecJOgg.class);
} catch (SoundSystemException e) {

}

SoundSystem mySoundSystem = new SoundSystem();
mySoundSystem.setMasterVolume(0.5f);

File bg = new File("Edward_Shallow_-_01_-_Tower.ogg");
try {
mySoundSystem.backgroundMusic(bg.getName(), bg.toURI().toURL(),
bg.getName(), true);
} catch (MalformedURLException e) {
e.printStackTrace();
}

File clip = new File("explosion.ogg");
try {
mySoundSystem.quickPlay(true, clip.toURI().toURL(), clip.getName(), true, 0, 0, 0, SoundSystemConfig.ATTENUATION_NONE, SoundSystemConfig.getDefaultRolloff());
} catch (MalformedURLException e) {
e.printStackTrace();
}


}
}
]

I might just be approaching it in too simplistic a manner--I'd like to call quickPlay and have it automatically play the sound effect as well as the background music.

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3495
  • Developer
    • View Profile
    • PaulsCode.Com
Re: SoundSystem - Simultaneous Clips Hanging
« Reply #4 on: November 20, 2013, 07:17:13 PM »
I don't see anything obviously wrong with your code.  One thing I did notice is you are using CodecJOgg, which sometimes has problems with short-duration ogg files.  You might try testing with CodecJOrbis just to rule that out as the cause.
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 easalmon

  • bit
  • Posts: 4
    • View Profile
Re: SoundSystem - Simultaneous Clips Hanging
« Reply #5 on: November 20, 2013, 07:38:51 PM »
Ahh, that was it!

Thanks!