1 /* 2 * Copyright 2019 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 #include "LinearResampler.h" 18 19 using namespace RESAMPLER_OUTER_NAMESPACE::resampler; 20 LinearResampler(const MultiChannelResampler::Builder & builder)21LinearResampler::LinearResampler(const MultiChannelResampler::Builder &builder) 22 : MultiChannelResampler(builder) { 23 mPreviousFrame = std::make_unique<float[]>(getChannelCount()); 24 mCurrentFrame = std::make_unique<float[]>(getChannelCount()); 25 } 26 writeFrame(const float * frame)27void LinearResampler::writeFrame(const float *frame) { 28 memcpy(mPreviousFrame.get(), mCurrentFrame.get(), sizeof(float) * getChannelCount()); 29 memcpy(mCurrentFrame.get(), frame, sizeof(float) * getChannelCount()); 30 } 31 readFrame(float * frame)32void LinearResampler::readFrame(float *frame) { 33 float *previous = mPreviousFrame.get(); 34 float *current = mCurrentFrame.get(); 35 float phase = (float) getIntegerPhase() / mDenominator; 36 // iterate across samples in the frame 37 for (int channel = 0; channel < getChannelCount(); channel++) { 38 float f0 = *previous++; 39 float f1 = *current++; 40 *frame++ = f0 + (phase * (f1 - f0)); 41 } 42 } 43