Sound handling in (game) application

As my previous question did not receive any answers, I'll try to rephrase it.

I need to change the volume of sounds during the game (changing pitch would be nice too). I tried to use:

double currentVolume, volumeGain=.01, newVolume;

FloatControl gainControl = (FloatControl)clipP1.getControl(FloatControl.Type.MASTER_GAIN);

currentVolume=Math.log(gainControl.getValue())*Math.log(10.0)/20.0;

newVolume = currentVolume + volumeGain;

gainControl.setValue((float)(Math.log(newVolume)/Math.log(10.0)*20.0));

The volume increase/decrease itself worked, but it was always delayed about 0.4-1.0 seconds. That is not acceptable.

Any workarounds or do I have to use another library to achieve this?

Thank You!

[828 byte] By [gwegrwergwra] at [2007-11-27 11:13:31]
# 1

I know little about the sound library, but I have a chunk of code that was edited from someone else. It might be faster, but I don't know. It also needs to be supported (obviously), so it may not even work (my game's sound was kind of buggy).

vol is an integer with linear scaling, I believe.

if (soundClip.isControlSupported(FloatControl.Type.VOLUME)){

FloatControl volumeControl = (FloatControl) soundClip.getControl(FloatControl.Type.VOLUME);

volumeControl.setValue(vol);

}

eitomuraa at 2007-7-29 14:01:22 > top of Java-index,Other Topics,Java Game Development...
# 2

Nope.. Unfortunately I get:

"Unsupported control type: Volume at com.sun.media.sound.AbstractLine.getControl(Unknown Source)"..

But thanks :)

gwegrwergwra at 2007-7-29 14:01:22 > top of Java-index,Other Topics,Java Game Development...