/*
   HARK Library
   Copyright (C) 2021 Honda Research Institute Japan Inc.
 */

#include "hark-lib/node/MultiGain.h"

#include "hark-lib/matrix.h"

namespace hark
{
namespace node
{
    MultiGain::MultiGain():
        NodeDef("MultiGain")
    {
        *this
            << Terminal::in("INPUT")
            << Terminal::in("GAIN").def(1.0f)
            >> Terminal::out("OUTPUT");
    }

    void
    MultiGain::reset()
    {
    }

    bool
    MultiGain::operator () (size_t count, InputDataBundle &input, OutputDataBundle &output)
    {
        const Matrix<float> &inputMatrix = input["INPUT"].last().cast<Matrix<float>>();
        float gain = input["GAIN"].last().cast<float>();

        data outputMatrixData = data::create<Matrix<float>>(inputMatrix.rows(), inputMatrix.cols());
        Matrix<float> &outputMatrix = outputMatrixData.cast<Matrix<float>>();

        outputMatrix = gain * inputMatrix;
        output["OUTPUT"].push(outputMatrixData);
        return true;
    }
}
}

/* end of file */
