165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian/* 265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * Copyright (C) 2007 The Android Open Source Project 365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * 465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * you may not use this file except in compliance with the License. 665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * You may obtain a copy of the License at 765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * 865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * 1065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * Unless required by applicable law or agreed to in writing, software 1165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 1265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * See the License for the specific language governing permissions and 1465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * limitations under the License. 1565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian */ 1665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#ifndef ANDROID_AUDIO_RESAMPLER_SINC_H 1865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#define ANDROID_AUDIO_RESAMPLER_SINC_H 1965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 2065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <stdint.h> 2165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <sys/types.h> 2265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <cutils/log.h> 2365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 2465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include "AudioResampler.h" 2565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 2665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopiannamespace android { 2765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 2841dfd129a181a5b0b62628733cf96e0ce11d64d7SathishKumar Mani 2941dfd129a181a5b0b62628733cf96e0ce11d64d7SathishKumar Manitypedef const int32_t * (*readCoefficientsFn)(bool upDownSample); 30a6d41334d25ffde12484eb28301352560a063ef6Glenn Kastentypedef int32_t (*readResampleFirNumCoeffFn)(); 31a6d41334d25ffde12484eb28301352560a063ef6Glenn Kastentypedef int32_t (*readResampleFirLerpIntBitsFn)(); 3241dfd129a181a5b0b62628733cf96e0ce11d64d7SathishKumar Mani 3365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ---------------------------------------------------------------------------- 3465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 3565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianclass AudioResamplerSinc : public AudioResampler { 3665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianpublic: 37a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten AudioResamplerSinc(int bitDepth, int inChannelCount, int32_t sampleRate, 38a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten src_quality quality = HIGH_QUALITY); 3965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 40c19e22450e6e3d07594c935c7a9522e85e909e82Glenn Kasten virtual ~AudioResamplerSinc(); 4165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 4265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian virtual void resample(int32_t* out, size_t outFrameCount, 4365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioBufferProvider* provider); 4465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianprivate: 4565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian void init(); 4665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 473c11ff2f409a0abb5b9d8ffd5e13cc42cda67fdcMathias Agopian virtual void setVolume(int16_t left, int16_t right); 483c11ff2f409a0abb5b9d8ffd5e13cc42cda67fdcMathias Agopian 4965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian template<int CHANNELS> 5065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian void resample(int32_t* out, size_t outFrameCount, 5165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioBufferProvider* provider); 5265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 5365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian template<int CHANNELS> 5465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian inline void filterCoefficient( 553c11ff2f409a0abb5b9d8ffd5e13cc42cda67fdcMathias Agopian int32_t* out, uint32_t phase, const int16_t *samples, uint32_t vRL); 5665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 5765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian template<int CHANNELS> 5865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian inline void interpolate( 5965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian int32_t& l, int32_t& r, 60e8299af5665bf9c396466c33b9b16a84fe78c7f6Mathias Agopian const int32_t* coefs, size_t offset, 61e8299af5665bf9c396466c33b9b16a84fe78c7f6Mathias Agopian int32_t lerp, const int16_t* samples); 6265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 6365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian template<int CHANNELS> 6465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian inline void read(int16_t*& impulse, uint32_t& phaseFraction, 6554c3b66444ebfb9f2265ee70ac3b76ccefa0506aGlenn Kasten const int16_t* in, size_t inputIndex); 6665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 6765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian int16_t *mState; 6865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian int16_t *mImpulse; 6965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian int16_t *mRingFull; 703c11ff2f409a0abb5b9d8ffd5e13cc42cda67fdcMathias Agopian int32_t mVolumeSIMD[2]; 7165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 7254c3b66444ebfb9f2265ee70ac3b76ccefa0506aGlenn Kasten const int32_t * mFirCoefs; 7392b1343f5fbc2fc43198a0a1252fe023cc9a5061Glenn Kasten static const uint32_t mFirCoefsDown[]; 7492b1343f5fbc2fc43198a0a1252fe023cc9a5061Glenn Kasten static const uint32_t mFirCoefsUp[]; 7565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 7665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // ---------------------------------------------------------------------------- 7765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian static const int32_t RESAMPLE_FIR_NUM_COEF = 8; 783bd72cc23f74e750069a2943ad3d5c9af3be4b55Mathias Agopian static const int32_t RESAMPLE_FIR_LERP_INT_BITS = 7; 7965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 80a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten struct Constants { 81a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten int coefsBits; 82a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten int cShift; 83a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten uint32_t cMask; 84a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten int pShift; 85a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten uint32_t pMask; 86a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten // number of zero-crossing on each side 87a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten unsigned int halfNumCoefs; 88a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten }; 8965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 90a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten static Constants highQualityConstants; 91a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten static Constants veryHighQualityConstants; 92a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten const Constants *mConstants; // points to appropriate set of coefficient parameters 9365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 94a6d41334d25ffde12484eb28301352560a063ef6Glenn Kasten static void init_routine(); 9565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}; 9665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 9765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ---------------------------------------------------------------------------- 9865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}; // namespace android 9965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 10065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#endif /*ANDROID_AUDIO_RESAMPLER_SINC_H*/ 101