1*05767d91SRobert Wu /* 2*05767d91SRobert Wu * Copyright 2018 The Android Open Source Project 3*05767d91SRobert Wu * 4*05767d91SRobert Wu * Licensed under the Apache License, Version 2.0 (the "License"); 5*05767d91SRobert Wu * you may not use this file except in compliance with the License. 6*05767d91SRobert Wu * You may obtain a copy of the License at 7*05767d91SRobert Wu * 8*05767d91SRobert Wu * http://www.apache.org/licenses/LICENSE-2.0 9*05767d91SRobert Wu * 10*05767d91SRobert Wu * Unless required by applicable law or agreed to in writing, software 11*05767d91SRobert Wu * distributed under the License is distributed on an "AS IS" BASIS, 12*05767d91SRobert Wu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*05767d91SRobert Wu * See the License for the specific language governing permissions and 14*05767d91SRobert Wu * limitations under the License. 15*05767d91SRobert Wu */ 16*05767d91SRobert Wu 17*05767d91SRobert Wu #include <unistd.h> 18*05767d91SRobert Wu 19*05767d91SRobert Wu #include "ManyToMultiConverter.h" 20*05767d91SRobert Wu 21*05767d91SRobert Wu using namespace FLOWGRAPH_OUTER_NAMESPACE::flowgraph; 22*05767d91SRobert Wu ManyToMultiConverter(int32_t channelCount)23*05767d91SRobert WuManyToMultiConverter::ManyToMultiConverter(int32_t channelCount) 24*05767d91SRobert Wu : inputs(channelCount) 25*05767d91SRobert Wu , output(*this, channelCount) { 26*05767d91SRobert Wu for (int i = 0; i < channelCount; i++) { 27*05767d91SRobert Wu inputs[i] = std::make_unique<FlowGraphPortFloatInput>(*this, 1); 28*05767d91SRobert Wu } 29*05767d91SRobert Wu } 30*05767d91SRobert Wu onProcess(int32_t numFrames)31*05767d91SRobert Wuint32_t ManyToMultiConverter::onProcess(int32_t numFrames) { 32*05767d91SRobert Wu int32_t channelCount = output.getSamplesPerFrame(); 33*05767d91SRobert Wu 34*05767d91SRobert Wu for (int ch = 0; ch < channelCount; ch++) { 35*05767d91SRobert Wu const float *inputBuffer = inputs[ch]->getBuffer(); 36*05767d91SRobert Wu float *outputBuffer = output.getBuffer() + ch; 37*05767d91SRobert Wu 38*05767d91SRobert Wu for (int i = 0; i < numFrames; i++) { 39*05767d91SRobert Wu // read one, write into the proper interleaved output channel 40*05767d91SRobert Wu float sample = *inputBuffer++; 41*05767d91SRobert Wu *outputBuffer = sample; 42*05767d91SRobert Wu outputBuffer += channelCount; // advance to next multichannel frame 43*05767d91SRobert Wu } 44*05767d91SRobert Wu } 45*05767d91SRobert Wu return numFrames; 46*05767d91SRobert Wu } 47*05767d91SRobert Wu 48