blob: 5b67c168200fcfb4da34affe239a7e985f3f1ce2 [file] [log] [blame]
Richard Burton00553462021-11-10 16:27:14 +00001/*
Richard Burtonf32a86a2022-11-15 11:46:11 +00002 * SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates <open-source-office@arm.com>
Richard Burton00553462021-11-10 16:27:14 +00003 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#ifndef NOISE_REDUCTION_EVT_HANDLER_HPP
18#define NOISE_REDUCTION_EVT_HANDLER_HPP
19
20#include "AppContext.hpp"
21#include "Model.hpp"
22
23namespace arm {
24namespace app {
25
26 /**
27 * @brief Handles the inference event for noise reduction.
28 * @param[in] ctx pointer to the application context
29 * @param[in] runAll flag to request classification of all the available audio clips
30 * @return True or false based on execution success
31 **/
32 bool NoiseReductionHandler(ApplicationContext& ctx, bool runAll);
33
34 /**
35 * @brief Dumps the output tensors to a memory address.
36 * This functionality is required for RNNoise use case as we want to
37 * save the inference output to a file. Dumping out tensors to a
38 * memory location will allow the Arm FVP or MPS3 to extract the
39 * contents of this memory location to a file. This file could then
40 * be used by an offline post-processing script.
41 *
42 * @param[in] model reference to a model
43 * @param[in] memAddress memory address at which the dump will start
44 * @param[in] memSize maximum size (in bytes) of the dump.
45 *
46 * @return number of bytes written to memory.
47 */
48 size_t DumpOutputTensorsToMemory(Model& model, uint8_t* memAddress,
49 size_t memSize);
50
51 /**
52 * @brief Dumps the audio file header.
53 * This functionality is required for RNNoise use case as we want to
54 * save the inference output to a file. Dumping out the header to a
55 * memory location will allow the Arm FVP or MPS3 to extract the
56 * contents of this memory location to a file.
57 * The header contains the following information
58 * int32_t filenameLength: filename length
59 * uint8_t[] filename: the string containing the file name (without trailing \0)
60 * int32_t dumpSizeByte: audiofile buffer size in bytes
61 *
62 * @param[in] filename the file name
63 * @param[in] dumpSize the size of the audio file (int elements)
64 * @param[in] memAddress memory address at which the dump will start
65 * @param[in] memSize maximum size (in bytes) of the dump.
66 *
67 * @return number of bytes written to memory.
68 */
69 size_t DumpDenoisedAudioHeader(const char* filename, size_t dumpSize,
70 uint8_t* memAddress, size_t memSize);
71
72 /**
73 * @brief Write a EOF marker at the end of the dump memory.
74 *
75 * @param[in] memAddress memory address at which the dump will start
76 * @param[in] memSize maximum size (in bytes) of the dump.
77 *
78 * @return number of bytes written to memory.
79 */
80 size_t DumpDenoisedAudioFooter(uint8_t *memAddress, size_t memSize);
81
82 /**
83 * @brief Dump the audio data to the memory
84 *
85 * @param[in] audioFrame The vector containg the audio data
86 * @param[in] memAddress memory address at which the dump will start
87 * @param[in] memSize maximum size (in bytes) of the dump.
88 *
89 * @return number of bytes written to memory.
90 */
91 size_t DumpOutputDenoisedAudioFrame(const std::vector<int16_t> &audioFrame,
92 uint8_t *memAddress, size_t memSize);
93
94} /* namespace app */
95} /* namespace arm */
96
97#endif /* NOISE_REDUCTION_EVT_HANDLER_HPP */