本文整理汇总了Java中javax.sound.sampled.FloatControl.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java FloatControl.getValue方法的具体用法?Java FloatControl.getValue怎么用?Java FloatControl.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.sampled.FloatControl
的用法示例。
在下文中一共展示了FloatControl.getValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValue
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
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;
}
示例2: setVolume
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
@Override
public void setVolume(float volume) {
FloatControl control = (FloatControl)this.controls.get("Master Gain");
float min = control.getMinimum();
float max = control.getMaximum();
float oldVal = control.getValue();
float newVal = volume < min ? min : (volume > max ? max : volume);
control.setValue(newVal);
this.trigger(AudioEvent.Type.VOLUME_CHANGED, oldVal, newVal);
}
示例3: increaseSound
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
public static void increaseSound() {
if (isTreadAlive()) {
try {
gain = (FloatControl) radioPLayer.line.getControl(FloatControl.Type.MASTER_GAIN);
if (gain.getValue() < (gain.getMaximum() - 2.0F)) {
gain.setValue(gain.getValue() + 1.0F);
}
} catch (NullPointerException e) {
System.out.println("Sound System was still warming up");
}
}
}
示例4: decreaseSound
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
public static void decreaseSound() {
if (isTreadAlive()) {
try {
gain = (FloatControl) radioPLayer.line.getControl(FloatControl.Type.MASTER_GAIN);
if (gain.getValue() > (gain.getMinimum() + 2.0F)) {
gain.setValue(gain.getValue() - 1.0F);
}
} catch (NullPointerException e) {
System.out.println("Sound System was still warming up");
}
}
}
示例5: adjustMasterVolume
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
public static void adjustMasterVolume(float f) {
Mixer.Info[] mixers = AudioSystem.getMixerInfo();
for (Mixer.Info mixerInfo : mixers) {
Mixer mixer = AudioSystem.getMixer(mixerInfo);
Line.Info[] lineInfos = mixer.getTargetLineInfo();
for (Line.Info lineInfo : lineInfos) {
if (lineInfo.toString().toLowerCase().contains("pcm")) {
Line line = null;
boolean opened = true;
try {
line = mixer.getLine(lineInfo);
opened = line.isOpen() || line instanceof Clip;
if (!opened) {
line.open();
}
List<FloatControl> volumeControls = getVolumeControls(line);
for (FloatControl floatControl : volumeControls) {
float newVolume = floatControl.getValue() + f;
if (newVolume > 1.0) {
newVolume = 1.0F;
}
if (newVolume < 0.0) {
newVolume = 0.0F;
}
floatControl.setValue(newVolume);
}
} catch (LineUnavailableException e) {
e.printStackTrace();
} catch (IllegalArgumentException iaEx) {
System.out.println(" " + iaEx);
} finally {
if (line != null && !opened) {
line.close();
}
}
}
}
}
}
示例6: FloatControlBoundedRangeModel
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
public FloatControlBoundedRangeModel(FloatControl control) {
this.control = control;
float range = 100;
float steps = range / 100;
factor = range / steps;
int min = (int) (control.getMinimum() * factor);
int max = (int) (control.getMaximum() * factor);
int value = (int) (control.getValue() * factor);
setRangeProperties(value, 0, min, max, false);
}
示例7: setVolume
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
/**
* Sets the volume of the line.
* @param volume the volume
*/
public void setVolume(double volume) {
if (volume < MIN_VOLUME || volume > MAX_VOLUME) {
// if its not in range log a message and return
LOGGER.warn("Desired volume is out of range [" + volume + "]. Volume clamped.");
// clamp the value
if (volume < MIN_VOLUME) {
volume = MIN_VOLUME;
}
if (volume > MAX_VOLUME) {
volume = MAX_VOLUME;
}
}
// make sure the audio is still open
if (this.line != null) {
// calculate the new volume
double volumePercent = volume / MAX_VOLUME;
// determine what type of volume control to use
if (this.line.isControlSupported(FloatControl.Type.VOLUME)) {
// create the volume control
FloatControl volumeControl = (FloatControl) this.line.getControl(FloatControl.Type.VOLUME);
// compute the target volume
float tVolume = (float)volumePercent * volumeControl.getMaximum();
// only update the volume if it has changed
if (volumeControl.getValue() != volume) {
volumeControl.setValue(tVolume);
}
// log that the audio volume has been changed
LOGGER.debug("Volume changed using VOLUME contorl.");
} else if (this.line.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
// create the volume control
FloatControl gainControl = (FloatControl) this.line.getControl(FloatControl.Type.MASTER_GAIN);
// calculate the decible value
float dB = (float) (Math.log(volumePercent == 0.0 ? 0.0001 : volumePercent) / Math.log(10.0) * 20.0);
// only update the volume if it has changed
if (dB != gainControl.getValue()) {
gainControl.setValue(dB);
}
// log that the audio volume has been changed
LOGGER.debug("Volume changed using MASTER_GAIN contorl.");
} else {
LOGGER.warn("Volume control not supported.");
}
}
}
示例8: playAudioFile
import javax.sound.sampled.FloatControl; //导入方法依赖的package包/类
public static void playAudioFile(File file, int playDurationMillis)
{
try
{
// Get AudioInputStream from given file.
AudioInputStream compressedInput = AudioSystem.getAudioInputStream(file);
AudioInputStream decodedInput = null;
if (compressedInput != null)
{
AudioFormat baseFormat = compressedInput.getFormat();
AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16,
baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
// Get AudioInputStream that will be decoded by underlying VorbisSPI
decodedInput = AudioSystem.getAudioInputStream(format, compressedInput);
int oneSecondBytes = (int) Math.ceil(format.getFrameSize() * format.getFrameRate());
int fadeOutDurationBytes = oneSecondBytes / 20;
int playDurationBytes;
if (playDurationMillis <= 0)
playDurationBytes = Integer.MAX_VALUE;
else
playDurationBytes = oneSecondBytes * playDurationMillis / 1000;
byte[] data = new byte[1024];
SourceDataLine line = (SourceDataLine) AudioSystem.getLine(new DataLine.Info(SourceDataLine.class,
format));
line.open(format);
FloatControl gainControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);
float initialGain = gainControl.getValue();
// Start
line.start();
int bytesRead;
int totalBytes = 0;
while ((bytesRead = decodedInput.read(data, 0, data.length)) != -1)
{
totalBytes += bytesRead;
int playedBytes = totalBytes;
if (totalBytes >= playDurationBytes)
{
bytesRead -= totalBytes - playDurationBytes;
playedBytes = playDurationBytes;
}
if (playDurationBytes - playedBytes < fadeOutDurationBytes)
{
float fadePct = ((float) (playDurationBytes - playedBytes)) / fadeOutDurationBytes;
gainControl.setValue(initialGain * fadePct + gainControl.getMinimum() * (1.0f - fadePct));
}
line.write(data, 0, bytesRead);
if (totalBytes >= playDurationBytes)
break;
}
// Stop
line.drain();
gainControl.setValue(initialGain);
line.stop();
line.close();
decodedInput.close();
compressedInput.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}