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 "common/OboeDebug.h" 18 #include "InterpolatingDelayLine.h" 19 InterpolatingDelayLine(int32_t delaySize)20InterpolatingDelayLine::InterpolatingDelayLine(int32_t delaySize) { 21 mDelaySize = delaySize; 22 mDelayLine = std::make_unique<float[]>(delaySize); 23 } 24 process(float delay,float input)25float InterpolatingDelayLine::process(float delay, float input) { 26 float *writeAddress = mDelayLine.get() + mCursor; 27 *writeAddress = input; 28 mDelayLine.get()[mCursor] = input; 29 int32_t delayInt = std::min(mDelaySize - 1, (int32_t) delay); 30 int32_t readIndex = mCursor - delayInt; 31 if (readIndex < 0) { 32 readIndex += mDelaySize; 33 } 34 // TODO interpolate 35 float *readAddress = mDelayLine.get() + readIndex; 36 float output = *readAddress; 37 mCursor++; 38 if (mCursor >= mDelaySize) { 39 mCursor = 0; 40 } 41 return output; 42 }; 43