From 8cdbfb676ea31c6719e6f6e8ae7a44e060a5987f Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 25 Aug 2013 02:47:49 +0200 Subject: GLMediaPlayer/AudioSink: Add set[Audio]Volume(float v)/get[Audio]Volume() allowing to change the audio volume. --- .../jogamp/opengl/openal/av/ALAudioSink.java | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/jogl/classes/jogamp/opengl/openal') 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; @@ -685,6 +686,34 @@ public class ALAudioSink implements AudioSink { return false; } + @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 ) { -- cgit v1.2.3