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 <algorithm> 18*05767d91SRobert Wu #include <unistd.h> 19*05767d91SRobert Wu #include "FlowGraphNode.h" 20*05767d91SRobert Wu #include "SinkFloat.h" 21*05767d91SRobert Wu 22*05767d91SRobert Wu using namespace FLOWGRAPH_OUTER_NAMESPACE::flowgraph; 23*05767d91SRobert Wu SinkFloat(int32_t channelCount)24*05767d91SRobert WuSinkFloat::SinkFloat(int32_t channelCount) 25*05767d91SRobert Wu : FlowGraphSink(channelCount) { 26*05767d91SRobert Wu } 27*05767d91SRobert Wu read(void * data,int32_t numFrames)28*05767d91SRobert Wuint32_t SinkFloat::read(void *data, int32_t numFrames) { 29*05767d91SRobert Wu float *floatData = (float *) data; 30*05767d91SRobert Wu const int32_t channelCount = input.getSamplesPerFrame(); 31*05767d91SRobert Wu 32*05767d91SRobert Wu int32_t framesLeft = numFrames; 33*05767d91SRobert Wu while (framesLeft > 0) { 34*05767d91SRobert Wu // Run the graph and pull data through the input port. 35*05767d91SRobert Wu int32_t framesPulled = pullData(framesLeft); 36*05767d91SRobert Wu if (framesPulled <= 0) { 37*05767d91SRobert Wu break; 38*05767d91SRobert Wu } 39*05767d91SRobert Wu const float *signal = input.getBuffer(); 40*05767d91SRobert Wu int32_t numSamples = framesPulled * channelCount; 41*05767d91SRobert Wu memcpy(floatData, signal, numSamples * sizeof(float)); 42*05767d91SRobert Wu floatData += numSamples; 43*05767d91SRobert Wu framesLeft -= framesPulled; 44*05767d91SRobert Wu } 45*05767d91SRobert Wu return numFrames - framesLeft; 46*05767d91SRobert Wu } 47