Increasing volume in sounds?

Hi,

I'm quite new to the jME audio.* package and therefore I'm sorry for the question in the style "what's wrong with my code". But I can not figure out how to correctly play sound repeatedly (not in loop, but play boom on the first shot and another boom at the second one etc…) Always I play the sound for the next time it has higher volume then the previous one until it is at some maximum (1.0f supposedly).



This code is very easy and even though it makes that problem I described above. (pls do not refer to the code style:-). That IF statement simulates the repeated even when sound should be played - quick'n'dirty :))



package spaceWars.control.utils;

import java.net.URL;

import spaceWars.Const;

import com.jmex.audio.AudioSystem;
import com.jmex.audio.AudioTrack;
import com.jmex.audio.AudioTrack.TrackType;
import com.jmex.audio.MusicTrackQueue.RepeatType;

public class AudioTest {


   private AudioTrack sound;
   
   
   
   public void loadMusic() {
      AudioSystem audio = AudioSystem.getSystem();
      
       audio.getMusicQueue().setRepeatType(RepeatType.ALL);       
      
       //background music is the character voice from JME audio.* tests
       AudioTrack music1 = getMusic(AudioTest.class.getResource(Const.MUSIC + "CHAR_CRE_1.ogg"));                   
       audio.getMusicQueue().addTrack(music1);
      
       //sound is explosion from JME audio.* tests
       sound = getSFX(AudioTest.class.getResource(Const.SOUNDS + "explosion.ogg"));
      
   }
   
   public void playSound() {      
      sound.play();      
   }
   
   private AudioTrack getMusic(URL resource) {
        // Create a non-streaming, non-looping, relative sound clip.
        AudioTrack sound = AudioSystem.getSystem().createAudioTrack(resource, false);
        sound.setType(TrackType.MUSIC);
        sound.setRelative(true);
        sound.setTargetVolume(0.1f);
        sound.setLooping(false);
        return sound;
    }
   
   private AudioTrack getSFX(URL resource) {
      // Create a non-streaming, non-looping, positional sound clip.
      AudioTrack sound = AudioSystem.getSystem().createAudioTrack(resource, false);
      sound.setType(TrackType.POSITIONAL);
      sound.setRelative(false);
      sound.setVolume(0.1f);
      sound.setLooping(false);
      
      return sound;
   }
   
   /**
    * @param args
    */
   public static void main(String[] args) {
      AudioTest test = new AudioTest();
      test.loadMusic();
      
      AudioSystem.getSystem().getMusicQueue().play();
      
      long i = 0;
      while (true) {
         i++;         
         if (i >= 200000) {
            test.playSound();
            i = 0;
         }
         
         AudioSystem.getSystem().update();
      }

   }

}



When I launch this code. Background voice plays fine. I suppose that the first exposion has its volume fine too but the next one is much louder:-(.
Have you any ideas where the problem lies or how can I avoid it?

Thanks a lot

Add


sound.setTargetVolume(0.1f);


to your getSFX method.

Hi,

it works fine, thanks a lot!

Can you tell me where such information can I get from? To prevent another such simple-solved questions? I looked at those two tests in JME and there is not much info about using audio.* package and also the javadoc is nearly none for this package:-( I don't even know there is such method and what is the difference between volume and targetVolume? What it is good for? etc… You know what I mean. There can come up many such stupid questions such as mine above because of insufficient documentation:-( Or do I look at wrong places?



Thank once more for solving my problem