From 68398b708eea921928b2be518e1f210ebf1d17a7 Mon Sep 17 00:00:00 2001 From: bachinger Date: Thu, 13 Feb 2020 17:50:03 +0000 Subject: [PATCH] remove pitch field from PlaybackParameters PiperOrigin-RevId: 294936851 --- .../mediasession/MediaSessionConnector.java | 6 ---- .../exoplayer2/PlaybackParameters.java | 31 +++---------------- .../android/exoplayer2/SimpleExoPlayer.java | 2 +- .../exoplayer2/audio/DefaultAudioSink.java | 9 +++--- .../android/exoplayer2/audio/Sonic.java | 20 ++++-------- .../exoplayer2/audio/SonicAudioProcessor.java | 30 ------------------ .../android/exoplayer2/util/EventLogger.java | 4 +-- .../android/exoplayer2/ExoPlayerTest.java | 2 +- .../audio/SonicAudioProcessorTest.java | 8 ----- .../android/exoplayer2/testutil/Action.java | 6 +--- 10 files changed, 20 insertions(+), 98 deletions(-) diff --git a/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java b/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java index 1e6a8b8328..61b82347ea 100644 --- a/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java +++ b/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java @@ -132,11 +132,6 @@ public final class MediaSessionConnector { * PlaybackParameters#speed}. */ public static final String EXTRAS_SPEED = "EXO_SPEED"; - /** - * The name of the {@link PlaybackStateCompat} float extra with the value of {@link - * PlaybackParameters#pitch}. - */ - public static final String EXTRAS_PITCH = "EXO_PITCH"; private static final long BASE_PLAYBACK_ACTIONS = PlaybackStateCompat.ACTION_PLAY_PAUSE @@ -773,7 +768,6 @@ public final class MediaSessionConnector { : MediaSessionCompat.QueueItem.UNKNOWN_ID; PlaybackParameters playbackParameters = player.getPlaybackParameters(); extras.putFloat(EXTRAS_SPEED, playbackParameters.speed); - extras.putFloat(EXTRAS_PITCH, playbackParameters.pitch); float sessionPlaybackSpeed = player.isPlaying() ? playbackParameters.speed : 0f; builder .setActions(buildPrepareActions() | buildPlaybackActions(player)) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/PlaybackParameters.java b/library/core/src/main/java/com/google/android/exoplayer2/PlaybackParameters.java index 057cb371e5..2cee02896f 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/PlaybackParameters.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/PlaybackParameters.java @@ -23,18 +23,12 @@ import com.google.android.exoplayer2.util.Assertions; */ public final class PlaybackParameters { - /** - * The default playback parameters: real-time playback with no pitch modification or silence - * skipping. - */ + /** The default playback parameters: real-time playback with no silence skipping. */ public static final PlaybackParameters DEFAULT = new PlaybackParameters(/* speed= */ 1f); /** The factor by which playback will be sped up. */ public final float speed; - /** The factor by which the audio pitch will be scaled. */ - public final float pitch; - /** Whether to skip silence in the input. */ public final boolean skipSilence; @@ -46,32 +40,19 @@ public final class PlaybackParameters { * @param speed The factor by which playback will be sped up. Must be greater than zero. */ public PlaybackParameters(float speed) { - this(speed, /* pitch= */ 1f, /* skipSilence= */ false); + this(speed, /* skipSilence= */ false); } /** - * Creates new playback parameters that set the playback speed and audio pitch scaling factor. + * Creates new playback parameters that set the playback speed and whether to skip silence in the + * audio stream. * * @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. - */ - public PlaybackParameters(float speed, float pitch) { - this(speed, pitch, /* skipSilence= */ false); - } - - /** - * Creates new playback parameters that set the playback speed, audio pitch scaling factor and - * whether to skip silence in the audio stream. - * - * @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) { + public PlaybackParameters(float speed, boolean skipSilence) { Assertions.checkArgument(speed > 0); - Assertions.checkArgument(pitch > 0); this.speed = speed; - this.pitch = pitch; this.skipSilence = skipSilence; scaledUsPerMs = Math.round(speed * 1000f); } @@ -97,7 +78,6 @@ public final class PlaybackParameters { } PlaybackParameters other = (PlaybackParameters) obj; return this.speed == other.speed - && this.pitch == other.pitch && this.skipSilence == other.skipSilence; } @@ -105,7 +85,6 @@ public final class PlaybackParameters { public int hashCode() { int result = 17; result = 31 * result + Float.floatToRawIntBits(speed); - result = 31 * result + Float.floatToRawIntBits(pitch); result = 31 * result + (skipSilence ? 1 : 0); return result; } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java index 6c993d2c4d..2349e1b487 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java @@ -857,7 +857,7 @@ public class SimpleExoPlayer extends BasePlayer PlaybackParameters playbackParameters; if (params != null) { params.allowDefaults(); - playbackParameters = new PlaybackParameters(params.getSpeed(), params.getPitch()); + playbackParameters = new PlaybackParameters(params.getSpeed()); } else { playbackParameters = null; } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java index 7f5a69fb33..aed6a14f43 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java @@ -143,7 +143,6 @@ public final class DefaultAudioSink implements AudioSink { silenceSkippingAudioProcessor.setEnabled(playbackParameters.skipSilence); return new PlaybackParameters( sonicAudioProcessor.setSpeed(playbackParameters.speed), - sonicAudioProcessor.setPitch(playbackParameters.pitch), playbackParameters.skipSilence); } @@ -295,8 +294,8 @@ public final class DefaultAudioSink implements AudioSink { * output. May be empty. * @param enableConvertHighResIntPcmToFloat Whether to enable conversion of high resolution * integer PCM to 32-bit float for output, if possible. Functionality that uses 16-bit integer - * audio processing (for example, speed and pitch adjustment) will not be available when float - * output is in use. + * audio processing (for example, speed adjustment) will not be available when float output is + * in use. */ public DefaultAudioSink( @Nullable AudioCapabilities audioCapabilities, @@ -318,8 +317,8 @@ public final class DefaultAudioSink implements AudioSink { * parameters adjustments. The instance passed in must not be reused in other sinks. * @param enableConvertHighResIntPcmToFloat Whether to enable conversion of high resolution * integer PCM to 32-bit float for output, if possible. Functionality that uses 16-bit integer - * audio processing (for example, speed and pitch adjustment) will not be available when float - * output is in use. + * audio processing (for example, speed adjustment) will not be available when float output is + * in use. */ public DefaultAudioSink( @Nullable AudioCapabilities audioCapabilities, diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/Sonic.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/Sonic.java index 6cd46bb705..50e424003d 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/Sonic.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/Sonic.java @@ -35,7 +35,6 @@ import java.util.Arrays; private final int inputSampleRateHz; private final int channelCount; private final float speed; - private final float pitch; private final float rate; private final int minPeriod; private final int maxPeriod; @@ -62,15 +61,12 @@ import java.util.Arrays; * @param inputSampleRateHz The sample rate of input audio, in hertz. * @param channelCount The number of channels in the input audio. * @param speed The speedup factor for output audio. - * @param pitch The pitch factor for output audio. * @param outputSampleRateHz The sample rate for output audio, in hertz. */ - public Sonic( - int inputSampleRateHz, int channelCount, float speed, float pitch, int outputSampleRateHz) { + public Sonic(int inputSampleRateHz, int channelCount, float speed, int outputSampleRateHz) { this.inputSampleRateHz = inputSampleRateHz; this.channelCount = channelCount; this.speed = speed; - this.pitch = pitch; rate = (float) inputSampleRateHz / outputSampleRateHz; minPeriod = inputSampleRateHz / MAXIMUM_PITCH; maxPeriod = inputSampleRateHz / MINIMUM_PITCH; @@ -120,10 +116,8 @@ import java.util.Arrays; */ public void queueEndOfStream() { int remainingFrameCount = inputFrameCount; - float s = speed / pitch; - float r = rate * pitch; int expectedOutputFrames = - outputFrameCount + (int) ((remainingFrameCount / s + pitchFrameCount) / r + 0.5f); + outputFrameCount + (int) ((remainingFrameCount / speed + pitchFrameCount) / rate + 0.5f); // Add enough silence to flush both input and pitch buffers. inputBuffer = @@ -468,16 +462,14 @@ import java.util.Arrays; private void processStreamInput() { // Resample as many pitch periods as we have buffered on the input. int originalOutputFrameCount = outputFrameCount; - float s = speed / pitch; - float r = rate * pitch; - if (s > 1.00001 || s < 0.99999) { - changeSpeed(s); + if (speed > 1.00001 || speed < 0.99999) { + changeSpeed(speed); } else { copyToOutput(inputBuffer, 0, inputFrameCount); inputFrameCount = 0; } - if (r != 1.0f) { - adjustRate(r, originalOutputFrameCount); + if (rate != 1.0f) { + adjustRate(rate, originalOutputFrameCount); } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/SonicAudioProcessor.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/SonicAudioProcessor.java index b9a59cd620..48075bac50 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/SonicAudioProcessor.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/SonicAudioProcessor.java @@ -37,14 +37,6 @@ public final class SonicAudioProcessor implements AudioProcessor { * The minimum allowed playback speed in {@link #setSpeed(float)}. */ public static final float MINIMUM_SPEED = 0.1f; - /** - * The maximum allowed pitch in {@link #setPitch(float)}. - */ - public static final float MAXIMUM_PITCH = 8.0f; - /** - * The minimum allowed pitch in {@link #setPitch(float)}. - */ - public static final float MINIMUM_PITCH = 0.1f; /** * Indicates that the output sample rate should be the same as the input. */ @@ -63,7 +55,6 @@ public final class SonicAudioProcessor implements AudioProcessor { private int pendingOutputSampleRate; private float speed; - private float pitch; private AudioFormat pendingInputAudioFormat; private AudioFormat pendingOutputAudioFormat; @@ -84,7 +75,6 @@ public final class SonicAudioProcessor implements AudioProcessor { */ public SonicAudioProcessor() { speed = 1f; - pitch = 1f; pendingInputAudioFormat = AudioFormat.NOT_SET; pendingOutputAudioFormat = AudioFormat.NOT_SET; inputAudioFormat = AudioFormat.NOT_SET; @@ -112,23 +102,6 @@ public final class SonicAudioProcessor implements AudioProcessor { return speed; } - /** - * Sets the playback pitch. This method may only be called after draining data through the - * processor. The value returned by {@link #isActive()} may change, and the processor must be - * {@link #flush() flushed} before queueing more data. - * - * @param pitch The requested new pitch. - * @return The actual new pitch. - */ - public float setPitch(float pitch) { - pitch = Util.constrainValue(pitch, MINIMUM_PITCH, MAXIMUM_PITCH); - if (this.pitch != pitch) { - this.pitch = pitch; - pendingSonicRecreation = true; - } - return pitch; - } - /** * Sets the sample rate for output audio, in Hertz. Pass {@link #SAMPLE_RATE_NO_CHANGE} to output * audio at the same sample rate as the input. After calling this method, call {@link @@ -182,7 +155,6 @@ public final class SonicAudioProcessor implements AudioProcessor { public boolean isActive() { return pendingOutputAudioFormat.sampleRate != Format.NO_VALUE && (Math.abs(speed - 1f) >= CLOSE_THRESHOLD - || Math.abs(pitch - 1f) >= CLOSE_THRESHOLD || pendingOutputAudioFormat.sampleRate != pendingInputAudioFormat.sampleRate); } @@ -243,7 +215,6 @@ public final class SonicAudioProcessor implements AudioProcessor { inputAudioFormat.sampleRate, inputAudioFormat.channelCount, speed, - pitch, outputAudioFormat.sampleRate); } else if (sonic != null) { sonic.flush(); @@ -258,7 +229,6 @@ public final class SonicAudioProcessor implements AudioProcessor { @Override public void reset() { speed = 1f; - pitch = 1f; pendingInputAudioFormat = AudioFormat.NOT_SET; pendingOutputAudioFormat = AudioFormat.NOT_SET; inputAudioFormat = AudioFormat.NOT_SET; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/util/EventLogger.java b/library/core/src/main/java/com/google/android/exoplayer2/util/EventLogger.java index eda3f93ba6..99dde4fabf 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/util/EventLogger.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/util/EventLogger.java @@ -150,8 +150,8 @@ public class EventLogger implements AnalyticsListener { eventTime, "playbackParameters", Util.formatInvariant( - "speed=%.2f, pitch=%.2f, skipSilence=%s", - playbackParameters.speed, playbackParameters.pitch, playbackParameters.skipSilence)); + "speed=%.2f, skipSilence=%s", + playbackParameters.speed, playbackParameters.skipSilence)); } @Override diff --git a/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java b/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java index 987e6296fa..4b3fcbe018 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java @@ -960,7 +960,7 @@ public final class ExoPlayerTest { } }) // Set playback parameters (while the fake media period is not yet prepared). - .setPlaybackParameters(new PlaybackParameters(/* speed= */ 2f, /* pitch= */ 2f)) + .setPlaybackParameters(new PlaybackParameters(/* speed= */ 2f)) // Complete preparation of the fake media period. .executeRunnable(() -> fakeMediaPeriodHolder[0].setPreparationComplete()) .build(); diff --git a/library/core/src/test/java/com/google/android/exoplayer2/audio/SonicAudioProcessorTest.java b/library/core/src/test/java/com/google/android/exoplayer2/audio/SonicAudioProcessorTest.java index e6b448774c..a09719a283 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/audio/SonicAudioProcessorTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/audio/SonicAudioProcessorTest.java @@ -85,14 +85,6 @@ public final class SonicAudioProcessorTest { assertThat(sonicAudioProcessor.isActive()).isTrue(); } - @Test - public void testIsActiveWithPitchChange() throws Exception { - sonicAudioProcessor.setPitch(1.5f); - sonicAudioProcessor.configure(AUDIO_FORMAT_44100_HZ); - sonicAudioProcessor.flush(); - assertThat(sonicAudioProcessor.isActive()).isTrue(); - } - @Test public void testIsNotActiveWithNoChange() throws Exception { sonicAudioProcessor.configure(AUDIO_FORMAT_44100_HZ); diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/Action.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/Action.java index 3b528db2f2..4f30b20da2 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/Action.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/Action.java @@ -624,11 +624,7 @@ public abstract class Action { "SetPlaybackParameters:" + (playbackParameters == null ? "null" - : +playbackParameters.speed - + ":" - + playbackParameters.pitch - + ":" - + playbackParameters.skipSilence)); + : playbackParameters.speed + ":" + playbackParameters.skipSilence)); this.playbackParameters = playbackParameters; }