mirror of
https://github.com/samsonjs/media.git
synced 2026-04-07 11:35:46 +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;
|
||||
/** Bits per sample for the audio data. */
|
||||
private final int bitsPerSample;
|
||||
/** Number of samples in each block. */
|
||||
private final int samplesPerBlock;
|
||||
/** The PCM encoding. */
|
||||
@C.PcmEncoding private final int encoding;
|
||||
|
||||
|
|
@ -47,12 +49,14 @@ import com.google.android.exoplayer2.util.Util;
|
|||
int averageBytesPerSecond,
|
||||
int blockAlignment,
|
||||
int bitsPerSample,
|
||||
int samplesPerBlock,
|
||||
@C.PcmEncoding int encoding) {
|
||||
this.numChannels = numChannels;
|
||||
this.sampleRateHz = sampleRateHz;
|
||||
this.averageBytesPerSecond = averageBytesPerSecond;
|
||||
this.blockAlignment = blockAlignment;
|
||||
this.bitsPerSample = bitsPerSample;
|
||||
this.samplesPerBlock = samplesPerBlock;
|
||||
this.encoding = encoding;
|
||||
dataStartPosition = C.POSITION_UNSET;
|
||||
dataEndPosition = C.POSITION_UNSET;
|
||||
|
|
@ -101,8 +105,8 @@ import com.google.android.exoplayer2.util.Util;
|
|||
|
||||
@Override
|
||||
public long getDurationUs() {
|
||||
long numFrames = (dataEndPosition - dataStartPosition) / blockAlignment;
|
||||
return (numFrames * C.MICROS_PER_SECOND) / sampleRateHz;
|
||||
long numBlocks = (dataEndPosition - dataStartPosition) / blockAlignment;
|
||||
return numBlocks * samplesPerBlock * C.MICROS_PER_SECOND / sampleRateHz;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -157,6 +161,11 @@ import com.google.android.exoplayer2.util.Util;
|
|||
return numChannels;
|
||||
}
|
||||
|
||||
/** Returns the number of samples in each block. */
|
||||
public int getSamplesPerBlock() {
|
||||
return samplesPerBlock;
|
||||
}
|
||||
|
||||
/** Returns the PCM encoding. **/
|
||||
public @C.PcmEncoding int getEncoding() {
|
||||
return encoding;
|
||||
|
|
|
|||
|
|
@ -94,7 +94,13 @@ import java.io.IOException;
|
|||
input.advancePeekPosition((int) chunkHeader.size - 16);
|
||||
|
||||
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)
|
||||
throws IOException, InterruptedException {
|
||||
input.peekFully(scratch.data, 0, SIZE_IN_BYTES);
|
||||
input.peekFully(scratch.data, /* offset= */ 0, /* length= */ SIZE_IN_BYTES);
|
||||
scratch.setPosition(0);
|
||||
|
||||
int id = scratch.readInt();
|
||||
|
|
|
|||
Loading…
Reference in a new issue