summaryrefslogtreecommitdiff
path: root/source/use_case/noise_reduction/include/UseCaseHandler.hpp
blob: 143f2ed3938d31a367e31e22b38f72f98f94aea0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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<int16_t> &audioFrame,
                                        uint8_t *memAddress, size_t memSize);

} /* namespace app */
} /* namespace arm */

#endif /* NOISE_REDUCTION_EVT_HANDLER_HPP */