Fix usage of 'samples' vs 'frames' for gapless

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=191704629
This commit is contained in:
andrewlewis 2018-04-05 00:44:45 -07:00 committed by Oliver Woodman
parent e3eddc4d20
commit 6ea79c8a4e
4 changed files with 38 additions and 26 deletions

View file

@ -145,12 +145,12 @@ public final class Format implements Parcelable {
@C.PcmEncoding
public final int pcmEncoding;
/**
* The number of samples to trim from the start of the decoded audio stream, or 0 if not
* The number of frames to trim from the start of the decoded audio stream, or 0 if not
* applicable.
*/
public final int encoderDelay;
/**
* The number of samples to trim from the end of the decoded audio stream, or 0 if not applicable.
* The number of frames to trim from the end of the decoded audio stream, or 0 if not applicable.
*/
public final int encoderPadding;

View file

@ -192,17 +192,23 @@ public interface AudioSink {
* @param outputChannels A mapping from input to output channels that is applied to this sink's
* input as a preprocessing step, if handling PCM input. Specify {@code null} to leave the
* input unchanged. Otherwise, the element at index {@code i} specifies index of the input
* channel to map to output channel {@code i} when preprocessing input buffers. After the
* map is applied the audio data will have {@code outputChannels.length} channels.
* @param trimStartSamples The number of audio samples to trim from the start of data written to
* the sink after this call.
* @param trimEndSamples The number of audio samples to trim from data written to the sink
* channel to map to output channel {@code i} when preprocessing input buffers. After the map
* is applied the audio data will have {@code outputChannels.length} channels.
* @param trimStartFrames The number of audio frames to trim from the start of data written to the
* sink after this call.
* @param trimEndFrames The number of audio frames to trim from data written to the sink
* immediately preceding the next call to {@link #reset()} or this method.
* @throws ConfigurationException If an error occurs configuring the sink.
*/
void configure(@C.Encoding int inputEncoding, int inputChannelCount, int inputSampleRate,
int specifiedBufferSize, @Nullable int[] outputChannels, int trimStartSamples,
int trimEndSamples) throws ConfigurationException;
void configure(
@C.Encoding int inputEncoding,
int inputChannelCount,
int inputSampleRate,
int specifiedBufferSize,
@Nullable int[] outputChannels,
int trimStartFrames,
int trimEndFrames)
throws ConfigurationException;
/**
* Starts or resumes consuming audio if initialized.

View file

@ -278,9 +278,15 @@ public final class DefaultAudioSink implements AudioSink {
}
@Override
public void configure(@C.Encoding int inputEncoding, int inputChannelCount, int inputSampleRate,
int specifiedBufferSize, @Nullable int[] outputChannels, int trimStartSamples,
int trimEndSamples) throws ConfigurationException {
public void configure(
@C.Encoding int inputEncoding,
int inputChannelCount,
int inputSampleRate,
int specifiedBufferSize,
@Nullable int[] outputChannels,
int trimStartFrames,
int trimEndFrames)
throws ConfigurationException {
boolean flush = false;
this.inputSampleRate = inputSampleRate;
int channelCount = inputChannelCount;
@ -297,7 +303,7 @@ public final class DefaultAudioSink implements AudioSink {
boolean processingEnabled = isInputPcm && inputEncoding != C.ENCODING_PCM_FLOAT;
canApplyPlaybackParameters = processingEnabled && !shouldConvertHighResIntPcmToFloat;
if (processingEnabled) {
trimmingAudioProcessor.setTrimSampleCount(trimStartSamples, trimEndSamples);
trimmingAudioProcessor.setTrimFrameCount(trimStartFrames, trimEndFrames);
channelMappingAudioProcessor.setChannelMap(outputChannels);
for (AudioProcessor audioProcessor : getAvailableAudioProcessors()) {
try {

View file

@ -26,8 +26,8 @@ import java.nio.ByteOrder;
/* package */ final class TrimmingAudioProcessor implements AudioProcessor {
private boolean isActive;
private int trimStartSamples;
private int trimEndSamples;
private int trimStartFrames;
private int trimEndFrames;
private int channelCount;
private int sampleRateHz;
@ -48,17 +48,17 @@ import java.nio.ByteOrder;
}
/**
* Sets the number of audio samples to trim from the start and end of audio passed to this
* Sets the number of audio frames to trim from the start and end of audio passed to this
* processor. After calling this method, call {@link #configure(int, int, int)} to apply the new
* trimming sample counts.
* trimming frame counts.
*
* @param trimStartSamples The number of audio samples to trim from the start of audio.
* @param trimEndSamples The number of audio samples to trim from the end of audio.
* @param trimStartFrames The number of audio frames to trim from the start of audio.
* @param trimEndFrames The number of audio frames to trim from the end of audio.
* @see AudioSink#configure(int, int, int, int, int[], int, int)
*/
public void setTrimSampleCount(int trimStartSamples, int trimEndSamples) {
this.trimStartSamples = trimStartSamples;
this.trimEndSamples = trimEndSamples;
public void setTrimFrameCount(int trimStartFrames, int trimEndFrames) {
this.trimStartFrames = trimStartFrames;
this.trimEndFrames = trimEndFrames;
}
@Override
@ -69,11 +69,11 @@ import java.nio.ByteOrder;
}
this.channelCount = channelCount;
this.sampleRateHz = sampleRateHz;
endBuffer = new byte[trimEndSamples * channelCount * 2];
endBuffer = new byte[trimEndFrames * channelCount * 2];
endBufferSize = 0;
pendingTrimStartBytes = trimStartSamples * channelCount * 2;
pendingTrimStartBytes = trimStartFrames * channelCount * 2;
boolean wasActive = isActive;
isActive = trimStartSamples != 0 || trimEndSamples != 0;
isActive = trimStartFrames != 0 || trimEndFrames != 0;
return wasActive != isActive;
}