aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/av/AudioSink.java22
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java23
-rw-r--r--src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java16
-rw-r--r--src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java31
-rw-r--r--src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java49
-rw-r--r--src/jogl/classes/jogamp/opengl/util/av/JavaSoundAudioSink.java14
-rw-r--r--src/jogl/classes/jogamp/opengl/util/av/NullAudioSink.java16
7 files changed, 163 insertions, 8 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/av/AudioSink.java b/src/jogl/classes/com/jogamp/opengl/util/av/AudioSink.java
index 2b8da8af9..7f477a57d 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/av/AudioSink.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/av/AudioSink.java
@@ -201,13 +201,31 @@ public interface AudioSink {
/**
* Sets the playback speed.
* <p>
- * Play speed is set to <i>normal</i>, i.e. <code>1.0f</code>
- * if <code> abs(1.0f - rate) < 0.01f</code> to simplify test.
+ * To simplify test, play speed is <i>normalized</i>, i.e.
+ * <ul>
+ * <li><code>1.0f</code>: if <code> Math.abs(1.0f - rate) < 0.01f </code></li>
+ * </ul>
* </p>
* @return true if successful, otherwise false, i.e. due to unsupported value range of implementation.
*/
public boolean setPlaySpeed(float s);
+ /** Returns the volume. */
+ public float getVolume();
+
+ /**
+ * Sets the volume [0f..1f].
+ * <p>
+ * To simplify test, volume is <i>normalized</i>, i.e.
+ * <ul>
+ * <li><code>0.0f</code>: if <code> Math.abs(v) < 0.01f </code></li>
+ * <li><code>1.0f</code>: if <code> Math.abs(1.0f - v) < 0.01f </code></li>
+ * </ul>
+ * </p>
+ * @return true if successful, otherwise false, i.e. due to unsupported value range of implementation.
+ */
+ public boolean setVolume(float v);
+
/**
* Returns the preferred {@link AudioDataFormat} by this sink.
* <p>
diff --git a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java
index 02fbd721c..6235bdeb0 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java
@@ -350,16 +350,35 @@ public interface GLMediaPlayer extends TextureSequence {
/**
* Sets the playback speed.
* <p>
- * Play speed is set to <i>normal</i>, i.e. <code>1.0f</code>
- * if <code> abs(1.0f - rate) < 0.01f</code> to simplify test.
+ * To simplify test, play speed is <i>normalized</i>, i.e.
+ * <ul>
+ * <li><code>1.0f</code>: if <code> Math.abs(1.0f - rate) < 0.01f </code></li>
+ * </ul>
* </p>
* @return true if successful, otherwise false, i.e. due to unsupported value range of implementation.
*/
public boolean setPlaySpeed(float rate);
+ /** Returns the playback speed. */
public float getPlaySpeed();
/**
+ * Sets the audio volume, [0f..1f].
+ * <p>
+ * To simplify test, volume is <i>normalized</i>, i.e.
+ * <ul>
+ * <li><code>0.0f</code>: if <code> Math.abs(v) < 0.01f </code></li>
+ * <li><code>1.0f</code>: if <code> Math.abs(1.0f - v) < 0.01f </code></li>
+ * </ul>
+ * </p>
+ * @return true if successful, otherwise false, i.e. due to unsupported value range of implementation.
+ */
+ public boolean setAudioVolume(float v);
+
+ /** Returns the audio volume. */
+ public float getAudioVolume();
+
+ /**
* <a href="#lifecycle">Lifecycle</a>: {@link State#Paused} -> {@link State#Playing}
*/
public State play();
diff --git a/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java b/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java
index 63d9c8d22..3ff156ae3 100644
--- a/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java
+++ b/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java
@@ -98,6 +98,22 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl {
@Override
protected final boolean setPlaySpeedImpl(float rate) {
+ // FIXME
+ return false;
+ }
+
+ @Override
+ protected final boolean setAudioVolumeImpl(float v) {
+ if(null != mp) {
+ try {
+ mp.setVolume(v, v);
+ return true;
+ } catch (IllegalStateException ise) {
+ if(DEBUG) {
+ ise.printStackTrace();
+ }
+ }
+ }
return false;
}
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;
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;
}