Code example for SourceDataLine

Methods: getControl

0
	 * @param mute the mute state to set. 
	 */	 
	public void setMute(boolean mute) {
		this.mute = mute;
		if(sourceDataLine != null) {
			BooleanControl muteCtrl = (BooleanControl)sourceDataLine.getControl(BooleanControl.Type.MUTE);			
			muteCtrl.setValue(mute);
			if(!mute) {
				setVolume(volume);
			} 
		} 
	} 
	 
	/** 
	 * Sets the volume of the audio stream. 
	 * @param volume the volume to set. 
	 */	 
	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);
		} 
	}