import javax.sound.sampled.*; AudioInputStream audioInputStream = AudioSystem.getAudioInputStream( new File("some_file.wav")); Clip clip = AudioSystem.getClip(); clip.open(audioInputStream); FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(-10.0f); // Reduce volume by 10 decibels. clip.start();
return dataLine.getControl(control);
FloatControl volumeControl = (FloatControl) sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN); volumeControl.setValue(100.0f);
try { Line line = mixer.getLine(lineInfo); FloatControl volCtrl = (FloatControl)line.getControl( FloatControl.Type.MASTER_GAIN); VolumeSlider vs = new VolumeSlider(volCtrl);
clip.getControl( FloatControl.Type.MASTER_GAIN );
import javax.sound.sampled.Clip; import javax.sound.sampled.FloatControl; ... private Clip clip public float getVolume() { FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); return (float) Math.pow(10f, gainControl.getValue() / 20f); } public void setVolume(float volume) { if (volume < 0f || volume > 1f) throw new IllegalArgumentException("Volume not valid: " + volume); FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(20f * (float) Math.log10(volume)); }
/** * Use the gain control to implement volume. */ protected static void adjustVolume (Line line, float vol) { FloatControl control = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN); // the only problem is that gain is specified in decibals, which is a logarithmic scale. // Since we want max volume to leave the sample unchanged, our // maximum volume translates into a 0db gain. float gain; if (vol == 0f) { gain = control.getMinimum(); } else { gain = (float) ((Math.log(vol) / Math.log(10.0)) * 20.0); } control.setValue(gain); //Log.info("Set gain: " + gain); }
/** * Set the pan value for the specified line. */ protected static void adjustPan (Line line, float pan) { try { FloatControl control = (FloatControl) line.getControl(FloatControl.Type.PAN); control.setValue(pan); } catch (Exception e) { log.debug("Cannot set pan on line: " + e); } }
/** * Use the gain control to implement volume. */ protected static void adjustVolume (Line line, float vol) { FloatControl control = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN); // the only problem is that gain is specified in decibals, which is a logarithmic scale. // Since we want max volume to leave the sample unchanged, our // maximum volume translates into a 0db gain. float gain; if (vol == 0f) { gain = control.getMinimum(); } else { gain = (float) ((Math.log(vol) / Math.log(10.0)) * 20.0); } control.setValue(gain); //Log.info("Set gain: " + gain); }
/** * Set the pan value for the specified line. */ protected static void adjustPan (Line line, float pan) { try { FloatControl control = (FloatControl) line.getControl(FloatControl.Type.PAN); control.setValue(pan); } catch (Exception e) { log.debug("Cannot set pan on line: " + e); } }
import java.io.File; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; import javax.sound.sampled.FloatControl; ... public static void main(String[] args) { try { Clip clip = AudioSystem.getClip(); File file = new File("[Some *.wav file]"); AudioInputStream stream = AudioSystem.getAudioInputStream(file); clip.open(stream); // Control the volume FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(-20.0f); clip.start(); // The clip won't keep the JVM up if you reach the "end" // so the sleep is merely to let it play in the demo Thread.sleep(1000); clip.close(); } catch(Exception e) { e.printStackTrace(); } }
FloatControl volumeControl = (FloatControl) outline.getControl(FloatControl.Type.VOLUME); System.out.println(" volume: " + volumeControl.getValue() ); float v = 0.33F;
line.open(); if(line.isControlSupported(FloatControl.Type.VOLUME)){ FloatControl control = (FloatControl) line.getControl(FloatControl.Type.VOLUME); System.out.println("Volume:"+control.getValue()); JProgressBar pb = new JProgressBar();
sourceDataLine.start(); FloatControl volumeControl = (FloatControl) sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN); volumeControl.setValue(1.00f);
line.open(); } catch (IllegalArgumentException iae) {} return (FloatControl) line.getControl(FloatControl.Type.VOLUME);
public void run() { final FloatControl control = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
FloatControl gainControl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(gain);
line.open(); if(line.isControlSupported(FloatControl.Type.VOLUME)){ FloatControl control = (FloatControl) line.getControl(FloatControl.Type.VOLUME); System.out.println("Volume:"+control.getValue()); JProgressBar pb = new JProgressBar();
play.addLineListener(listener); play.open(audioInputStream); FloatControl volume = (FloatControl) play.getControl(FloatControl.Type.MASTER_GAIN); volume.setValue(1.0f); // Reduce volume by 10 decibels. play.start();
.getControl(FloatControl.Type.PAN); if (curPosition == Position.RIGHT) pan.setValue(1.0f);