Example usage for javax.sound.sampled FloatControl getMinimum

List of usage examples for javax.sound.sampled FloatControl getMinimum

Introduction

In this page you can find the example usage for javax.sound.sampled FloatControl getMinimum.

Prototype

public float getMinimum() 

Source Link

Document

Obtains the minimum value permitted.

Usage

From source file:com.lfv.lanzius.application.SoundClip.java

public synchronized void setVolume(float volume) {
    if (stream != null && clip != null) {
        volume *= volumeAdjustment;/*from  www . j a  v  a 2  s.c o m*/
        if (volume < 0.0001f)
            volume = 0.0001f;
        float gain_dB = (float) (20.0 * Math.log10(volume));
        FloatControl ctrl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
        gain_dB = Math.max(gain_dB, ctrl.getMinimum());
        gain_dB = Math.min(gain_dB, ctrl.getMaximum());
        ctrl.setValue(gain_dB);
    }
}

From source file:SoundPlayer.java

JSlider createSlider(final FloatControl c) {
    if (c == null)
        return null;
    final JSlider s = new JSlider(0, 1000);
    final float min = c.getMinimum();
    final float max = c.getMaximum();
    final float width = max - min;
    float fval = c.getValue();
    s.setValue((int) ((fval - min) / width * 1000));

    java.util.Hashtable labels = new java.util.Hashtable(3);
    labels.put(new Integer(0), new JLabel(c.getMinLabel()));
    labels.put(new Integer(500), new JLabel(c.getMidLabel()));
    labels.put(new Integer(1000), new JLabel(c.getMaxLabel()));
    s.setLabelTable(labels);//from ww w .  j av  a2 s  .  com
    s.setPaintLabels(true);

    s.setBorder(new TitledBorder(c.getType().toString() + " " + c.getUnits()));

    s.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            int i = s.getValue();
            float f = min + (i * width / 1000.0f);
            c.setValue(f);
        }
    });
    return s;
}