From 46b52ccbf6b6c8ec4c50f985861bf4c100ede40b Mon Sep 17 00:00:00 2001 From: collinsmith Date: Tue, 6 Oct 2020 11:35:09 -0700 Subject: [PATCH] Pass BIK reference to child BinkAudio for flags and version validation --- core/src/com/riiablo/video/BIK.java | 2 +- core/src/com/riiablo/video/BinkAudio.java | 20 ++++++++++++-------- core/src/com/riiablo/video/VideoPlayer.java | 1 + 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/core/src/com/riiablo/video/BIK.java b/core/src/com/riiablo/video/BIK.java index c9efaa3d..14a56b47 100644 --- a/core/src/com/riiablo/video/BIK.java +++ b/core/src/com/riiablo/video/BIK.java @@ -114,7 +114,7 @@ public class BIK { for (int i = 0, s = numTracks; i < s; i++) { try { MDC.put("track", i); - tracks[i] = new BinkAudio(in); + tracks[i] = new BinkAudio(this, in); } finally { MDC.remove("track"); } diff --git a/core/src/com/riiablo/video/BinkAudio.java b/core/src/com/riiablo/video/BinkAudio.java index 0548c6ec..3491ecd6 100644 --- a/core/src/com/riiablo/video/BinkAudio.java +++ b/core/src/com/riiablo/video/BinkAudio.java @@ -34,6 +34,7 @@ public class BinkAudio { private final int[] BANDS; private final float[][] PREVIOUS = new float[MAX_CHANNELS][BLOCK_MAX_SIZE >>> 4]; + final BIK bik; final short numChannels; final int sampleRate; final int flags; @@ -48,7 +49,9 @@ public class BinkAudio { boolean first; - BinkAudio(ByteInput in) { + BinkAudio(BIK bik, ByteInput in) { + this.bik = bik; + log.trace("slicing {} bytes", SIZE); in = in.readSlice(SIZE); @@ -122,6 +125,12 @@ public class BinkAudio { return (flags & FLAG_AUDIO_STEREO) == 0; } + static float readFloat29(BitInput bits) { + int power = bits.read31u(5); + float f = FastMath.scalb(bits.read31u(23), power - 23); + return bits.readBoolean() ? -f : f; + } + void decode(BitInput bits, float[][] out) { int ch, i, j, k; float q; @@ -143,11 +152,12 @@ public class BinkAudio { // parse coefficients i = 2; while (i < frameLen) { + assert bik.version == 'i'; { int v = bits.read1(); if (v != 0) { v = bits.read7u(4); - j = i + RLE[v] << 3; + j = i + RLE[v] * 8; } else { j = i + 8; } @@ -202,10 +212,4 @@ public class BinkAudio { first = false; } - - static float readFloat29(BitInput bits) { - int power = bits.read32(5); - float f = FastMath.scalb(bits.read32(23), power - 23); - return bits.readBoolean() ? f : -f; - } } diff --git a/core/src/com/riiablo/video/VideoPlayer.java b/core/src/com/riiablo/video/VideoPlayer.java index 280536ad..f8e14115 100644 --- a/core/src/com/riiablo/video/VideoPlayer.java +++ b/core/src/com/riiablo/video/VideoPlayer.java @@ -20,6 +20,7 @@ public class VideoPlayer implements Disposable { private int frame; private float time, nextFrame; private ExecutorService audioStreams; + // FIXME: child threads should throw an error to parent? public VideoPlayer() {