Java 类javax.sound.sampled.FloatControl 实例源码

项目:Java-Google-Speech-Recognizer    文件:AudioPlayer.java   
/**
 * Sets Gain value. Line should be opened before calling this method. Linear scale 0.0 <--> 1.0 Threshold Coef. : 1/2 to avoid saturation.
 * 
 * @param fGain
 */
public void setGain(float fGain) {

    // if (line != null)
    // System.out.println(((FloatControl)
    // line.getControl(FloatControl.Type.MASTER_GAIN)).getValue())

    // Set the value
    gain = fGain;

    // Better type
    if (line != null && line.isControlSupported(FloatControl.Type.MASTER_GAIN))
        ( (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN) ).setValue((float) ( 20 * Math.log10(fGain <= 0.0 ? 0.0000 : fGain) ));
    // OR (Math.log(fGain == 0.0 ? 0.0000 : fGain) / Math.log(10.0))

    // if (line != null)
    // System.out.println(((FloatControl)
    // line.getControl(FloatControl.Type.MASTER_GAIN)).getValue())
}
项目:Mafia    文件:AudioClip.java   
private void loadClip() {
    try {
        clip = AudioSystem.getClip();

        InputStream in = getClass().getClassLoader().getResourceAsStream(filePath);
        BufferedInputStream bufferedIn = new BufferedInputStream(in);
        AudioInputStream audioIn = AudioSystem.getAudioInputStream(bufferedIn);

        clip.open(audioIn);


        volume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
    } catch (LineUnavailableException | UnsupportedAudioFileException | IOException e) {
        e.printStackTrace();
        System.exit(-1);
    }
}
项目:opsu-dance    文件:MultiClip.java   
/**
 * Plays the clip with the specified volume.
 * @param volume the volume the play at
 * @param listener the line listener
 * @throws LineUnavailableException if a clip object is not available or
 *         if the line cannot be opened due to resource restrictions
 */
public void start(float volume, LineListener listener) throws LineUnavailableException {
    Clip clip = getClip();
    if (clip == null)
        return;

    // PulseAudio does not support Master Gain
    if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
        // set volume
        FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
        float dB = (float) (Math.log(volume) / Math.log(10.0) * 20.0);
        gainControl.setValue(dB);
    }

    if (listener != null)
        clip.addLineListener(listener);
    clip.setFramePosition(0);
    clip.start();
}
项目:opsu-dance    文件:MultiClip.java   
/**
* Mute the Clip (because destroying it, won't stop it)
*/
public void mute() {
    try {
        Clip c = getClip();
        if (c == null) {
            return;
        }
        float val = (float) (Math.log(Float.MIN_VALUE) / Math.log(10.0) * 20.0);
        if (val < -80.0f) {
            val = -80.0f;
        }
        ((FloatControl) c.getControl(FloatControl.Type.MASTER_GAIN)).setValue(val);
    } catch (IllegalArgumentException ignored) {
    } catch (LineUnavailableException e) {
        e.printStackTrace();
    }
}
项目:MercuryTrade    文件:SoundNotifier.java   
private void play(String wavPath, float db) {
    if (!dnd && db > -40) {
        ClassLoader classLoader = getClass().getClassLoader();
        try (AudioInputStream stream = AudioSystem.getAudioInputStream(classLoader.getResource(wavPath))) {
            Clip clip = AudioSystem.getClip();
            clip.open(stream);
            if (db != 0.0) {
                FloatControl gainControl =
                        (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
                gainControl.setValue(db);
            }
            clip.start();
        } catch (Exception e) {
            logger.error("Cannot start playing wav file: ", e);
        }
    }
}
项目:QwickSound    文件:PreloadedPlayback.java   
/**
 * Creates a new {@code PreloadedPlayback}. PreloadedPlayback objects will
 * always be created by their associated PreloadedAudio object.
 * <p>
 * IMPLEMENTATION NOTE: Originally, the fetching of a new {@code Line} was
 * done in the {@code run} method, however testing revealed that latency is
 * decreased if a {@code Line} is acquired ahead of time, here in the
 * constructor.
 * 
 * @param audio
 *            The {@code Audio} that created this {@code PreloadedPlayback}.
 * @param audioFormat
 *            Specifies the particular arrangement of audio data.
 * @param audioBytes
 *            Holds the audio data from which a {@code Clip} will be
 *            created.
 * @param instanceID
 *            The {@code instanceID} of this {@code PreloadedPlayback}.
 */
protected PreloadedPlayback(Audio audio, AudioFormat audioFormat,
        byte[] audioBytes, long instanceID) {
    super(audio, instanceID);
    DataLine.Info info = new DataLine.Info(Clip.class, audioFormat);
    try {
        clip = (Clip) AudioSystem.getLine(info);
        clip.open(audioFormat, audioBytes, 0, audioBytes.length);
        if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
            volCtrl = (FloatControl) clip
                    .getControl(FloatControl.Type.MASTER_GAIN);
        } else {
            logger.warning("Master-Gain control is not supported."
                    + " Volume will be fixed at the default level.");
        }
    } catch (LineUnavailableException ex) {
        ex.printStackTrace();
    }
    clip.addLineListener(this);
}
项目:QwickSound    文件:StreamingPlayback.java   
/**
 * Creates a new {@code StreamingPlayback}. StreamingPlayback objects will
 * always be created by their associated StreamingAudio object.
 *
 * @param audio
 *            The {@code Audio} that created this {@code StreamingPlayback}.
 * @param audioInStream
 *            The {@code AudioInputStream} used by this
 *            {@code StreamingPlayback}.
 * @param instanceID
 *            The {@code instanceID} of this {@code StreamingPlayback}.
 */
protected StreamingPlayback(Audio audio, AudioInputStream audioInStream,
        long instanceID) {

    super(audio, instanceID);
    this.audioInStream = audioInStream;

    AudioFormat audioFormat = audioInStream.getFormat();
    DataLine.Info info = new DataLine.Info(SourceDataLine.class,
            audioFormat);
    try {
        line = (SourceDataLine) AudioSystem.getLine(info);
        if (line != null) {
            line.open(audioFormat);
        }
        if (line.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
            volCtrl = (FloatControl) line
                    .getControl(FloatControl.Type.MASTER_GAIN);
        } else {
            logger.warning("Master-Gain control is not supported."
                    + " Volume will be fixed at the default level.");
        }
    } catch (LineUnavailableException ex) {
        ex.printStackTrace();
    }
}
项目:Side-Quest-City    文件:SoundClip.java   
public SoundClip(String path) {
    try {
        InputStream audioSrc = getClass().getResourceAsStream(path);
        InputStream bufferedIn = new BufferedInputStream(audioSrc);
        AudioInputStream ais = AudioSystem.getAudioInputStream(bufferedIn);
        AudioFormat baseFormat = ais.getFormat();
        AudioFormat decodeFormat = new AudioFormat(
                AudioFormat.Encoding.PCM_SIGNED,
                baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
                baseFormat.getChannels() * 2, baseFormat.getSampleRate(),
                false);
        AudioInputStream dais = AudioSystem.getAudioInputStream(decodeFormat, ais);

        clip = AudioSystem.getClip();
        clip.open(dais);

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

    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:MakamBox    文件:Player.java   
public void setPlayer(Wavefile af) throws Exception{
    clip = af.getClip();
       clip.open();
       fullLength = clip.getFrameLength();
       endPoint = fullLength;
       gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
       playing = false;
       clip.addLineListener(new LineListener(){
        @Override
        public void update(LineEvent arg0) {
            while(playing){
                int tempframe = clip.getFramePosition();
                MakamBoxAnalysis.positionSlide.setValue(tempframe);
                if (stopbutton!=null&&tempframe == fullLength){
                    stopbutton.doClick();
                } else if(stopbutton!=null && tempframe>=endPoint){
                    playAgain();
                } else if (tempframe == fullLength){
                    stop();
                }
            }
        }
       });
}
项目:raspberry-pi-api    文件:PlaySoundActionImpl.java   
@Override
public void invokeAction(final PiAction action) throws RaspberryPiAppException {
    final String soundFile = baseSoundDirectory + action.getValue();
    LOGGER.debug("Playing sound file: '{}'", soundFile);

    try {
        final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(
                new File(soundFile));
        final Clip clip = AudioSystem.getClip();
        clip.open(audioInputStream);

        // play at maximum volume
        final FloatControl gainControl =
                (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
        gainControl.setValue(gainControl.getMaximum());

        clip.start();

    } catch (Exception e) {
        throw new RaspberryPiAppException(e.getMessage(), e);
    }
}
项目:VN-RW    文件:VNSound.java   
/**
 * Constructor that starts off the VNSound tool with a sound at a certain volume. Will not loop.
 * 
 * @param file - the file path and name of the audio to play
 * @param volume - volume to play the file at
 */
public VNSound(File file, float volume) {
    try {
           audio = AudioSystem.getAudioInputStream(file); 
           clip = AudioSystem.getClip();
           clip.open(audio);
           volumeControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
           setVolume(volume);
           clip.start();
       }
       catch(UnsupportedAudioFileException uae) {
           System.out.println(uae);
       }
       catch(IOException ioe) {
           System.out.println(ioe);
       }
       catch(LineUnavailableException lua) {
           System.out.println(lua);
       }
}
项目:VN-RW    文件:VNSound.java   
/**
 * Opens a new sound and replaces the old one. If object is set to loop the sound (isLoop = true) then it will loop
 * 
 * @param file - the file path and name of the audio to play
 */
public void open(File file) {
    try {
        clip.stop();
           clip.close();
           audio = AudioSystem.getAudioInputStream(file);
           clip.open(audio);
        volumeControl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
           clip.start();
           if(isLoop)
            clip.loop(Clip.LOOP_CONTINUOUSLY);
           else
            clip.loop(0);
       }
       catch(UnsupportedAudioFileException uae) {
           System.out.println(uae);
       }
       catch(IOException ioe) {
           System.out.println(ioe);
           System.out.println(file);
       }
       catch(LineUnavailableException lua) {
           System.out.println(lua);
       }
}
项目:VN-RW    文件:VNSound.java   
/**
 * Will open a new file for a certain volume.
 * 
 * @param file - File of audio to open
 * @param volume - Volume of audio to play from 100 to 0
 */
public void open(File file, float volume) {
    try {
        clip.stop();
           clip.close();
           audio = AudioSystem.getAudioInputStream(file);
           clip.open(audio);
        volumeControl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
           setVolume(volume);
        clip.start();
           if(isLoop)
            clip.loop(Clip.LOOP_CONTINUOUSLY);
           else
            clip.loop(0);
       }
       catch(UnsupportedAudioFileException uae) {
           System.out.println(uae);
       }
       catch(IOException ioe) {
           System.out.println(ioe);
           System.out.println(file);
       }
       catch(LineUnavailableException lua) {
           System.out.println(lua);
       }
}
项目:BotLibre    文件:AudioPlayer.java   
/**
 * Sets Gain value. Line should be opened before calling this method. Linear scale 0.0 <--> 1.0 Threshold Coef. : 1/2 to avoid saturation.
 * 
 * @param fGain
 */
public void setGain(float fGain) {

    // if (line != null)
    // System.out.println(((FloatControl)
    // line.getControl(FloatControl.Type.MASTER_GAIN)).getValue())

    // Set the value
    gain = fGain;

    // Better type
    if (line != null && line.isControlSupported(FloatControl.Type.MASTER_GAIN))
        ( (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN) ).setValue((float) ( 20 * Math.log10(fGain <= 0.0 ? 0.0000 : fGain) ));
    // OR (Math.log(fGain == 0.0 ? 0.0000 : fGain) / Math.log(10.0))

    // if (line != null)
    // System.out.println(((FloatControl)
    // line.getControl(FloatControl.Type.MASTER_GAIN)).getValue())
}
项目:zmpp-wandora    文件:DefaultSoundEffect.java   
/**
 * Sets the volume.
 *
 * @param vol the volume
 */
private void setVolume(final int vol) {

    int volume = vol;
    if (volume < 0) {
        volume = MAX_VOLUME;
    }
    float gainDb = 0.0f;
    final FloatControl gain = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);

    if (volume == 0) {
        gainDb = gain.getMinimum();

    } else if (volume < MAX_VOLUME) {

  // The volume algorithm is subtractive: The implementation assumes that
        // the sound is already at maximum volume, so we avoid distortion by
        // making the amplitude values
        // The scaling factor for the volume would be 20 normally, but
        // it seems that 13 is better
        gainDb = (float) (Math.log10(MAX_VOLUME - volume) * 13.0);
    }
    gain.setValue(-gainDb);
}
项目:SoundCenterClient    文件:StationPlayer.java   
private void init(AudioFormat baseFormat) throws LineUnavailableException {

        decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
                baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat);
        line = (SourceDataLine) AudioSystem.getLine(info);
        line.open(decodedFormat);

        volumeControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);
        minGainDB = volumeControl.getMinimum();
        ampGainDB = ((10.0f / 20.0f) * volumeControl.getMaximum()) - volumeControl.getMinimum();
        cste = Math.log(10.0) / 20;

        //for stations we want to set the initial volume to 0
        volumeControl.setValue((float) minGainDB);

        line.start();

        //App.logger.d("prefix + WebPlayer SourceDataLine started!", null);
    }
项目:SoundCenterClient    文件:SingleSongPlayer.java   
private void init(AudioFormat baseFormat) throws LineUnavailableException {

        decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
                baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat);
        line = (SourceDataLine) AudioSystem.getLine(info);
        line.open(decodedFormat);

        volumeControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);
        minGainDB = volumeControl.getMinimum();
        ampGainDB = ((10.0f / 20.0f) * volumeControl.getMaximum()) - volumeControl.getMinimum();
        cste = Math.log(10.0) / 20;

        line.start();

        //App.logger.d("prefix + WebPlayer SourceDataLine started!", null);
    }
项目:SoundCenterClient    文件:VoicePlayer.java   
private void init() {
    AudioFormat speexFormat = new AudioFormat(16000, 16, 1, true, false);
    DataLine.Info sourceLineInfo = new DataLine.Info(SourceDataLine.class, speexFormat, bufferSize);
    speexDecoder.init(1, 16000, 1, false);
    try {
        line = (SourceDataLine) AudioSystem.getLine(sourceLineInfo);
        line.open(speexFormat, bufferSize);

        volumeControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);
        minGainDB = volumeControl.getMinimum();
        ampGainDB = ((10.0f / 20.0f) * volumeControl.getMaximum()) - volumeControl.getMinimum();
        cste = Math.log(10.0) / 20;

        volumeControl.setValue((float) minGainDB);

        line.start();

    } catch (LineUnavailableException e) {
        App.logger.w("Failed to create voice player (type: " + type + " id: " + playerId + "):" , e);
        if (!exit)
            close(false);
    }
}
项目:opsu    文件:MultiClip.java   
/**
 * Plays the clip with the specified volume.
 * @param volume the volume the play at
 * @param listener the line listener
 * @throws LineUnavailableException if a clip object is not available or
 *         if the line cannot be opened due to resource restrictions
 */
public void start(float volume, LineListener listener) throws LineUnavailableException {
    Clip clip = getClip();
    if (clip == null)
        return;

    // PulseAudio does not support Master Gain
    if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
        // set volume
        FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
        float dB = (float) (Math.log(volume) / Math.log(10.0) * 20.0);
        gainControl.setValue(Utils.clamp(dB, gainControl.getMinimum(), gainControl.getMaximum()));
    } else if (clip.isControlSupported(FloatControl.Type.VOLUME)) {
        // The docs don't mention what unit "volume" is supposed to be,
        // but for PulseAudio it seems to be amplitude
        FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.VOLUME);
        float amplitude = (float) Math.sqrt(volume) * volumeControl.getMaximum();
        volumeControl.setValue(Utils.clamp(amplitude, volumeControl.getMinimum(), volumeControl.getMaximum()));
    }

    if (listener != null)
        clip.addLineListener(listener);
    clip.setFramePosition(0);
    clip.start();
}
项目:PokerFace    文件:SoundEngine.java   
public void setVolume(float volume)
{
    float max = ((FloatControl)check.getControl(FloatControl.Type.MASTER_GAIN)).getMaximum();
    float min = ((FloatControl)check.getControl(FloatControl.Type.MASTER_GAIN)).getMinimum();

    volume = todB(volume);
    if (volume > max)
    {
        volume = max;
    }
    if (volume < min)
    {
        volume = min;
    }

    this.volume = volume;
    ((FloatControl)check.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume);
    ((FloatControl)call.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume);
    ((FloatControl)allin.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume);
    ((FloatControl)bet.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume);
    ((FloatControl)fold.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume);
    ((FloatControl)win.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume);
    ((FloatControl)lose.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume);
    ((FloatControl)raise.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume);
}
项目:GameUtils    文件:Sound.java   
/**
 * Plays the Clip. If the sound is off, the volume is set to the minimum.
 * @param name The name of the Clip to play.
 */
public void play(String name) {
    Clip c = get(name);

    if(c != null) {
        c.stop();
        c.flush();
        c.setFramePosition(0);

        if(!on) {
            FloatControl volume = (FloatControl)c.getControl(FloatControl.Type.MASTER_GAIN);
            volume.setValue(volume.getMinimum());
        }

        c.start();
    }
}
项目:GameUtils    文件:Sound.java   
/**
 * Loops the Clip. If the sound is off, the volume is set to the minimum.
 * @param name The name of the Clip to loop.
 */
public void loop(String name) {
    Clip c = get(name);

    if(c != null) {
        c.stop();
        c.flush();
        c.setFramePosition(0);

        if(!on) {
            FloatControl volume = (FloatControl)c.getControl(FloatControl.Type.MASTER_GAIN);
            volume.setValue(volume.getMinimum());
        }

        c.loop(Clip.LOOP_CONTINUOUSLY);
    }
}
项目:monkey-shines-java-port    文件:JavaDefaultSoundManager.java   
/**
 * 
 * Automatically called on construction and game setting change to match clip volume to
 * user defined levels.
 * 
 * @param value
 *      percentage to set music volume to
 * 
 */
private void setSoundVolume(int value) {
    if (value == 0) {
        soundOff = true;
        return;
    }

    soundOff = false;

    float decibelLevelOffset = SoundUtils.resolveDecibelOffsetFromPercentage(value);
    System.out.println("Decibel offset for sound: " + decibelLevelOffset);
    for (GameSoundEffect effect : GameSoundEffect.values() ) {
        Optional<Clip> clip = sounds.get(effect);
        if (clip.isPresent() ) {
            FloatControl gainControl = (FloatControl)
                clip.get().getControl(FloatControl.Type.MASTER_GAIN);
            gainControl.setValue(decibelLevelOffset);
        }
    }
}
项目:romanov    文件:Controller.java   
/** @invisible
 * 
 * Prints the available controls and their ranges to the console. Not all
 * Controllers have all of the controls available on them so this is a way to find
 * out what is available.
 * 
 */
public void printControls()
{
  if (controls.length > 0)
  {
    System.out.println("Available controls are:");
    for (int i = 0; i < controls.length; i++)
    {
      Control.Type type = controls[i].getType();
      System.out.print("  " + type.toString());
      if (type == VOLUME || type == GAIN || type == BALANCE || type == PAN)
      {
        FloatControl fc = (FloatControl) controls[i];
        String shiftSupported = "does";
        if (fc.getUpdatePeriod() == -1)
        {
          shiftSupported = "doesn't";
        }
        System.out.println(", which has a range of " + fc.getMaximum() + " to "
            + fc.getMinimum() + " and " + shiftSupported
            + " support shifting.");
      }
      else
      {
        System.out.println("");
      }
    }
  }
  else
  {
    System.out.println("There are no controls available.");
  }
}
项目:romanov    文件:Controller.java   
private float getValue(FloatControl.Type type)
{
  float v = 0;
  if (hasControl(type))
  {
    FloatControl c = (FloatControl) getControl(type);
    v = c.getValue();
  }
  else
  {
    Minim.error(type.toString() + " is not supported.");
  }
  return v;
}
项目:romanov    文件:Controller.java   
private void setValue(FloatControl.Type type, float v)
{
  if (hasControl(type))
  {
    FloatControl c = (FloatControl) getControl(type);
    if (v > c.getMaximum())
      v = c.getMaximum();
    else if (v < c.getMinimum()) v = c.getMinimum();
    c.setValue(v);
  }
  else
  {
    Minim.error(type.toString() + " is not supported.");
  }
}
项目:airsonic    文件:AudioPlayer.java   
public AudioPlayer(InputStream in, Listener listener) throws Exception {
    this.in = in;
    this.listener = listener;

    AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100.0F, 16, 2, 4, 44100.0F, true);
    line = AudioSystem.getSourceDataLine(format);
    line.open(format);
    LOG.debug("Opened line " + line);

    if (line.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
        gainControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);
        setGain(DEFAULT_GAIN);
    }
    new AudioDataWriter();
}
项目:JuggleMasterPro    文件:ExtendedClip.java   
final public float getVolume(int intPvolumePercentage) throws Throwable {

        if (this.objGclip != null && this.objGclip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
            final FloatControl objLvolumeFloatControl = (FloatControl) this.objGclip.getControl(FloatControl.Type.MASTER_GAIN);
            final float fltLrange = (objLvolumeFloatControl.getMaximum() - objLvolumeFloatControl.getMinimum()) * 1.2F;
            return Math.min(fltLrange * Math.max(0, intPvolumePercentage) / 100.0F + objLvolumeFloatControl.getMinimum(),
                            objLvolumeFloatControl.getMaximum());
        }
        throw new Throwable();
    }
项目:JuggleMasterPro    文件:ExtendedClip.java   
final public void setBalance(int intPbalancePercentage) {

        if (this.objGclip != null && this.objGclip.isControlSupported(FloatControl.Type.PAN)) {
            try {
                final FloatControl objLbalanceFloatControl = (FloatControl) this.objGclip.getControl(FloatControl.Type.PAN);
                objLbalanceFloatControl.setValue(Math.max(-100, Math.min(intPbalancePercentage, 100)) / 100.0F);
            } catch (final Throwable objPthrowable) {
                Tools.err("Error while setting sound balance : ", Constants.strS_FILE_SOUND_NAME_A[this.bytGsoundFileIndex]);
            }
        }
    }
项目:JuggleMasterPro    文件:ExtendedClip.java   
final public void setVolume(int intPvolumePercentage) {

        try {
            final float fltLvolume = this.getVolume(intPvolumePercentage);
            final FloatControl objLvolumeFloatControl = (FloatControl) this.objGclip.getControl(FloatControl.Type.MASTER_GAIN);
            objLvolumeFloatControl.setValue(fltLvolume);
        } catch (final Throwable objPthrowable) {
            Tools.err("Error while setting sound volume : ", Constants.strS_FILE_SOUND_NAME_A[this.bytGsoundFileIndex]);
        }
    }
项目:openjdk-jdk10    文件:DirectAudioDevice.java   
private Gain() {

                super(FloatControl.Type.MASTER_GAIN,
                      Toolkit.linearToDB(0.0f),
                      Toolkit.linearToDB(2.0f),
                      Math.abs(Toolkit.linearToDB(1.0f)-Toolkit.linearToDB(0.0f))/128.0f,
                      -1,
                      0.0f,
                      "dB", "Minimum", "", "Maximum");
            }
项目:openjdk-jdk10    文件:ClipOpenBug.java   
public static void main(String args[]) throws Exception {
    boolean res = true;
    try {
        AudioInputStream ais = new AudioInputStream(
                new ByteArrayInputStream(new byte[2000]),
                new AudioFormat(8000.0f, 8, 1, false, false), 2000); //
        AudioFormat format = ais.getFormat();
        DataLine.Info info = new DataLine.Info(Clip.class, format,
                                               ((int) ais.getFrameLength()
                                                        * format
                                                       .getFrameSize()));
        Clip clip = (Clip) AudioSystem.getLine(info);
        clip.open();
        FloatControl rateControl = (FloatControl) clip.getControl(
                FloatControl.Type.SAMPLE_RATE);
        int c = 0;
        while (c++ < 10) {
            clip.stop();
            clip.setFramePosition(0);
            clip.start();
            for (float frq = 22000; frq < 44100; frq = frq + 100) {
                try {
                    Thread.currentThread().sleep(20);
                } catch (Exception e) {
                    break;
                }
                rateControl.setValue(frq);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        res = ex.getMessage().indexOf(
                "This method should not have been invoked!") < 0;
    }
    if (res) {
        System.out.println("Test passed");
    } else {
        System.out.println("Test failed");
        throw new Exception("Test failed");
    }
}
项目:SimpleAudio    文件:AbstractAudio.java   
@Override
public void setVolume(float volume) {

    FloatControl control = (FloatControl)this.controls.get("Master Gain");
    float min = control.getMinimum();
    float max = control.getMaximum();
    float oldVal = control.getValue();
    float newVal = volume < min ? min : (volume > max ? max : volume);
    control.setValue(newVal);
    this.trigger(AudioEvent.Type.VOLUME_CHANGED, oldVal, newVal);
}
项目:SimpleAudio    文件:AbstractAudio.java   
@Override
public void setBalance(float balance) {

    FloatControl balanceControl = (FloatControl)this.controls.get("Balance");
    float max = balanceControl.getMaximum();
    float min = balanceControl.getMinimum();
    balanceControl.setValue(balance < min ? min : (balance > max ? max : balance));
}
项目:Device-Mod-Apps    文件:ApplicationMusicPlayer.java   
public void play() {
    if (clip != null) {
        if (progress != null) {
            progress.setMax((int) clip.getMicrosecondLength());

            if (progressUpdateThread == null) {
                progressUpdateThread = new Thread("Progressbar Update Thread") {
                    @Override
                    public void run() {
                        while (!Thread.interrupted()) {
                            progress.setProgress((int) clip.getMicrosecondPosition()); // /1000000
                        }
                    }
                };

                progressUpdateThread.start();
            }
        }

        float volume = Minecraft.getMinecraft().gameSettings.getSoundLevel(SoundCategory.RECORDS);
        FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);        
        gainControl.setValue(20f * (float) Math.log10(volume));

        Minecraft.getMinecraft().getSoundHandler().stopSounds();
        if (isAlive()) {
            clip.start();
        } else {
            start();
        }
    } else {
        Minecraft mc = Minecraft.getMinecraft();

        mc.getSoundHandler().stopSounds();
        mc.getSoundHandler().playSound(listedSong.ps);

        start();
    }
}
项目:java-stream-player    文件:StreamPlayer.java   
/**
 * Sets Pan value. Line should be opened before calling this method. Linear scale : -1.0 ... +1.0
 *
 * @param fPan
 *            the new pan
 */
public void setPan(double fPan) {

    if (!hasControl(FloatControl.Type.PAN, panControl) || fPan < -1.0 || fPan > 1.0)
        return;
    logger.info(() -> "Pan : " + fPan);
    panControl.setValue((float) fPan);
    generateEvent(Status.PAN, getEncodedStreamPosition(), null);

}
项目:java-stream-player    文件:StreamPlayer.java   
/**
 * Represents a control for the relative balance of a stereo signal between two stereo speakers. The valid range of values is -1.0 (left channel
 * only) to 1.0 (right channel only). The default is 0.0 (centered).
 *
 * @param fBalance
 *            the new balance
 */
public void setBalance(float fBalance) {
    if (hasControl(FloatControl.Type.BALANCE, balanceControl) && fBalance >= -1.0 && fBalance <= 1.0)
        balanceControl.setValue(fBalance);
    else
        try {
            throw new StreamPlayerException(StreamPlayerException.PlayerException.BALANCE_CONTROL_NOT_SUPPORTED);
        } catch (StreamPlayerException ex) {
            logger.log(Level.WARNING, ex.getMessage(), ex);
        }
}
项目:group-10    文件:Sound.java   
public Sound(String dir) {
    try {
        URL url = getClass().getResource(dir);
        AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url);
        clip = AudioSystem.getClip();
        clip.open(audioInputStream);
        gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
    } catch (Exception e) {
    }
}
项目:group-10    文件:Sound.java   
public Sound(String dir) {
    try {
        URL url = getClass().getResource(dir);
        AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url);
        clip = AudioSystem.getClip();
        clip.open(audioInputStream);
        gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
    } catch (Exception e) {
    }
}
项目:subsonic    文件:AudioPlayer.java   
public AudioPlayer(InputStream in, Listener listener) throws Exception {
    this.in = in;
    this.listener = listener;

    AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100.0F, 16, 2, 4, 44100.0F, true);
    line = AudioSystem.getSourceDataLine(format);
    line.open(format);
    LOG.debug("Opened line " + line);

    if (line.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
        gainControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);
        setGain(DEFAULT_GAIN);
    }
    new AudioDataWriter();
}