Strange Behavior with Sound System

Hey,

First of all, the method getNifty().getSoundSystem().setSoundVolume(0); doesn’t do nothing, it simply set the sound volume attribute, but jme doesn’t call its volume getter from anywhere, then the volume will never be changed. I already took a look at the SoundHandleJme and SoundDeviceJme classes.

Then I tried to use the method getNifty().getSoundSystem().getSound(“btnHoverSound”).setVolume(0); and it really set the volume, but if the sound be played again, the volume is reseted again (I don’t know why -.- ).



Then the only PARTIAL solution I found, is set the volume with the method above in each appState update, but it is a really bad solution. Any ideas?

I guess its simply not considered somehow… @Momoko_Fan?

OK I added those issues to the tracker

1 Like

How are the supported sound file formats by the engine. I know two : “.wav” and “ogg”. What about “mp3”? mp3 is more compressed than ogg and wav, I wonder why it’s not supported.

mp3 is covered by patents and since we are not making any profit from the engine we cannot afford a license nor do we want to.

Apparently you have to pay 2,500$ to use it in a game (source, not sure if reliable).

On the other hand, OGG/Vorbis is patent free and is better than mp3 (source)

1 Like

Hi,

Do you guys plan add a pause feature to the SoundHandleJme.java? It seems was forgotten by Kiril :roll:. Right now I’m creating a sound editor for my rhythm game like in FretsOnFire, but there’s no way to pause the music via nifty, because the nifty sounds and musics are SoundHandleJme in jme. I did it myself, then if you guys plan add it feature here is how I did. I’ve added a pause method to that:



SoundHandleJme.java



[java]

public void pause() {

if (node != null){

node.pause();

}

}

[/java]



-Regards

You could always just not use nifty to play your sounds and just use AudioNode instead.

Yeah! It would make my problems go away. But I’m using nifty sound system because I’m working on gui at moment. So as my nifty components plays sounds, I thought better using nifty sound system to handle sounds at all. Btw your suggestion is cool too.

Also, there’s a way to retard / advance sounds in jme?

@glaucomardano said:
Also, there's a way to retard / advance sounds in jme?

Nope, it's in the todo

Hmm. Ok. I hope it’s not so difficult to do. So I would contribute with that, because I have to implement that in my game anyway, there’s no way to create a sound editor without that feature. I’ll take a look at that.

@glaucomardano said:
Hmm. Ok. I hope it's not so difficult to do. So I would contribute with that, because I have to implement that in my game anyway, there's no way to create a sound editor without that feature. I'll take a look at that.

When I talk about it with Kirill it sounded awfully complicated...
I'll try to look into it , i need it for cinematics.

So such stuff exist :slight_smile: :



[java]

audioNode.setTimeOffset();

[/java]



I just didn’t find it before because I was using nifty, and the SoundHandleJme.java does not have methods like these:



my working copy



[java]

public void pause() {

if (node != null){

node.pause();

}

}



public void setTimeOffset(float timeOffset) {

node.setTimeOffset(timeOffset);

}

[/java]



-Glauco Márdano

hmmm. Now I know why SoundHandleJme.java didn’t have those methods before, That’s because SoundHandleJme.java extends SoundHandle.java, and SoundHandle.java is from nifty libraly xD. Then the only way I know to call those methods is ((SoundHandleJme)soundHandle).pause()…

Or… you do like I originally suggest and not use SoundHandle at all. :wink:



I still don’t understand why not just use the AudioNode directly. You get no really strong benefit with SoundHandle since you are trying to control these sounds through your game logic and not as just an effect on a button.

1 Like

Yeah. Damned sound handle. Your right. I’m mixing the things. I’m feeding a baby with a bottle of vodka xD. Thanks for waking me up.

What a metaphor! :slight_smile:



I think it’s more like using a butter knife as a screwdriver… with similarly dangerous-but-not-very consequences. :slight_smile:

Hi. I just wanna say that the issue that I reported in my first post isn’t a bug from jme, it’s from nifty side.



@Momoko_Fan said:

OK I added those issues to the tracker



Disregard that ;).

I just looked at the nifty source code and the following method of the SoundSystem.java:

[java]
public void setSoundVolume(float newSoundVolume) {
this.soundVolume = newSoundVolume;
}
[/java]

should be replace with:

[java]
public void setSoundVolume(float newSoundVolume) {
this.soundVolume = newSoundVolume;
for(SoundHandle sd:soundLookup.values())
sd.setVolume(soundVolume);
}
[/java]

@void256 : Am i wrong :)?

and @pspeed, don't worry, I'm usign the audionode as well for my musics ;). But for the nifty components that's inevitable.
For the musics I'm using an audioManager ;) :

[java]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package rhythmgame.audio;

import com.jme3.asset.AssetManager;
import com.jme3.audio.AudioNode;
import com.jme3.scene.Node;
import java.util.ArrayList;
import java.util.List;
import rhythmgame.util.Stopwatch;

/**
*
* @author Glauco Márdano
*/
public class AudioManager {

private AssetManager assetManager;
private Node audioNode = new Node("audioNode");
private List<Stopwatch> stopwatchList = new ArrayList<Stopwatch>();

public AudioManager(AssetManager assetManager, Node rootNode) {
this.assetManager = assetManager;
rootNode.attachChild(audioNode);
}

public void addAudio(String source, String name) {
AudioNode ad = new AudioNode(assetManager, source);
ad.setName(name);
audioNode.attachChild(ad);
stopwatchList.add(new Stopwatch());
}

public void removeAudio(String name) {
AudioNode ad = getAudio(name);
stopwatchList.remove(getStopwatch(ad));
ad.removeFromParent();
}

public void playAudio(String name) {
AudioNode ad = getAudio(name);
Stopwatch sw = getStopwatch(ad);
ad.play();
sw.start();
}

public void resumeAudio(String name) {
AudioNode ad = getAudio(name);
Stopwatch sw = getStopwatch(ad);
ad.play();
sw.resume();
}

public void pauseAudio(String name) {
AudioNode ad = getAudio(name);
Stopwatch sw = getStopwatch(ad);
ad.pause();
sw.pause();
ad.setTimeOffset(sw.elapsed() / 1000);
}

public void stopAudio(String name) {
AudioNode ad = getAudio(name);
Stopwatch sw = getStopwatch(ad);
ad.stop();
sw.stop();
ad.setTimeOffset(0);
}

public void setAudioElapsedTime(String name, long elapsed) {
AudioNode ad = getAudio(name);
Stopwatch sw = getStopwatch(ad);
ad.setTimeOffset(elapsed / 1000);
sw.reset(elapsed);

}

public Stopwatch getStopwatch(AudioNode ad) {
return stopwatchList.get(audioNode.getChildIndex(ad));
}

public AudioNode getAudio(String name) {
return (AudioNode) audioNode.getChild(name);
}
}
[/java]

The stopwatch can be found here :P http://hub.jmonkeyengine.org/groups/beta-1-game-contest/forum/topic/wip-tilting-ball-maze-game-in-3d-contest-entry/?topic_page=3&num=15#post-156478