mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Fix For Sample-To-Bytes Calculation In OpusDecoder
Aligning the byte size calculation with the sizes defined in opus_jni.cc for the `outputFloat=true` case #minor-release PiperOrigin-RevId: 427028982
This commit is contained in:
parent
31aa9d458d
commit
1270eb012d
1 changed files with 7 additions and 1 deletions
|
|
@ -213,7 +213,7 @@ public final class OpusDecoder
|
||||||
outputData.position(0);
|
outputData.position(0);
|
||||||
outputData.limit(result);
|
outputData.limit(result);
|
||||||
if (skipSamples > 0) {
|
if (skipSamples > 0) {
|
||||||
int bytesPerSample = channelCount * 2;
|
int bytesPerSample = samplesToBytes(1, channelCount, outputFloat);
|
||||||
int skipBytes = skipSamples * bytesPerSample;
|
int skipBytes = skipSamples * bytesPerSample;
|
||||||
if (result <= skipBytes) {
|
if (result <= skipBytes) {
|
||||||
skipSamples -= result / bytesPerSample;
|
skipSamples -= result / bytesPerSample;
|
||||||
|
|
@ -280,6 +280,12 @@ public final class OpusDecoder
|
||||||
return DEFAULT_SEEK_PRE_ROLL_SAMPLES;
|
return DEFAULT_SEEK_PRE_ROLL_SAMPLES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns number of bytes to represent {@code samples}. */
|
||||||
|
private static int samplesToBytes(int samples, int channelCount, boolean outputFloat) {
|
||||||
|
int bytesPerChannel = outputFloat ? 4 : 2;
|
||||||
|
return samples * channelCount * bytesPerChannel;
|
||||||
|
}
|
||||||
|
|
||||||
private static int readSignedLittleEndian16(byte[] input, int offset) {
|
private static int readSignedLittleEndian16(byte[] input, int offset) {
|
||||||
int value = input[offset] & 0xFF;
|
int value = input[offset] & 0xFF;
|
||||||
value |= (input[offset + 1] & 0xFF) << 8;
|
value |= (input[offset + 1] & 0xFF) << 8;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue