mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add WavHeader.samplesPerBlock (currently always == 1)
PiperOrigin-RevId: 284961417
This commit is contained in:
parent
039ce8a95b
commit
a97b09d799
2 changed files with 19 additions and 4 deletions
|
|
@ -33,6 +33,8 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
private final int blockAlignment;
|
private final int blockAlignment;
|
||||||
/** Bits per sample for the audio data. */
|
/** Bits per sample for the audio data. */
|
||||||
private final int bitsPerSample;
|
private final int bitsPerSample;
|
||||||
|
/** Number of samples in each block. */
|
||||||
|
private final int samplesPerBlock;
|
||||||
/** The PCM encoding. */
|
/** The PCM encoding. */
|
||||||
@C.PcmEncoding private final int encoding;
|
@C.PcmEncoding private final int encoding;
|
||||||
|
|
||||||
|
|
@ -47,12 +49,14 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
int averageBytesPerSecond,
|
int averageBytesPerSecond,
|
||||||
int blockAlignment,
|
int blockAlignment,
|
||||||
int bitsPerSample,
|
int bitsPerSample,
|
||||||
|
int samplesPerBlock,
|
||||||
@C.PcmEncoding int encoding) {
|
@C.PcmEncoding int encoding) {
|
||||||
this.numChannels = numChannels;
|
this.numChannels = numChannels;
|
||||||
this.sampleRateHz = sampleRateHz;
|
this.sampleRateHz = sampleRateHz;
|
||||||
this.averageBytesPerSecond = averageBytesPerSecond;
|
this.averageBytesPerSecond = averageBytesPerSecond;
|
||||||
this.blockAlignment = blockAlignment;
|
this.blockAlignment = blockAlignment;
|
||||||
this.bitsPerSample = bitsPerSample;
|
this.bitsPerSample = bitsPerSample;
|
||||||
|
this.samplesPerBlock = samplesPerBlock;
|
||||||
this.encoding = encoding;
|
this.encoding = encoding;
|
||||||
dataStartPosition = C.POSITION_UNSET;
|
dataStartPosition = C.POSITION_UNSET;
|
||||||
dataEndPosition = C.POSITION_UNSET;
|
dataEndPosition = C.POSITION_UNSET;
|
||||||
|
|
@ -101,8 +105,8 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getDurationUs() {
|
public long getDurationUs() {
|
||||||
long numFrames = (dataEndPosition - dataStartPosition) / blockAlignment;
|
long numBlocks = (dataEndPosition - dataStartPosition) / blockAlignment;
|
||||||
return (numFrames * C.MICROS_PER_SECOND) / sampleRateHz;
|
return numBlocks * samplesPerBlock * C.MICROS_PER_SECOND / sampleRateHz;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -157,6 +161,11 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
return numChannels;
|
return numChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns the number of samples in each block. */
|
||||||
|
public int getSamplesPerBlock() {
|
||||||
|
return samplesPerBlock;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the PCM encoding. **/
|
/** Returns the PCM encoding. **/
|
||||||
public @C.PcmEncoding int getEncoding() {
|
public @C.PcmEncoding int getEncoding() {
|
||||||
return encoding;
|
return encoding;
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,13 @@ import java.io.IOException;
|
||||||
input.advancePeekPosition((int) chunkHeader.size - 16);
|
input.advancePeekPosition((int) chunkHeader.size - 16);
|
||||||
|
|
||||||
return new WavHeader(
|
return new WavHeader(
|
||||||
numChannels, sampleRateHz, averageBytesPerSecond, blockAlignment, bitsPerSample, encoding);
|
numChannels,
|
||||||
|
sampleRateHz,
|
||||||
|
averageBytesPerSecond,
|
||||||
|
blockAlignment,
|
||||||
|
bitsPerSample,
|
||||||
|
/* samplesPerBlock= */ 1,
|
||||||
|
encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -182,7 +188,7 @@ import java.io.IOException;
|
||||||
*/
|
*/
|
||||||
public static ChunkHeader peek(ExtractorInput input, ParsableByteArray scratch)
|
public static ChunkHeader peek(ExtractorInput input, ParsableByteArray scratch)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
input.peekFully(scratch.data, 0, SIZE_IN_BYTES);
|
input.peekFully(scratch.data, /* offset= */ 0, /* length= */ SIZE_IN_BYTES);
|
||||||
scratch.setPosition(0);
|
scratch.setPosition(0);
|
||||||
|
|
||||||
int id = scratch.readInt();
|
int id = scratch.readInt();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue