From 5a8a95de6dad1a3bcf3da5a37b35766e89086e13 Mon Sep 17 00:00:00 2001 From: Ricardo Garcia Date: Sat, 18 Apr 2015 14:47:04 -0700 Subject: Use AudioPlaybackRate to hold TimestretchBufferProvider parameters Use this struct to handle the parameters for TimestretchBufferProvider all across the system. Add stretch mode and fallback mode to TimestretchBuffer Provider. Change-Id: I19099924a7003c62e48bb6ead56c785cb129fba2 --- services/audioflinger/AudioMixer.cpp | 46 ++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'services/audioflinger/AudioMixer.cpp') diff --git a/services/audioflinger/AudioMixer.cpp b/services/audioflinger/AudioMixer.cpp index c2c791f..18ce1d0 100644 --- a/services/audioflinger/AudioMixer.cpp +++ b/services/audioflinger/AudioMixer.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include "AudioMixerOps.h" #include "AudioMixer.h" @@ -223,8 +222,7 @@ int AudioMixer::getTrackName(audio_channel_mask_t channelMask, t->mMixerChannelMask = audio_channel_mask_from_representation_and_bits( AUDIO_CHANNEL_REPRESENTATION_POSITION, AUDIO_CHANNEL_OUT_STEREO); t->mMixerChannelCount = audio_channel_count_from_out_mask(t->mMixerChannelMask); - t->mSpeed = AUDIO_TIMESTRETCH_SPEED_NORMAL; - t->mPitch = AUDIO_TIMESTRETCH_PITCH_NORMAL; + t->mPlaybackRate = AUDIO_PLAYBACK_RATE_DEFAULT; // Check the downmixing (or upmixing) requirements. status_t status = t->prepareForDownmix(); if (status != OK) { @@ -668,19 +666,25 @@ void AudioMixer::setParameter(int name, int target, int param, void *value) case TIMESTRETCH: switch (param) { case PLAYBACK_RATE: { - const float speed = reinterpret_cast(value)[0]; - const float pitch = reinterpret_cast(value)[1]; - ALOG_ASSERT(AUDIO_TIMESTRETCH_SPEED_MIN <= speed - && speed <= AUDIO_TIMESTRETCH_SPEED_MAX, - "bad speed %f", speed); - ALOG_ASSERT(AUDIO_TIMESTRETCH_PITCH_MIN <= pitch - && pitch <= AUDIO_TIMESTRETCH_PITCH_MAX, - "bad pitch %f", pitch); - if (track.setPlaybackRate(speed, pitch)) { - ALOGV("setParameter(TIMESTRETCH, PLAYBACK_RATE, %f %f", speed, pitch); + const AudioPlaybackRate *playbackRate = + reinterpret_cast(value); + ALOG_ASSERT(AUDIO_TIMESTRETCH_SPEED_MIN <= playbackRate->mSpeed + && playbackRate->mSpeed <= AUDIO_TIMESTRETCH_SPEED_MAX, + "bad speed %f", playbackRate->mSpeed); + ALOG_ASSERT(AUDIO_TIMESTRETCH_PITCH_MIN <= playbackRate->mPitch + && playbackRate->mPitch <= AUDIO_TIMESTRETCH_PITCH_MAX, + "bad pitch %f", playbackRate->mPitch); + //TODO: use function from AudioResamplerPublic.h to test validity. + if (track.setPlaybackRate(*playbackRate)) { + ALOGV("setParameter(TIMESTRETCH, PLAYBACK_RATE, STRETCH_MODE, FALLBACK_MODE " + "%f %f %d %d", + playbackRate->mSpeed, + playbackRate->mPitch, + playbackRate->mStretchMode, + playbackRate->mFallbackMode); // invalidateState(1 << name); } - } break; + } break; default: LOG_ALWAYS_FATAL("setParameter timestretch: bad param %d", param); } @@ -730,24 +734,26 @@ bool AudioMixer::track_t::setResampler(uint32_t trackSampleRate, uint32_t devSam return false; } -bool AudioMixer::track_t::setPlaybackRate(float speed, float pitch) +bool AudioMixer::track_t::setPlaybackRate(const AudioPlaybackRate &playbackRate) { - if (speed == mSpeed && pitch == mPitch) { + if ((mTimestretchBufferProvider == NULL && + fabs(playbackRate.mSpeed - mPlaybackRate.mSpeed) < AUDIO_TIMESTRETCH_SPEED_MIN_DELTA && + fabs(playbackRate.mPitch - mPlaybackRate.mPitch) < AUDIO_TIMESTRETCH_PITCH_MIN_DELTA) || + isAudioPlaybackRateEqual(playbackRate, mPlaybackRate)) { return false; } - mSpeed = speed; - mPitch = pitch; + mPlaybackRate = playbackRate; if (mTimestretchBufferProvider == NULL) { // TODO: Remove MONO_HACK. Resampler sees #channels after the downmixer // but if none exists, it is the channel count (1 for mono). const int timestretchChannelCount = downmixerBufferProvider != NULL ? mMixerChannelCount : channelCount; mTimestretchBufferProvider = new TimestretchBufferProvider(timestretchChannelCount, - mMixerInFormat, sampleRate, speed, pitch); + mMixerInFormat, sampleRate, playbackRate); reconfigureBufferProviders(); } else { reinterpret_cast(mTimestretchBufferProvider) - ->setPlaybackRate(speed, pitch); + ->setPlaybackRate(playbackRate); } return true; } -- cgit v1.1