java类javax.sound.sampled.FloatControl的实例源码

AudioPlayer.java 文件源码 项目:Java-Google-Speech-Recognizer 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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())
}
AudioClip.java 文件源码 项目:Mafia 阅读 20 收藏 0 点赞 0 评论 0
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);
    }
}
MultiClip.java 文件源码 项目:opsu-dance 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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();
}
MultiClip.java 文件源码 项目:opsu-dance 阅读 24 收藏 0 点赞 0 评论 0
/**
* 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();
    }
}
SoundNotifier.java 文件源码 项目:MercuryTrade 阅读 18 收藏 0 点赞 0 评论 0
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);
        }
    }
}
PreloadedPlayback.java 文件源码 项目:QwickSound 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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);
}
StreamingPlayback.java 文件源码 项目:QwickSound 阅读 17 收藏 0 点赞 0 评论 0
/**
 * 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();
    }
}
SoundClip.java 文件源码 项目:Side-Quest-City 阅读 17 收藏 0 点赞 0 评论 0
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();
    }
}
Player.java 文件源码 项目:MakamBox 阅读 32 收藏 0 点赞 0 评论 0
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();
                }
            }
        }
       });
}
PlaySoundActionImpl.java 文件源码 项目:raspberry-pi-api 阅读 18 收藏 0 点赞 0 评论 0
@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);
    }
}
VNSound.java 文件源码 项目:VN-RW 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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);
       }
}
VNSound.java 文件源码 项目:VN-RW 阅读 16 收藏 0 点赞 0 评论 0
/**
 * 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);
       }
}
VNSound.java 文件源码 项目:VN-RW 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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);
       }
}
AudioPlayer.java 文件源码 项目:BotLibre 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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())
}
DefaultSoundEffect.java 文件源码 项目:zmpp-wandora 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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);
}
StationPlayer.java 文件源码 项目:SoundCenterClient 阅读 18 收藏 0 点赞 0 评论 0
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);
    }
SingleSongPlayer.java 文件源码 项目:SoundCenterClient 阅读 15 收藏 0 点赞 0 评论 0
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);
    }
VoicePlayer.java 文件源码 项目:SoundCenterClient 阅读 18 收藏 0 点赞 0 评论 0
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);
    }
}
MultiClip.java 文件源码 项目:opsu 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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();
}
SoundEngine.java 文件源码 项目:PokerFace 阅读 50 收藏 0 点赞 0 评论 0
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);
}
Sound.java 文件源码 项目:GameUtils 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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();
    }
}
Sound.java 文件源码 项目:GameUtils 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
JavaDefaultSoundManager.java 文件源码 项目:monkey-shines-java-port 阅读 68 收藏 0 点赞 0 评论 0
/**
 * 
 * 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);
        }
    }
}
Controller.java 文件源码 项目:romanov 阅读 20 收藏 0 点赞 0 评论 0
/** @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.");
  }
}
Controller.java 文件源码 项目:romanov 阅读 28 收藏 0 点赞 0 评论 0
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;
}
Controller.java 文件源码 项目:romanov 阅读 31 收藏 0 点赞 0 评论 0
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.");
  }
}
AudioPlayer.java 文件源码 项目:airsonic 阅读 29 收藏 0 点赞 0 评论 0
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();
}
ExtendedClip.java 文件源码 项目:JuggleMasterPro 阅读 19 收藏 0 点赞 0 评论 0
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();
    }
ExtendedClip.java 文件源码 项目:JuggleMasterPro 阅读 19 收藏 0 点赞 0 评论 0
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]);
            }
        }
    }
ExtendedClip.java 文件源码 项目:JuggleMasterPro 阅读 21 收藏 0 点赞 0 评论 0
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]);
        }
    }


问题


面经


文章

微信
公众号

扫码关注公众号