2024-12-19 16:20:00 +08:00
|
|
|
//
|
|
|
|
// ShapeStft.cpp
|
|
|
|
// MNN
|
|
|
|
//
|
|
|
|
// Created by MNN on 2024/11/26.
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "shape/SizeComputer.hpp"
|
|
|
|
#include "core/Macro.h"
|
|
|
|
#include "core/TensorUtils.hpp"
|
|
|
|
|
|
|
|
namespace MNN {
|
|
|
|
|
|
|
|
class StftOpComputer : public SizeComputer {
|
|
|
|
virtual bool onComputeSize(const MNN::Op* op, const std::vector<Tensor*>& inputs,
|
|
|
|
const std::vector<Tensor*>& outputs) const override {
|
2025-02-12 11:14:19 +08:00
|
|
|
int batch_size = inputs[0]->length(0);
|
|
|
|
int signal_length = inputs[0]->length(1);
|
|
|
|
outputs[0]->buffer().dimensions = 4;
|
|
|
|
outputs[0]->setLength(3, 2);
|
|
|
|
outputs[0]->setLength(0, batch_size);
|
|
|
|
int frame_length = inputs[2]->length(0);
|
|
|
|
int nstfts = ((signal_length - frame_length) / inputs[1]->host<int>()[0]) + 1;
|
|
|
|
outputs[0]->setLength(1, nstfts);
|
|
|
|
|
|
|
|
int dft_unique_bins;
|
|
|
|
if (op->main_as_StftParam()->abs()) {
|
|
|
|
dft_unique_bins = frame_length / 2 + 1;
|
|
|
|
} else {
|
|
|
|
dft_unique_bins = frame_length;
|
|
|
|
}
|
|
|
|
outputs[0]->setLength(2, dft_unique_bins);
|
|
|
|
|
2024-12-19 16:20:00 +08:00
|
|
|
TensorUtils::getDescribe(outputs[0])->dimensionFormat = TensorUtils::getDescribe(inputs[0])->dimensionFormat;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2025-02-12 11:14:19 +08:00
|
|
|
REGISTER_SHAPE_INPUTS(StftOpComputer, OpType_Stft, std::vector<int>{1});
|
2024-12-19 16:20:00 +08:00
|
|
|
|
|
|
|
} // namespace MNN
|