From 005534664e192cf909a11435c4bc4696b1f4c51f Mon Sep 17 00:00:00 2001 From: Richard Burton Date: Wed, 10 Nov 2021 16:27:14 +0000 Subject: MLECO-2354 MLECO-2355 MLECO-2356: Moving noise reduction to public repository * Use RNNoise model from PMZ * Add Noise reduction use-case Signed-off-by: Richard burton Change-Id: Ia8cc7ef102e22a5ff8bfbd3833594a4905a66057 --- .../noise_reduction/include/UseCaseHandler.hpp | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 source/use_case/noise_reduction/include/UseCaseHandler.hpp (limited to 'source/use_case/noise_reduction/include/UseCaseHandler.hpp') diff --git a/source/use_case/noise_reduction/include/UseCaseHandler.hpp b/source/use_case/noise_reduction/include/UseCaseHandler.hpp new file mode 100644 index 0000000..143f2ed --- /dev/null +++ b/source/use_case/noise_reduction/include/UseCaseHandler.hpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2021 Arm Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef NOISE_REDUCTION_EVT_HANDLER_HPP +#define NOISE_REDUCTION_EVT_HANDLER_HPP + +#include "AppContext.hpp" +#include "Model.hpp" + +namespace arm { +namespace app { + + /** + * @brief Handles the inference event for noise reduction. + * @param[in] ctx pointer to the application context + * @param[in] runAll flag to request classification of all the available audio clips + * @return True or false based on execution success + **/ + bool NoiseReductionHandler(ApplicationContext& ctx, bool runAll); + + /** + * @brief Dumps the output tensors to a memory address. + * This functionality is required for RNNoise use case as we want to + * save the inference output to a file. Dumping out tensors to a + * memory location will allow the Arm FVP or MPS3 to extract the + * contents of this memory location to a file. This file could then + * be used by an offline post-processing script. + * + * @param[in] model reference to a model + * @param[in] memAddress memory address at which the dump will start + * @param[in] memSize maximum size (in bytes) of the dump. + * + * @return number of bytes written to memory. + */ + size_t DumpOutputTensorsToMemory(Model& model, uint8_t* memAddress, + size_t memSize); + + /** + * @brief Dumps the audio file header. + * This functionality is required for RNNoise use case as we want to + * save the inference output to a file. Dumping out the header to a + * memory location will allow the Arm FVP or MPS3 to extract the + * contents of this memory location to a file. + * The header contains the following information + * int32_t filenameLength: filename length + * uint8_t[] filename: the string containing the file name (without trailing \0) + * int32_t dumpSizeByte: audiofile buffer size in bytes + * + * @param[in] filename the file name + * @param[in] dumpSize the size of the audio file (int elements) + * @param[in] memAddress memory address at which the dump will start + * @param[in] memSize maximum size (in bytes) of the dump. + * + * @return number of bytes written to memory. + */ + size_t DumpDenoisedAudioHeader(const char* filename, size_t dumpSize, + uint8_t* memAddress, size_t memSize); + + /** + * @brief Write a EOF marker at the end of the dump memory. + * + * @param[in] memAddress memory address at which the dump will start + * @param[in] memSize maximum size (in bytes) of the dump. + * + * @return number of bytes written to memory. + */ + size_t DumpDenoisedAudioFooter(uint8_t *memAddress, size_t memSize); + + /** + * @brief Dump the audio data to the memory + * + * @param[in] audioFrame The vector containg the audio data + * @param[in] memAddress memory address at which the dump will start + * @param[in] memSize maximum size (in bytes) of the dump. + * + * @return number of bytes written to memory. + */ + size_t DumpOutputDenoisedAudioFrame(const std::vector &audioFrame, + uint8_t *memAddress, size_t memSize); + +} /* namespace app */ +} /* namespace arm */ + +#endif /* NOISE_REDUCTION_EVT_HANDLER_HPP */ \ No newline at end of file -- cgit v1.2.1