当前位置: 首页>>代码示例>>Java>>正文


Java FloatControl.getValue方法代码示例

本文整理汇总了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;
}
 
开发者ID:JacobRoth,项目名称:romanov,代码行数:15,代码来源:Controller.java

示例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);
}
 
开发者ID:RalleYTN,项目名称:SimpleAudio,代码行数:12,代码来源:AbstractAudio.java

示例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");
        }
    }
}
 
开发者ID:Hoijima,项目名称:Fallout_Equestria,代码行数:14,代码来源:RadioThreadManager.java

示例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");
        }
    }
}
 
开发者ID:Hoijima,项目名称:Fallout_Equestria,代码行数:13,代码来源:RadioThreadManager.java

示例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();
          }
        }
      }
    }
  }
}
 
开发者ID:da-baumann,项目名称:dev,代码行数:41,代码来源:AudioControlUtil.java

示例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);
}
 
开发者ID:visit,项目名称:spark-svn-mirror,代码行数:11,代码来源:JavaMixer.java

示例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.");
		}
   	}
}
 
开发者ID:wnbittle,项目名称:praisenter,代码行数:49,代码来源:XugglerAudioPlayerThread.java

示例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();
	}
}
 
开发者ID:digero,项目名称:maestro,代码行数:71,代码来源:AudioPlayer.java


注:本文中的javax.sound.sampled.FloatControl.getValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。