Loading include/media/AudioResamplerPublic.h 0 → 100644 +29 −0 Original line number Diff line number Diff line /* * Copyright (C) 2014 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. */ #ifndef ANDROID_AUDIO_RESAMPLER_PUBLIC_H #define ANDROID_AUDIO_RESAMPLER_PUBLIC_H // AUDIO_RESAMPLER_DOWN_RATIO_MAX is the maximum ratio between the original // audio sample rate and the target rate when downsampling, // as permitted in the audio framework, e.g. AudioTrack and AudioFlinger. // In practice, it is not recommended to downsample more than 6:1 // for best audio quality, even though the audio framework permits a larger // downsampling ratio. // TODO: replace with an API #define AUDIO_RESAMPLER_DOWN_RATIO_MAX 256 #endif // ANDROID_AUDIO_RESAMPLER_PUBLIC_H media/libmedia/AudioTrack.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ #include <utils/Log.h> #include <private/media/AudioTrackShared.h> #include <media/IAudioFlinger.h> #include <media/AudioResamplerPublic.h> #define WAIT_PERIOD_MS 10 #define WAIT_STREAM_END_TIMEOUT_SEC 120 Loading Loading @@ -82,7 +83,7 @@ status_t AudioTrack::getMinFrameCount( } *frameCount = (sampleRate == 0) ? afFrameCount * minBufCount : afFrameCount * minBufCount * sampleRate / afSampleRate; afFrameCount * minBufCount * uint64_t(sampleRate) / afSampleRate; // The formula above should always produce a non-zero value, but return an error // in the unlikely event that it does not, as that's part of the API contract. if (*frameCount == 0) { Loading Loading @@ -646,8 +647,7 @@ status_t AudioTrack::setSampleRate(uint32_t rate) if (AudioSystem::getOutputSamplingRateForAttr(&afSamplingRate, &mAttributes) != NO_ERROR) { return NO_INIT; } // Resampler implementation limits input sampling rate to 2 x output sampling rate. if (rate == 0 || rate > afSamplingRate*2 ) { if (rate == 0 || rate > afSamplingRate * AUDIO_RESAMPLER_DOWN_RATIO_MAX) { return BAD_VALUE; } Loading Loading @@ -1002,7 +1002,7 @@ status_t AudioTrack::createTrack_l(size_t epoch) minBufCount = nBuffering; } size_t minFrameCount = (afFrameCount*mSampleRate*minBufCount)/afSampleRate; size_t minFrameCount = afFrameCount * minBufCount * uint64_t(mSampleRate) / afSampleRate; ALOGV("minFrameCount: %zu, afFrameCount=%zu, minBufCount=%d, sampleRate=%u, afSampleRate=%u" ", afLatency=%d", minFrameCount, afFrameCount, minBufCount, mSampleRate, afSampleRate, afLatency); Loading services/audioflinger/AudioResamplerDyn.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -393,7 +393,7 @@ void AudioResamplerDyn<TC, TI, TO>::setSampleRate(int32_t inSampleRate) mPhaseFraction = static_cast<unsigned long long>(mPhaseFraction) * phaseWrapLimit / oldPhaseWrapLimit; mPhaseFraction %= phaseWrapLimit; // should not do anything, but just in case. mPhaseIncrement = static_cast<uint32_t>(static_cast<double>(phaseWrapLimit) mPhaseIncrement = static_cast<uint32_t>(static_cast<uint64_t>(phaseWrapLimit) * inSampleRate / mSampleRate); // determine which resampler to use Loading services/audioflinger/Threads.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include <sys/stat.h> #include <cutils/properties.h> #include <media/AudioParameter.h> #include <media/AudioResamplerPublic.h> #include <utils/Log.h> #include <utils/Trace.h> Loading Loading @@ -1479,8 +1480,7 @@ sp<AudioFlinger::PlaybackThread::Track> AudioFlinger::PlaybackThread::createTrac lStatus = BAD_VALUE; goto Exit; } // Resampler implementation limits input sampling rate to 2 x output sampling rate. if (sampleRate > mSampleRate*2) { if (sampleRate > mSampleRate * AUDIO_RESAMPLER_DOWN_RATIO_MAX) { ALOGE("Sample rate out of range: %u mSampleRate %u", sampleRate, mSampleRate); lStatus = BAD_VALUE; goto Exit; Loading Loading @@ -3500,7 +3500,7 @@ AudioFlinger::PlaybackThread::mixer_state AudioFlinger::MixerThread::prepareTrac AudioMixer::TRACK, AudioMixer::MIXER_CHANNEL_MASK, (void *)(uintptr_t)mChannelMask); // limit track sample rate to 2 x output sample rate, which changes at re-configuration uint32_t maxSampleRate = mSampleRate * 2; uint32_t maxSampleRate = mSampleRate * AUDIO_RESAMPLER_DOWN_RATIO_MAX; uint32_t reqSampleRate = track->mAudioTrackServerProxy->getSampleRate(); if (reqSampleRate == 0) { reqSampleRate = mSampleRate; Loading Loading
include/media/AudioResamplerPublic.h 0 → 100644 +29 −0 Original line number Diff line number Diff line /* * Copyright (C) 2014 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. */ #ifndef ANDROID_AUDIO_RESAMPLER_PUBLIC_H #define ANDROID_AUDIO_RESAMPLER_PUBLIC_H // AUDIO_RESAMPLER_DOWN_RATIO_MAX is the maximum ratio between the original // audio sample rate and the target rate when downsampling, // as permitted in the audio framework, e.g. AudioTrack and AudioFlinger. // In practice, it is not recommended to downsample more than 6:1 // for best audio quality, even though the audio framework permits a larger // downsampling ratio. // TODO: replace with an API #define AUDIO_RESAMPLER_DOWN_RATIO_MAX 256 #endif // ANDROID_AUDIO_RESAMPLER_PUBLIC_H
media/libmedia/AudioTrack.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ #include <utils/Log.h> #include <private/media/AudioTrackShared.h> #include <media/IAudioFlinger.h> #include <media/AudioResamplerPublic.h> #define WAIT_PERIOD_MS 10 #define WAIT_STREAM_END_TIMEOUT_SEC 120 Loading Loading @@ -82,7 +83,7 @@ status_t AudioTrack::getMinFrameCount( } *frameCount = (sampleRate == 0) ? afFrameCount * minBufCount : afFrameCount * minBufCount * sampleRate / afSampleRate; afFrameCount * minBufCount * uint64_t(sampleRate) / afSampleRate; // The formula above should always produce a non-zero value, but return an error // in the unlikely event that it does not, as that's part of the API contract. if (*frameCount == 0) { Loading Loading @@ -646,8 +647,7 @@ status_t AudioTrack::setSampleRate(uint32_t rate) if (AudioSystem::getOutputSamplingRateForAttr(&afSamplingRate, &mAttributes) != NO_ERROR) { return NO_INIT; } // Resampler implementation limits input sampling rate to 2 x output sampling rate. if (rate == 0 || rate > afSamplingRate*2 ) { if (rate == 0 || rate > afSamplingRate * AUDIO_RESAMPLER_DOWN_RATIO_MAX) { return BAD_VALUE; } Loading Loading @@ -1002,7 +1002,7 @@ status_t AudioTrack::createTrack_l(size_t epoch) minBufCount = nBuffering; } size_t minFrameCount = (afFrameCount*mSampleRate*minBufCount)/afSampleRate; size_t minFrameCount = afFrameCount * minBufCount * uint64_t(mSampleRate) / afSampleRate; ALOGV("minFrameCount: %zu, afFrameCount=%zu, minBufCount=%d, sampleRate=%u, afSampleRate=%u" ", afLatency=%d", minFrameCount, afFrameCount, minBufCount, mSampleRate, afSampleRate, afLatency); Loading
services/audioflinger/AudioResamplerDyn.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -393,7 +393,7 @@ void AudioResamplerDyn<TC, TI, TO>::setSampleRate(int32_t inSampleRate) mPhaseFraction = static_cast<unsigned long long>(mPhaseFraction) * phaseWrapLimit / oldPhaseWrapLimit; mPhaseFraction %= phaseWrapLimit; // should not do anything, but just in case. mPhaseIncrement = static_cast<uint32_t>(static_cast<double>(phaseWrapLimit) mPhaseIncrement = static_cast<uint32_t>(static_cast<uint64_t>(phaseWrapLimit) * inSampleRate / mSampleRate); // determine which resampler to use Loading
services/audioflinger/Threads.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include <sys/stat.h> #include <cutils/properties.h> #include <media/AudioParameter.h> #include <media/AudioResamplerPublic.h> #include <utils/Log.h> #include <utils/Trace.h> Loading Loading @@ -1479,8 +1480,7 @@ sp<AudioFlinger::PlaybackThread::Track> AudioFlinger::PlaybackThread::createTrac lStatus = BAD_VALUE; goto Exit; } // Resampler implementation limits input sampling rate to 2 x output sampling rate. if (sampleRate > mSampleRate*2) { if (sampleRate > mSampleRate * AUDIO_RESAMPLER_DOWN_RATIO_MAX) { ALOGE("Sample rate out of range: %u mSampleRate %u", sampleRate, mSampleRate); lStatus = BAD_VALUE; goto Exit; Loading Loading @@ -3500,7 +3500,7 @@ AudioFlinger::PlaybackThread::mixer_state AudioFlinger::MixerThread::prepareTrac AudioMixer::TRACK, AudioMixer::MIXER_CHANNEL_MASK, (void *)(uintptr_t)mChannelMask); // limit track sample rate to 2 x output sample rate, which changes at re-configuration uint32_t maxSampleRate = mSampleRate * 2; uint32_t maxSampleRate = mSampleRate * AUDIO_RESAMPLER_DOWN_RATIO_MAX; uint32_t reqSampleRate = track->mAudioTrackServerProxy->getSampleRate(); if (reqSampleRate == 0) { reqSampleRate = mSampleRate; Loading