/* * Copyright 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.media; import android.annotation.IntDef; import android.annotation.TestApi; import android.compat.annotation.UnsupportedAppUsage; import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** * Structure for common playback params. * * Used by {@link AudioTrack} {@link AudioTrack#getPlaybackParams()} and * {@link AudioTrack#setPlaybackParams(PlaybackParams)} * to control playback behavior. *
audio fallback mode: * select out-of-range parameter handling. *
AudioTrack.setPlaybackParams(PlaybackParams)
.pitch: increases or decreases the tonal frequency of the audio content. * It is expressed as a multiplicative factor, where normal pitch is 1.0f. *
speed: increases or decreases the time to * play back a set of audio or video frames. * It is expressed as a multiplicative factor, where normal speed is 1.0f. *
Different combinations of speed and pitch may be used for audio playback; * some common ones: *
PlaybackParams
instance.
*/
public PlaybackParams allowDefaults() {
mSet |= SET_AUDIO_FALLBACK_MODE | SET_AUDIO_STRETCH_MODE | SET_PITCH | SET_SPEED;
return this;
}
/**
* Sets the audio fallback mode.
* @param audioFallbackMode
* @return this PlaybackParams
instance.
*/
public PlaybackParams setAudioFallbackMode(@AudioFallbackMode int audioFallbackMode) {
mAudioFallbackMode = audioFallbackMode;
mSet |= SET_AUDIO_FALLBACK_MODE;
return this;
}
/**
* Retrieves the audio fallback mode.
* @return audio fallback mode
* @throws IllegalStateException if the audio fallback mode is not set.
*/
public @AudioFallbackMode int getAudioFallbackMode() {
if ((mSet & SET_AUDIO_FALLBACK_MODE) == 0) {
throw new IllegalStateException("audio fallback mode not set");
}
return mAudioFallbackMode;
}
/**
* @hide
* Sets the audio stretch mode.
* @param audioStretchMode
* @return this PlaybackParams
instance.
*/
@TestApi
public PlaybackParams setAudioStretchMode(@AudioStretchMode int audioStretchMode) {
mAudioStretchMode = audioStretchMode;
mSet |= SET_AUDIO_STRETCH_MODE;
return this;
}
/**
* @hide
* Retrieves the audio stretch mode.
* @return audio stretch mode
* @throws IllegalStateException if the audio stretch mode is not set.
*/
@TestApi
public @AudioStretchMode int getAudioStretchMode() {
if ((mSet & SET_AUDIO_STRETCH_MODE) == 0) {
throw new IllegalStateException("audio stretch mode not set");
}
return mAudioStretchMode;
}
/**
* Sets the pitch factor.
* @param pitch
* @return this PlaybackParams
instance.
* @throws IllegalArgumentException if the pitch is negative.
*/
public PlaybackParams setPitch(float pitch) {
if (pitch < 0.f) {
throw new IllegalArgumentException("pitch must not be negative");
}
mPitch = pitch;
mSet |= SET_PITCH;
return this;
}
/**
* Retrieves the pitch factor.
* @return pitch
* @throws IllegalStateException if pitch is not set.
*/
public float getPitch() {
if ((mSet & SET_PITCH) == 0) {
throw new IllegalStateException("pitch not set");
}
return mPitch;
}
/**
* Sets the speed factor.
* @param speed
* @return this PlaybackParams
instance.
*/
public PlaybackParams setSpeed(float speed) {
mSpeed = speed;
mSet |= SET_SPEED;
return this;
}
/**
* Retrieves the speed factor.
* @return speed
* @throws IllegalStateException if speed is not set.
*/
public float getSpeed() {
if ((mSet & SET_SPEED) == 0) {
throw new IllegalStateException("speed not set");
}
return mSpeed;
}
public static final @android.annotation.NonNull Parcelable.Creator