blob: 1b14019bfd97723b07848211f325d4772f537771 [file] [log] [blame]
Mathias Agopian65ab4712010-07-14 17:59:35 -07001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_AUDIO_RESAMPLER_SINC_H
18#define ANDROID_AUDIO_RESAMPLER_SINC_H
19
20#include <stdint.h>
21#include <sys/types.h>
22#include <cutils/log.h>
23
24#include "AudioResampler.h"
25
26namespace android {
27
SathishKumar Mani41dfd122012-01-17 10:49:47 -080028
29typedef const int32_t * (*readCoefficientsFn)(bool upDownSample);
Glenn Kastena6d41332012-10-01 14:04:31 -070030typedef int32_t (*readResampleFirNumCoeffFn)();
31typedef int32_t (*readResampleFirLerpIntBitsFn)();
SathishKumar Mani41dfd122012-01-17 10:49:47 -080032
Mathias Agopian65ab4712010-07-14 17:59:35 -070033// ----------------------------------------------------------------------------
34
35class AudioResamplerSinc : public AudioResampler {
36public:
Glenn Kastena6d41332012-10-01 14:04:31 -070037 AudioResamplerSinc(int bitDepth, int inChannelCount, int32_t sampleRate,
38 src_quality quality = HIGH_QUALITY);
Mathias Agopian65ab4712010-07-14 17:59:35 -070039
Glenn Kastenc19e2242012-01-30 14:54:39 -080040 virtual ~AudioResamplerSinc();
Mathias Agopian65ab4712010-07-14 17:59:35 -070041
42 virtual void resample(int32_t* out, size_t outFrameCount,
43 AudioBufferProvider* provider);
44private:
45 void init();
46
47 template<int CHANNELS>
48 void resample(int32_t* out, size_t outFrameCount,
49 AudioBufferProvider* provider);
50
51 template<int CHANNELS>
52 inline void filterCoefficient(
Mathias Agopian50ebdf22012-11-03 23:37:53 -070053 int32_t& l, int32_t& r, uint32_t phase, const int16_t *samples, uint32_t vRL);
Mathias Agopian65ab4712010-07-14 17:59:35 -070054
55 template<int CHANNELS>
56 inline void interpolate(
57 int32_t& l, int32_t& r,
Mathias Agopiane8299af2012-11-04 02:03:49 -080058 const int32_t* coefs, size_t offset,
59 int32_t lerp, const int16_t* samples);
Mathias Agopian65ab4712010-07-14 17:59:35 -070060
61 template<int CHANNELS>
62 inline void read(int16_t*& impulse, uint32_t& phaseFraction,
Glenn Kasten54c3b662012-01-06 07:46:30 -080063 const int16_t* in, size_t inputIndex);
Mathias Agopian65ab4712010-07-14 17:59:35 -070064
65 int16_t *mState;
66 int16_t *mImpulse;
67 int16_t *mRingFull;
68
Glenn Kasten54c3b662012-01-06 07:46:30 -080069 const int32_t * mFirCoefs;
Mathias Agopian65ab4712010-07-14 17:59:35 -070070 static const int32_t mFirCoefsDown[];
71 static const int32_t mFirCoefsUp[];
72
73 // ----------------------------------------------------------------------------
74 static const int32_t RESAMPLE_FIR_NUM_COEF = 8;
Mathias Agopian3bd72cc2012-10-26 13:48:42 -070075 static const int32_t RESAMPLE_FIR_LERP_INT_BITS = 7;
Mathias Agopian65ab4712010-07-14 17:59:35 -070076
Glenn Kastena6d41332012-10-01 14:04:31 -070077 struct Constants {
78 // we have 16 coefs samples per zero-crossing
79 int coefsBits;
80 int cShift;
81 uint32_t cMask;
Mathias Agopian65ab4712010-07-14 17:59:35 -070082
Glenn Kastena6d41332012-10-01 14:04:31 -070083 int pShift;
84 uint32_t pMask;
Mathias Agopian65ab4712010-07-14 17:59:35 -070085
Glenn Kastena6d41332012-10-01 14:04:31 -070086 // number of zero-crossing on each side
87 unsigned int halfNumCoefs;
88 };
89
90 static Constants highQualityConstants;
91 static Constants veryHighQualityConstants;
92 const Constants *mConstants; // points to appropriate set of coefficient parameters
93
94 static void init_routine();
Mathias Agopian65ab4712010-07-14 17:59:35 -070095};
96
97// ----------------------------------------------------------------------------
98}; // namespace android
99
100#endif /*ANDROID_AUDIO_RESAMPLER_SINC_H*/