Java 8 FloatControl - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 FloatControl class.

This code example shows how to use the following methods:getMaximum, getMinimum
    /** 
     * Gets max Gain value. 
     */ 
    public float getMaximumGain() { 
        if (hasGainControl()) { 
            return gainControl.getMaximum();
        } else { 
            return 0.0F; 
        } 
    } 
 
    /** 
     * Gets min Gain value. 
     */ 
    public float getMinimumGain() { 
        if (hasGainControl()) { 
            return gainControl.getMinimum();
        } else { 
            return 0.0F; 
        } 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getMaximum, getMinimum, setValue
 
    public void setLineGain(float gain) {
        if (source != null) {
            if (source.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
                FloatControl volControl = (FloatControl) source.getControl(FloatControl.Type.MASTER_GAIN);
                float newGain = Math.min(Math.max(gain, volControl.getMinimum()), volControl.getMaximum());
 
                volControl.setValue(newGain);
            } 
        } 
    } 
     
    public float getMaxGain() { 
//        boolean test = false; 
//        try { 
//            if (source == null) { 
//                test = true; 
//                if(testSource == null) { 
//                    test(); 
//                    createSource2(false); 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getMaximum, getMinimum, setValue
    } 
     
    public void setVolume(double percentage) {
        if (volumeControl != null) {
        	if (log.isTraceEnabled()) 
        		log.trace("setVolume(): max=" + volumeControl.getMaximum() + ", min=" + volumeControl.getMinimum());
        	float max = Math.min(volumeControl.getMaximum(), 0.0f);
        	float min = Math.max(volumeControl.getMinimum(), -20.0f);
            float range = max - min;         
            if (percentage == 0.0)
            	volumeControl.setValue(volumeControl.getMinimum());
            else 
            	volumeControl.setValue((float)(range * percentage + min));
        } 
    } 
     
    public void setCallBack(PlayerCallBack callBack) {
        this.callBack = callBack;
    } 
     
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setValue
 
	private static void setMasterVolumeJavaSound(final float volume) {
		runVolumeCommand(new Closure() { 
			public void execute(Object input) { 
				FloatControl volumeControl = (FloatControl) input;
				volumeControl.setValue(volume);
			} 
		}); 
	} 
 
	@ActionDoc(text="increases the master volume of the host") 
	static public void increaseMasterVolume(@ParamDoc(name="percent") final float percent) throws IOException {
		if(percent<=0 || percent>100) {
			throw new IllegalArgumentException("Percent must be in the range (0,100]!");
		} 
		Float volume = getMasterVolume();
		if(volume==0) {
			// as increasing 0 by x percent will still be 0, we have to set some initial positive value 
			volume = 0.001f;
		} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getMaximum, getMinimum, setValue
  private void setValue(FloatControl.Type type, float v)
  { 
    if (hasControl(type))
    { 
      FloatControl c = (FloatControl) getControl(type);
      if (v > c.getMaximum())
        v = c.getMaximum();
      else if (v < c.getMinimum()) v = c.getMinimum();
      c.setValue(v);
    } 
    else 
    { 
      Minim.error(type.toString() + " is not supported.");
    } 
  } 
 
  /** 
   * Returns the current volume. If a volume control is not available, this 
   * returns 0. Note that the volume is not the same thing as the 
   * <code>level()</code> of an AudioBuffer! 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setValue
			// PulseAudio does not support Master Gain 
			if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
				// set volume 
				FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
				float dB = (float) (Math.log(volume) / Math.log(10.0) * 20.0);
				gainControl.setValue(dB);
			} 
 
			// play clip 
			clip.setFramePosition(0);
			clip.start();
		} 
	} 
 
	/** 
	 * Plays a sound. 
	 * @param sound the sound (SOUND_* constant) 
	 */ 
	public static void playSound(int sound) {
		if (sound < 0 || sound >= SOUND_MAX)
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setValue
	public void setVolume(int volume){
		this.volume = volume;
		if((sourceDataLine != null) && !mute) {
			FloatControl volumeCtrl = (FloatControl)sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN);
			float GainDb = (float)(20.d * Math.log(volume == 0 ? Double.MIN_VALUE: ((double)volume / 100.d)) / Math.log(10));      
			volumeCtrl.setValue(GainDb);
		} 
	} 
	 
	/** 
	 * Returns <tt>true</tt>, if the audio device is opened, <tt>false</tt> otherwise. 
	 */ 
	public boolean isOpened() { 
		return opened;
	} 
	 
	/** 
	 * Returns <tt>true</tt>, if the audio device is ready to play the audio stream, <tt>false</tt> otherwise. 
	 */ 
	public boolean isReady() { 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getValue
	private static float getMasterVolumeJavaSound() throws IOException {
		final Float[] volumes = new Float[1];
		runVolumeCommand(new Closure() { 
			public void execute(Object input) { 
				FloatControl volumeControl = (FloatControl) input;
				volumes[0] = volumeControl.getValue();
			} 
		}); 
		if(volumes[0]!=null) {
			return volumes[0];
		} else { 
			throw new IOException("Cannot determine master volume level");
		} 
	} 
 
	private static 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)) {
3
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 FloatControl Methods: