Package org.jitsi.service.neomedia
Class BasicVolumeControl
- java.lang.Object
-
- org.jitsi.service.neomedia.BasicVolumeControl
-
- All Implemented Interfaces:
javax.media.Control,javax.media.GainControl,VolumeControl
- Direct Known Subclasses:
HardwareVolumeControl
public class BasicVolumeControl extends Object implements VolumeControl, javax.media.GainControl
Provides a basic implementation of VolumeControl which stores the volume level/value set on it in the ConfigurationService.- Author:
- Damian Minkov, Lyubomir Marinov
-
-
Field Summary
Fields Modifier and Type Field Description protected static floatMAX_VOLUME_LEVELThe maximum volume level accepted by AbstractVolumeControl.static intMAX_VOLUME_PERCENTThe maximum volume level expressed in percent accepted by AbstractVolumeControl.protected static floatMIN_VOLUME_LEVELThe minimum volume level accepted by AbstractVolumeControl.static intMIN_VOLUME_PERCENTThe minimum volume level expressed in percent accepted by AbstractVolumeControl.protected floatvolumeLevelThe current volume level.-
Fields inherited from interface org.jitsi.service.neomedia.VolumeControl
CAPTURE_VOLUME_LEVEL_PROPERTY_NAME, PLAYBACK_VOLUME_LEVEL_PROPERTY_NAME
-
-
Constructor Summary
Constructors Constructor Description BasicVolumeControl(String volumeLevelConfigurationPropertyName)Creates volume control instance and initializes initial level value if stored in the configuration service.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddGainChangeListener(javax.media.GainChangeListener listener)Register for gain change update events.voidaddVolumeChangeListener(VolumeChangeListener listener)Adds a VolumeChangeListener to be informed for any change in the volume levels.static voidapplyGain(javax.media.GainControl gainControl, byte[] buffer, int offset, int length)Applies the gain specified by gainControl to the signal defined by the length number of samples given in buffer starting at offset.ComponentgetControlComponent()Not used.floatgetDB()Get the current gain set for this object in dB.protected static floatgetDefaultVolumeLevel()Returns the default volume level.protected static floatgetGainReferenceLevel()Returns the reference volume level for computing the gain.floatgetLevel()Get the current gain set for this object as a value between 0.0 and 1.0floatgetMaxValue()Returns the maximum allowed volume value.floatgetMinValue()Returns the minimum allowed volume value.booleangetMute()Get mute state of sound.floatgetVolume()Current volume value.protected voidloadVolume()Reads the initial volume level from the system.voidremoveGainChangeListener(javax.media.GainChangeListener listener)Remove interest in gain change update events.voidremoveVolumeChangeListener(VolumeChangeListener listener)Removes a VolumeChangeListener.floatsetDB(float gain)Set the gain in decibels.floatsetLevel(float level)Set the gain using a floating point scale with values between 0.0 and 1.0.voidsetMute(boolean mute)Mutes current sound.floatsetVolume(float value)Changes volume level.protected voidupdateHardwareVolume()Modifies the hardware microphone sensibility (hardware amplification).
-
-
-
Field Detail
-
MAX_VOLUME_LEVEL
protected static final float MAX_VOLUME_LEVEL
The maximum volume level accepted by AbstractVolumeControl.- See Also:
- Constant Field Values
-
MAX_VOLUME_PERCENT
public static final int MAX_VOLUME_PERCENT
The maximum volume level expressed in percent accepted by AbstractVolumeControl.- See Also:
- Constant Field Values
-
MIN_VOLUME_LEVEL
protected static final float MIN_VOLUME_LEVEL
The minimum volume level accepted by AbstractVolumeControl.- See Also:
- Constant Field Values
-
MIN_VOLUME_PERCENT
public static final int MIN_VOLUME_PERCENT
The minimum volume level expressed in percent accepted by AbstractVolumeControl.- See Also:
- Constant Field Values
-
volumeLevel
protected float volumeLevel
The current volume level.
-
-
Constructor Detail
-
BasicVolumeControl
public BasicVolumeControl(String volumeLevelConfigurationPropertyName)
Creates volume control instance and initializes initial level value if stored in the configuration service.- Parameters:
volumeLevelConfigurationPropertyName- the name of the configuration property which specifies the value of the volume level of the new instance
-
-
Method Detail
-
applyGain
public static void applyGain(javax.media.GainControl gainControl, byte[] buffer, int offset, int length)Applies the gain specified by gainControl to the signal defined by the length number of samples given in buffer starting at offset.- Parameters:
gainControl- the GainControl which specifies the gain to applybuffer- the samples of the signal to apply the gain tooffset- the start of the samples of the signal in bufferlength- the number of samples of the signal given in buffer
-
getDefaultVolumeLevel
protected static float getDefaultVolumeLevel()
Returns the default volume level.- Returns:
- The default volume level.
-
getGainReferenceLevel
protected static float getGainReferenceLevel()
Returns the reference volume level for computing the gain.- Returns:
- The reference volume level for computing the gain.
-
addGainChangeListener
public void addGainChangeListener(javax.media.GainChangeListener listener)
Register for gain change update events. AGainChangeEventis posted when the state of theGainControlchanges.- Specified by:
addGainChangeListenerin interfacejavax.media.GainControl- Parameters:
listener- The object to deliver events to.
-
addVolumeChangeListener
public void addVolumeChangeListener(VolumeChangeListener listener)
Adds a VolumeChangeListener to be informed for any change in the volume levels.- Specified by:
addVolumeChangeListenerin interfaceVolumeControl- Parameters:
listener- volume change listener.
-
getControlComponent
public Component getControlComponent()
Not used.- Specified by:
getControlComponentin interfacejavax.media.Control- Returns:
- null
-
getDB
public float getDB()
Get the current gain set for this object in dB.- Specified by:
getDBin interfacejavax.media.GainControl- Returns:
- The gain in dB.
-
getLevel
public float getLevel()
Get the current gain set for this object as a value between 0.0 and 1.0- Specified by:
getLevelin interfacejavax.media.GainControl- Returns:
- The gain in the level scale (0.0-1.0).
- See Also:
GainControl
-
getMaxValue
public float getMaxValue()
Returns the maximum allowed volume value.- Specified by:
getMaxValuein interfaceVolumeControl- Returns:
- the maximum allowed volume value.
- See Also:
VolumeControl
-
getMinValue
public float getMinValue()
Returns the minimum allowed volume value.- Specified by:
getMinValuein interfaceVolumeControl- Returns:
- the minimum allowed volume value.
- See Also:
VolumeControl
-
getMute
public boolean getMute()
Get mute state of sound.- Specified by:
getMutein interfacejavax.media.GainControl- Specified by:
getMutein interfaceVolumeControl- Returns:
- mute state of sound.
-
getVolume
public float getVolume()
Current volume value.- Specified by:
getVolumein interfaceVolumeControl- Returns:
- the current volume level.
- See Also:
VolumeControl
-
loadVolume
protected void loadVolume()
Reads the initial volume level from the system.
-
removeGainChangeListener
public void removeGainChangeListener(javax.media.GainChangeListener listener)
Remove interest in gain change update events.- Specified by:
removeGainChangeListenerin interfacejavax.media.GainControl- Parameters:
listener- The object that has been receiving events.
-
removeVolumeChangeListener
public void removeVolumeChangeListener(VolumeChangeListener listener)
Removes a VolumeChangeListener.- Specified by:
removeVolumeChangeListenerin interfaceVolumeControl- Parameters:
listener- the volume change listener to be removed.
-
setDB
public float setDB(float gain)
Set the gain in decibels. Setting the gain to 0.0 (the default) implies that the audio signal is neither amplified nor attenuated. Positive values amplify the audio signal and negative values attenuate the signal.- Specified by:
setDBin interfacejavax.media.GainControl- Parameters:
gain- The new gain in dB.- Returns:
- The gain that was actually set.
- See Also:
GainControl
-
setLevel
public float setLevel(float level)
Set the gain using a floating point scale with values between 0.0 and 1.0. 0.0 is silence; 1.0 is the loudest useful level that thisGainControlsupports.- Specified by:
setLevelin interfacejavax.media.GainControl- Parameters:
level- The new gain value specified in the level scale.- Returns:
- The level that was actually set.
- See Also:
GainControl
-
setMute
public void setMute(boolean mute)
Mutes current sound.- Specified by:
setMutein interfacejavax.media.GainControl- Specified by:
setMutein interfaceVolumeControl- Parameters:
mute- mutes/unmutes.
-
setVolume
public float setVolume(float value)
Changes volume level.- Specified by:
setVolumein interfaceVolumeControl- Parameters:
value- the new level to set.- Returns:
- the actual level which was set.
- See Also:
VolumeControl
-
updateHardwareVolume
protected void updateHardwareVolume()
Modifies the hardware microphone sensibility (hardware amplification). This is a void function for AbstractVolumeControl since it does not have any connection to hardware volume. But, this function must be redefined by any extending class.
-
-