0

I am trying to change the output audio levels of the program, preferably in decibels. I need to change the audio levels of the entire program and record the change in the level. The language is Java. Is there any easy way to do this? The sounds I am using to play the sounds is below:

import java.io.InputStream;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;


public class Sound 
{
    String sounds;
    public Sound(String file)
    {
        sounds = file;
        playSound(sounds);
    }//end contructor

    public void playSound(String soundLoc)
    {  
        try
        {
            InputStream inputStream = getClass().getResourceAsStream(soundLoc);
            AudioStream audioStream = new AudioStream(inputStream);
            AudioPlayer.player.start(audioStream);
        }//end try

        catch (Exception e)
        {
        }//end catch
    }//end playSound method
}//end class Sound
  • You could use the Java Sound API. Maybe [this](http://stackoverflow.com/questions/953598/audio-volume-control-increase-or-decrease-in-java) helps – fishi0x01 Feb 27 '15 at 18:30

1 Answers1

0

You can use MASTER_GAIN_CONTROL using the Java sound API

you need to import this.... import javax.sound.sampled.*;

get your clip using a Clip object and then,

public void playSound(String soundLoc)
    {  
        try
        {
            InputStream inputStream = getClass().getResourceAsStream(soundLoc);
            AudioStream audioStream = new AudioStream(inputStream);
            AudioPlayer.player.start(audioStream);
            Clip myclip = AudioSystem.getClip();
            myclip.open(audioStream);
            FloatControl audioControl = (FloatControl) myclip.getControl(FloatControl.Type.MASTER_GAIN);
             audioControl.setValue(-5.0f); //decrease volume 5 decibels
             clip.start();
        }//end try

        catch (Exception e)
        {
        }//end catch
    }//end playSound method
BDRSuite
  • 1,594
  • 1
  • 10
  • 15