List of usage examples for javax.sound.sampled FloatControl setValue
public void setValue(float newValue)
From source file:Main.java
public static void main(String[] argv) throws Exception { DataLine.Info info = null;//w ww . j a v a2 s. c o m Clip clip = (Clip) AudioSystem.getLine(info); FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); double gain = .5D; // number between 0 and 1 (loudest) float dB = (float) (Math.log(gain) / Math.log(10.0) * 20.0); gainControl.setValue(dB); BooleanControl muteControl = (BooleanControl) clip.getControl(BooleanControl.Type.MUTE); muteControl.setValue(true); muteControl.setValue(false); }
From source file:com.lfv.lanzius.application.SoundClip.java
public synchronized void setVolume(float volume) { if (stream != null && clip != null) { volume *= volumeAdjustment;/*w ww. ja v a 2s .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:fr.ritaly.dungeonmaster.audio.SoundSystem.java
private void play(final double angle, final double distance, final AudioClip clip) { if (clip == null) { throw new IllegalArgumentException("The given audio clip is null"); }/* w w w . jav a 2 s . c o m*/ if (!isInitialized()) { // On ne lve pas d'erreur pour les tests unitaires return; } if (log.isDebugEnabled()) { log.debug("Submitting new task ..."); } executorService.execute(new Runnable() { @Override public void run() { final Sound sound = sounds.get(clip.getSound()); if (sound == null) { throw new IllegalArgumentException("Unsupported sound <" + clip + ">"); } try { final Clip clip2 = (Clip) AudioSystem .getLine(new DataLine.Info(Clip.class, sound.getAudioFormat())); clip2.addLineListener(new LineListener() { @Override public void update(LineEvent event) { if (event.getType().equals(LineEvent.Type.STOP)) { clip2.close(); } } }); clip2.open(sound.getAudioFormat(), sound.getData(), 0, sound.getData().length); final DecimalFormat decimalFormat = new DecimalFormat("###.#"); // Pan dans [-1, +1] final FloatControl pan = (FloatControl) clip2.getControl(FloatControl.Type.PAN); if (!Double.isNaN(angle)) { final float p = (float) Math.sin(angle); if ((0 <= angle) && (angle <= Math.PI)) { // Son sur la gauche, pan positif pan.setValue(p); } else { // Son sur la droite, pan ngatif pan.setValue(p); } if (log.isDebugEnabled()) { log.debug("Angle = " + decimalFormat.format((angle / Math.PI) * 180) + " / Pan = " + decimalFormat.format(p * 100)); } } else { pan.setValue(0); } final double attenuation = Utils.attenuation(distance); if (log.isDebugEnabled()) { log.debug("Distance = " + distance + " / Attenuation = " + decimalFormat.format((attenuation * 100)) + "%"); } if (distance != 0) { // Gain dans [-30, 0] final FloatControl gain = (FloatControl) clip2.getControl(FloatControl.Type.MASTER_GAIN); gain.setValue((float) attenuation * -30); } clip2.loop(0); } catch (LineUnavailableException e) { throw new RuntimeException(e); } } }); if (log.isDebugEnabled()) { log.debug("Task submitted"); } }
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 w ww . ja va 2 s . c om 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; }
From source file:org.eclipse.smarthome.io.javasound.internal.JavaSoundAudioSink.java
@Override public void setVolume(final PercentType volume) throws IOException { if (volume.intValue() < 0 || volume.intValue() > 100) { throw new IllegalArgumentException("Volume value must be in the range [0,100]!"); }//from www. j a va 2 s. c om if (!isMac) { runVolumeCommand(new Closure() { @Override public void execute(Object input) { FloatControl volumeControl = (FloatControl) input; volumeControl.setValue(volume.floatValue() / 100f); } }); } else { Runtime.getRuntime() .exec(new String[] { "osascript", "-e", "set volume output volume " + volume.intValue() }); macVolumeValue = volume; } }
From source file:org.openhab.io.multimedia.actions.Audio.java
private static void setMasterVolumeJavaSound(final float volume) { runVolumeCommand(new Closure() { public void execute(Object input) { FloatControl volumeControl = (FloatControl) input; volumeControl.setValue(volume); }/* w w w .ja v a2s. c o m*/ }); }