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/openal | |
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/openal')
-rw-r--r-- | src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java b/src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java index f9ca0c028..d3964a2cf 100644 --- a/src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java +++ b/src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java @@ -58,7 +58,8 @@ public class ALAudioSink implements AudioSink { /** Playback speed, range [0.5 - 2.0], default 1.0. */ private float playSpeed; - + private float volume = 1.0f; + static class ALAudioFrame extends AudioFrame { private final int alBuffer; @@ -686,6 +687,34 @@ public class ALAudioSink implements AudioSink { } @Override + public final float getVolume() { + return volume; + } + + @Override + public final boolean setVolume(float v) { + if( !initialized || null == chosenFormat ) { + return false; + } + lockContext(); + try { + if( Math.abs(v) < 0.01f ) { + v = 0.0f; + } else if( Math.abs(1.0f - v) < 0.01f ) { + v = 1.0f; + } + if( 0.0f <= v && v <= 1.0f ) { // OpenAL limits + volume = v; + al.alSourcef(alSource[0], AL.AL_GAIN, v); + return true; + } + } finally { + unlockContext(); + } + return false; + } + + @Override public final void flush() { if( !initialized || null == chosenFormat ) { return; |