Commit ba8bbd89 by andrewlewis Committed by Oliver Woodman

Add skip silence option to PlaybackParameters

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=190917894
parent 017c95ff
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
* Fix an issue where the playback position would pause just after playback * Fix an issue where the playback position would pause just after playback
begins, and poll the audio timestamp less frequently once it starts begins, and poll the audio timestamp less frequently once it starts
advancing ([#3841](https://github.com/google/ExoPlayer/issues/3841)). advancing ([#3841](https://github.com/google/ExoPlayer/issues/3841)).
* Add an option to skip silent audio in `PlaybackParameters`
((#2635)[https://github.com/google/ExoPlayer/issues/2635]).
* Caching: * Caching:
* Add release method to Cache interface. * Add release method to Cache interface.
* Prevent multiple instances of SimpleCache in the same folder. * Prevent multiple instances of SimpleCache in the same folder.
......
...@@ -22,21 +22,19 @@ import com.google.android.exoplayer2.util.Assertions; ...@@ -22,21 +22,19 @@ import com.google.android.exoplayer2.util.Assertions;
*/ */
public final class PlaybackParameters { public final class PlaybackParameters {
/** /** The default playback parameters: real-time playback with no pitch modification. */
* The default playback parameters: real-time playback with no pitch modification. public static final PlaybackParameters DEFAULT =
*/ new PlaybackParameters(/* speed= */ 1f, /* pitch= */ 1f, /* skipSilence= */ false);
public static final PlaybackParameters DEFAULT = new PlaybackParameters(1f, 1f);
/** /** The factor by which playback will be sped up. */
* The factor by which playback will be sped up.
*/
public final float speed; public final float speed;
/** /** The factor by which the audio pitch will be scaled. */
* The factor by which the audio pitch will be scaled.
*/
public final float pitch; public final float pitch;
/** Whether to skip silence in the input. */
public final boolean skipSilence;
private final int scaledUsPerMs; private final int scaledUsPerMs;
/** /**
...@@ -46,10 +44,22 @@ public final class PlaybackParameters { ...@@ -46,10 +44,22 @@ public final class PlaybackParameters {
* @param pitch The factor by which the audio pitch will be scaled. Must be greater than zero. * @param pitch The factor by which the audio pitch will be scaled. Must be greater than zero.
*/ */
public PlaybackParameters(float speed, float pitch) { public PlaybackParameters(float speed, float pitch) {
this(speed, pitch, /* skipSilence= */ false);
}
/**
* Creates new playback parameters.
*
* @param speed The factor by which playback will be sped up. Must be greater than zero.
* @param pitch The factor by which the audio pitch will be scaled. Must be greater than zero.
* @param skipSilence Whether to skip silences in the audio stream.
*/
public PlaybackParameters(float speed, float pitch, boolean skipSilence) {
Assertions.checkArgument(speed > 0); Assertions.checkArgument(speed > 0);
Assertions.checkArgument(pitch > 0); Assertions.checkArgument(pitch > 0);
this.speed = speed; this.speed = speed;
this.pitch = pitch; this.pitch = pitch;
this.skipSilence = skipSilence;
scaledUsPerMs = Math.round(speed * 1000f); scaledUsPerMs = Math.round(speed * 1000f);
} }
...@@ -73,14 +83,17 @@ public final class PlaybackParameters { ...@@ -73,14 +83,17 @@ public final class PlaybackParameters {
return false; return false;
} }
PlaybackParameters other = (PlaybackParameters) obj; PlaybackParameters other = (PlaybackParameters) obj;
return this.speed == other.speed && this.pitch == other.pitch; return this.speed == other.speed
&& this.pitch == other.pitch
&& this.skipSilence == other.skipSilence;
} }
@Override @Override
public int hashCode() { public int hashCode() {
int result = 17; int result = 17;
result = 31 * result + Float.floatToRawIntBits(speed); result = 31 * result + Float.floatToRawIntBits(speed);
result = 31 * result + Float.floatToRawIntBits(pitch); result = 31 * result + Float.floatToRawIntBits(pitch);
result = 31 * result + (skipSilence ? 1 : 0);
return result; return result;
} }
......
...@@ -738,9 +738,12 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -738,9 +738,12 @@ public final class DefaultAudioSink implements AudioSink {
this.playbackParameters = PlaybackParameters.DEFAULT; this.playbackParameters = PlaybackParameters.DEFAULT;
return this.playbackParameters; return this.playbackParameters;
} }
playbackParameters = new PlaybackParameters( playbackParameters =
sonicAudioProcessor.setSpeed(playbackParameters.speed), new PlaybackParameters(
sonicAudioProcessor.setPitch(playbackParameters.pitch)); sonicAudioProcessor.setSpeed(playbackParameters.speed),
sonicAudioProcessor.setPitch(playbackParameters.pitch),
playbackParameters.skipSilence);
silenceSkippingAudioProcessor.setEnabled(playbackParameters.skipSilence);
PlaybackParameters lastSetPlaybackParameters = PlaybackParameters lastSetPlaybackParameters =
drainingPlaybackParameters != null ? drainingPlaybackParameters drainingPlaybackParameters != null ? drainingPlaybackParameters
: !playbackParametersCheckpoints.isEmpty() : !playbackParametersCheckpoints.isEmpty()
......
...@@ -115,8 +115,8 @@ public class EventLogger ...@@ -115,8 +115,8 @@ public class EventLogger
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
logd( logd(
Util.formatInvariant( Util.formatInvariant(
"playbackParameters [speed=%.2f, pitch=%.2f]", "playbackParameters [speed=%.2f, pitch=%.2f, skipSilence=%s]",
playbackParameters.speed, playbackParameters.pitch)); playbackParameters.speed, playbackParameters.pitch, playbackParameters.skipSilence));
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment