diff options
author | Sven Gothel <[email protected]> | 2013-08-25 02:47:49 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-08-25 02:47:49 +0200 |
commit | 8cdbfb676ea31c6719e6f6e8ae7a44e060a5987f (patch) | |
tree | 1808877f76e87d4c67d0ff23657b39af823c072b /src/jogl/classes/jogamp/opengl/util/av | |
parent | 517371b2c200783890e2f6a173748cf65d3c8c91 (diff) |
GLMediaPlayer/AudioSink: Add set[Audio]Volume(float v)/get[Audio]Volume() allowing to change the audio volume.
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/util/av')
3 files changed, 76 insertions, 3 deletions
diff --git a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java index 238595d45..05cc997ca 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java +++ b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java @@ -88,6 +88,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { protected URI streamLoc = null; protected volatile float playSpeed = 1.0f; + protected float audioVolume = 1.0f; /** Shall be set by the {@link #initStreamImpl(int, int)} method implementation. */ protected int vid = GLMediaPlayer.STREAM_ID_AUTO; @@ -362,7 +363,6 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { @Override public final boolean setPlaySpeed(float rate) { synchronized( stateLock ) { - final State preState = state; final float preSpeed = playSpeed; boolean res = false; if(State.Uninitialized != state ) { @@ -377,7 +377,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } } } - if(DEBUG) { System.err.println("setPlaySpeed("+rate+"): "+preState+"/"+preSpeed+" -> "+state+"/"+playSpeed+", "+toString()); } + if(DEBUG) { System.err.println("setPlaySpeed("+rate+"): "+state+", "+preSpeed+" -> "+playSpeed+", "+toString()); } return res; } } @@ -398,6 +398,51 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } @Override + public final float getAudioVolume() { + getAudioVolumeImpl(); + return audioVolume; + } + /** + * Override if not using AudioSink, or AudioSink's {@link AudioSink#getVolume()} is not sufficient! + */ + protected void getAudioVolumeImpl() { + if( null != audioSink ) { + audioVolume = audioSink.getVolume(); + } + } + + @Override + public boolean setAudioVolume(float v) { + synchronized( stateLock ) { + final float preVolume = audioVolume; + boolean res = false; + if(State.Uninitialized != state ) { + if( Math.abs(v) < 0.01f ) { + v = 0.0f; + } else if( Math.abs(1.0f - v) < 0.01f ) { + v = 1.0f; + } + if( setAudioVolumeImpl(v) ) { + audioVolume = v; + res = true; + } + } + if(DEBUG) { System.err.println("setAudioVolume("+v+"): "+state+", "+preVolume+" -> "+audioVolume+", "+toString()); } + return res; + } + } + /** + * Override if not using AudioSink, or AudioSink's {@link AudioSink#setVolume(float)} is not sufficient! + */ + protected boolean setAudioVolumeImpl(float v) { + if( null != audioSink ) { + return audioSink.setVolume(v); + } + // still true, even if audioSink rejects command .. + return true; + } + + @Override public final void initStream(URI streamLoc, int vid, int aid, int reqTextureCount) throws IllegalStateException, IllegalArgumentException { synchronized( stateLock ) { if(State.Uninitialized != state) { diff --git a/src/jogl/classes/jogamp/opengl/util/av/JavaSoundAudioSink.java b/src/jogl/classes/jogamp/opengl/util/av/JavaSoundAudioSink.java index b46b64748..b1b9c1b6c 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/JavaSoundAudioSink.java +++ b/src/jogl/classes/jogamp/opengl/util/av/JavaSoundAudioSink.java @@ -36,6 +36,7 @@ public class JavaSoundAudioSink implements AudioSink { private AudioDataFormat chosenFormat = null; private volatile boolean playRequested = false; + private float volume = 1.0f; static { boolean ok = false; @@ -63,6 +64,19 @@ public class JavaSoundAudioSink implements AudioSink { } @Override + public final float getVolume() { + // FIXME + return volume; + } + + @Override + public final boolean setVolume(float v) { + // FIXME + volume = v; + return true; + } + + @Override public AudioDataFormat getPreferredFormat() { return DefaultFormat; } diff --git a/src/jogl/classes/jogamp/opengl/util/av/NullAudioSink.java b/src/jogl/classes/jogamp/opengl/util/av/NullAudioSink.java index 067322819..83799b074 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/NullAudioSink.java +++ b/src/jogl/classes/jogamp/opengl/util/av/NullAudioSink.java @@ -14,7 +14,8 @@ public class NullAudioSink implements AudioSink { private volatile float playSpeed = 1.0f; private volatile boolean playRequested = false; - + private float volume = 1.0f; + @Override public final float getPlaySpeed() { return playSpeed; } @@ -28,6 +29,19 @@ public class NullAudioSink implements AudioSink { } @Override + public final float getVolume() { + // FIXME + return volume; + } + + @Override + public final boolean setVolume(float v) { + // FIXME + volume = v; + return true; + } + + @Override public AudioDataFormat getPreferredFormat() { return DefaultFormat; } |