use of javax.sound.sampled.FloatControl in project playn by threerings.
the class JavaSound method setVolumeImpl.
@Override
protected void setVolumeImpl(float volume) {
if (impl.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
FloatControl volctrl = (FloatControl) impl.getControl(FloatControl.Type.MASTER_GAIN);
volctrl.setValue(toGain(volume, volctrl.getMinimum(), volctrl.getMaximum()));
}
}
use of javax.sound.sampled.FloatControl in project lionengine by b3dgs.
the class WavImpl method updateVolume.
/**
* Update the sound volume.
*
* @param dataLine Audio source data.
* @param volume The audio playback volume value.
*/
private static void updateVolume(DataLine dataLine, int volume) {
if (dataLine.isControlSupported(Type.MASTER_GAIN)) {
final FloatControl gainControl = (FloatControl) dataLine.getControl(Type.MASTER_GAIN);
final double gain = UtilMath.clamp(volume / 100.0, 0.0, 100.0);
final double dB = Math.log(gain) / Math.log(10.0) * 20.0;
gainControl.setValue((float) dB);
}
}
use of javax.sound.sampled.FloatControl in project smarthome by eclipse.
the class JavaSoundAudioSink method getVolume.
@Override
public PercentType getVolume() throws IOException {
if (!isMac) {
final Float[] volumes = new Float[1];
runVolumeCommand(new Closure() {
@Override
public void execute(Object input) {
FloatControl volumeControl = (FloatControl) input;
volumes[0] = volumeControl.getValue();
}
});
if (volumes[0] != null) {
return new PercentType(new BigDecimal(volumes[0] * 100f));
} else {
throw new IOException("Cannot determine master volume level");
}
} else {
// we use a cache of the value as the script execution is pretty slow
if (macVolumeValue == null) {
Process p = Runtime.getRuntime().exec(new String[] { "osascript", "-e", "output volume of (get volume settings)" });
String value = IOUtils.toString(p.getInputStream()).trim();
macVolumeValue = new PercentType(value);
}
return macVolumeValue;
}
}
use of javax.sound.sampled.FloatControl in project smarthome by eclipse.
the class JavaSoundAudioSink method runVolumeCommand.
private void runVolumeCommand(Closure closure) {
Mixer.Info[] infos = AudioSystem.getMixerInfo();
for (Mixer.Info info : infos) {
Mixer mixer = AudioSystem.getMixer(info);
if (mixer.isLineSupported(Port.Info.SPEAKER)) {
Port port;
try {
port = (Port) mixer.getLine(Port.Info.SPEAKER);
port.open();
if (port.isControlSupported(FloatControl.Type.VOLUME)) {
FloatControl volume = (FloatControl) port.getControl(FloatControl.Type.VOLUME);
closure.execute(volume);
}
port.close();
} catch (LineUnavailableException e) {
logger.error("Cannot access master volume control", e);
}
}
}
}
use of javax.sound.sampled.FloatControl in project smarthome by eclipse.
the class JavaSoundAudioSink method setVolume.
@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]!");
}
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;
}
}
Aggregations