aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/openal/av
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-08-24 23:38:42 +0200
committerSven Gothel <[email protected]>2013-08-24 23:38:42 +0200
commit517371b2c200783890e2f6a173748cf65d3c8c91 (patch)
treeca4c43e48762c7f67c13e5fb5175476f4c5de57c /src/jogl/classes/jogamp/opengl/openal/av
parentd0e01cb5c0ec3e48b8a9b9b79a7795b214c6e3ea (diff)
AudioSink.init(..) abstract 'frame count' -> duration [ms] allowing non-frame based AudioSink's to deal w/ desired queue sizes.
- Rename AudioSink.initSink(..) -> AudioSink.init(..) - Move: "int initialFrameCount, int frameGrowAmount, int frameLimit" to "int initialQueueSize, int queueGrowAmount, int queueLimit" based on milliseconds instead of frame count. - Passing hint 'float frameDuration' to calculate frame count for fame based audio sink, i.e. ALAudioSink. - Adding sensible static final default values - AudioDataFormat: Add convenient conversion routines (samples/bytes/frame-count) - FFMPEGMediaPlayer: Retrieve audio frame size in samples per channel, pass it to AudioSink.init(..) to properly calculate frame count/limits based on duration.
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/openal/av')
-rw-r--r--src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java b/src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java
index 5f98c3ad2..f9ca0c028 100644
--- a/src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java
+++ b/src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java
@@ -213,7 +213,8 @@ public class ALAudioSink implements AudioSink {
return "ALAudioSink[init "+initialized+", playRequested "+playRequested+", device "+deviceSpecifier+", ctx "+toHexString(ctxHash)+", alSource "+alSrcName+
", chosen "+chosenFormat+", alFormat "+toHexString(alFormat)+
", playSpeed "+playSpeed+", buffers[total "+alBuffersLen+", avail "+alFramesAvail.size()+", "+
- "queued["+alFramesPlaying.size()+", apts "+getPTS()+", "+getQueuedTime() + " ms, " + alBufferBytesQueued+" bytes]";
+ "queued["+alFramesPlaying.size()+", apts "+getPTS()+", "+getQueuedTime() + " ms, " + alBufferBytesQueued+" bytes], "+
+ "queue[g "+frameGrowAmount+", l "+frameLimit+"]";
}
public final String getPerfString() {
final int alBuffersLen = null != alBufferNames ? alBufferNames.length : 0;
@@ -226,7 +227,7 @@ public class ALAudioSink implements AudioSink {
}
@Override
- public final AudioDataFormat initSink(AudioDataFormat requestedFormat, int initialFrameCount, int frameGrowAmount, int frameLimit) {
+ public final AudioDataFormat init(AudioDataFormat requestedFormat, float frameDuration, int initialQueueSize, int queueGrowAmount, int queueLimit) {
if( !staticAvailable ) {
return null;
}
@@ -260,6 +261,10 @@ public class ALAudioSink implements AudioSink {
// Allocate buffers
destroyBuffers();
{
+ final float useFrameDuration = frameDuration > 1f ? frameDuration : AudioSink.DefaultFrameDuration;
+ final int initialFrameCount = requestedFormat.getFrameCount(
+ initialQueueSize > 0 ? initialQueueSize : AudioSink.DefaultInitialQueueSize, useFrameDuration);
+ // frameDuration, int initialQueueSize, int queueGrowAmount, int queueLimit) {
alBufferNames = new int[initialFrameCount];
al.alGenBuffers(initialFrameCount, alBufferNames, 0);
final int err = al.alGetError();
@@ -274,8 +279,10 @@ public class ALAudioSink implements AudioSink {
alFramesAvail = new LFRingbuffer<ALAudioFrame>(alFrames);
alFramesPlaying = new LFRingbuffer<ALAudioFrame>(ALAudioFrame[].class, initialFrameCount);
- this.frameGrowAmount = frameGrowAmount;
- this.frameLimit = frameLimit;
+ this.frameGrowAmount = requestedFormat.getFrameCount(
+ queueGrowAmount > 0 ? queueGrowAmount : AudioSink.DefaultQueueGrowAmount, useFrameDuration);
+ this.frameLimit = requestedFormat.getFrameCount(
+ queueLimit > 0 ? queueLimit : AudioSink.DefaultQueueLimitWithVideo, useFrameDuration);
}
} finally {
unlockContext();
@@ -423,9 +430,9 @@ public class ALAudioSink implements AudioSink {
if( wait && val[0] < releaseBufferLimes ) {
i++;
// clip wait at [2 .. 100] ms
- final int avgBufferDura = chosenFormat.getDuration( alBufferBytesQueued / alFramesPlaying.size() );
+ final int avgBufferDura = chosenFormat.getBytesDuration( alBufferBytesQueued / alFramesPlaying.size() );
final int sleep = Math.max(2, Math.min(100, releaseBufferLimes * avgBufferDura));
- if( DEBUG ) {
+ if( DEBUG || true ) {
System.err.println(getThreadName()+": ALAudioSink: Dequeue.wait["+i+"]: avgBufferDura "+avgBufferDura+", releaseBufferLimes "+releaseBufferLimes+", sleep "+sleep+" ms, playImpl "+isPlayingImpl1()+", processed "+val[0]+", "+this);
}
unlockContext();
@@ -512,7 +519,7 @@ public class ALAudioSink implements AudioSink {
throw new RuntimeException("ALError "+toHexString(alErr)+" while makeCurrent. "+this);
}
- final int duration = chosenFormat.getDuration(byteCount);
+ final int duration = chosenFormat.getBytesDuration(byteCount);
final boolean dequeueDone;
if( alFramesAvail.isEmpty() ) {
// try to dequeue first
@@ -738,7 +745,7 @@ public class ALAudioSink implements AudioSink {
if( !initialized || null == chosenFormat ) {
return 0;
}
- return chosenFormat.getDuration(alBufferBytesQueued);
+ return chosenFormat.getBytesDuration(alBufferBytesQueued);
}
@Override