0

プログラムの出力オーディオ レベルを、できればデシベル単位で変更しようとしています。プログラム全体のオーディオ レベルを変更し、レベルの変化を記録する必要があります。言語はJavaです。これを行う簡単な方法はありますか?サウンドを再生するために使用しているサウンドは次のとおりです。

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
4

1 に答える 1

0

JavaサウンドAPIを使用してMASTER_GAIN_CONTROLを使用できます

これをインポートする必要があります.... import javax.sound.sampled.*;

Clip オブジェクトを使用してクリップを取得してから、

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
于 2015-02-27T18:33:10.160 に答える