當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。