1 /*
2  * Copyright 2021 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 <unistd.h>
18 #include "FlowGraphNode.h"
19 #include "MultiToManyConverter.h"
20 
21 using namespace FLOWGRAPH_OUTER_NAMESPACE::flowgraph;
22 
MultiToManyConverter(int32_t channelCount)23 MultiToManyConverter::MultiToManyConverter(int32_t channelCount)
24         : outputs(channelCount)
25         , input(*this, channelCount) {
26     for (int i = 0; i < channelCount; i++) {
27         outputs[i] = std::make_unique<FlowGraphPortFloatOutput>(*this, 1);
28     }
29 }
30 
31 MultiToManyConverter::~MultiToManyConverter() = default;
32 
onProcess(int32_t numFrames)33 int32_t MultiToManyConverter::onProcess(int32_t numFrames) {
34     int32_t channelCount = input.getSamplesPerFrame();
35 
36     for (int ch = 0; ch < channelCount; ch++) {
37         const float *inputBuffer = input.getBuffer() + ch;
38         float *outputBuffer = outputs[ch]->getBuffer();
39 
40         for (int i = 0; i < numFrames; i++) {
41             *outputBuffer++ = *inputBuffer;
42             inputBuffer += channelCount;
43         }
44     }
45 
46     return numFrames;
47 }
48