Skip to content

Commit

Permalink
Add SilenceSkippingAudioProcessor
Browse files Browse the repository at this point in the history
This uses a simple threshold-based algorithm for classifying audio frames as
silent, and removes silences from input audio that last longer than a given
duration.

The plan is to expose this functionality via PlaybackParameters in a later
change.

Issue: #2635

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=190737027
  • Loading branch information
andrewlewis authored and ojw28 committed Mar 29, 2018
1 parent 18df028 commit 6dcfe57
Show file tree
Hide file tree
Showing 3 changed files with 838 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ private InvalidAudioTrackTimestampException(String message) {
private final boolean enableConvertHighResIntPcmToFloat;
private final ChannelMappingAudioProcessor channelMappingAudioProcessor;
private final TrimmingAudioProcessor trimmingAudioProcessor;
private final SilenceSkippingAudioProcessor silenceSkippingAudioProcessor;
private final SonicAudioProcessor sonicAudioProcessor;
private final AudioProcessor[] toIntPcmAvailableAudioProcessors;
private final AudioProcessor[] toFloatPcmAvailableAudioProcessors;
Expand Down Expand Up @@ -226,14 +227,16 @@ public DefaultAudioSink(
audioTrackPositionTracker = new AudioTrackPositionTracker(new PositionTrackerListener());
channelMappingAudioProcessor = new ChannelMappingAudioProcessor();
trimmingAudioProcessor = new TrimmingAudioProcessor();
silenceSkippingAudioProcessor = new SilenceSkippingAudioProcessor();
sonicAudioProcessor = new SonicAudioProcessor();
toIntPcmAvailableAudioProcessors = new AudioProcessor[4 + audioProcessors.length];
toIntPcmAvailableAudioProcessors = new AudioProcessor[5 + audioProcessors.length];
toIntPcmAvailableAudioProcessors[0] = new ResamplingAudioProcessor();
toIntPcmAvailableAudioProcessors[1] = channelMappingAudioProcessor;
toIntPcmAvailableAudioProcessors[2] = trimmingAudioProcessor;
System.arraycopy(
audioProcessors, 0, toIntPcmAvailableAudioProcessors, 3, audioProcessors.length);
toIntPcmAvailableAudioProcessors[3 + audioProcessors.length] = sonicAudioProcessor;
toIntPcmAvailableAudioProcessors[3 + audioProcessors.length] = silenceSkippingAudioProcessor;
toIntPcmAvailableAudioProcessors[4 + audioProcessors.length] = sonicAudioProcessor;
toFloatPcmAvailableAudioProcessors = new AudioProcessor[] {new FloatResamplingAudioProcessor()};
volume = 1.0f;
startMediaTimeState = START_NOT_SET;
Expand Down Expand Up @@ -272,7 +275,7 @@ public long getCurrentPositionUs(boolean sourceEnded) {
}
long positionUs = audioTrackPositionTracker.getCurrentPositionUs(sourceEnded);
positionUs = Math.min(positionUs, framesToDurationUs(getWrittenFrames()));
return startMediaTimeUs + applySpeedup(positionUs);
return startMediaTimeUs + applySkipping(applySpeedup(positionUs));
}

@Override
Expand Down Expand Up @@ -938,6 +941,10 @@ private long applySpeedup(long positionUs) {
positionUs - playbackParametersPositionUs, playbackParameters.speed);
}

private long applySkipping(long positionUs) {
return positionUs + framesToDurationUs(silenceSkippingAudioProcessor.getSkippedFrames());
}

private boolean isInitialized() {
return audioTrack != null;
}
Expand Down
Loading

0 comments on commit 6dcfe57

Please sign in to comment.