1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup feature_processor
18  * @{
19  *
20  * @brief Defines the basic functions for FeatureProcessor, including the supported data types
21  * and other related configuration paramters.
22  *
23  * @since 2.2
24  * @version 1.0
25  */
26 
27 /**
28  * @file log_scale_processor.h
29  *
30  * @brief Defines LogScaleProcessor that implements weighting on the natural logarithm obtained
31  * from feature calculation.
32  *
33  * @since 2.2
34  * @version 1.0
35  */
36 
37 #ifndef AUDIO_PREPROCESS_LOG_SCALE_PROCESSOR_H
38 #define AUDIO_PREPROCESS_LOG_SCALE_PROCESSOR_H
39 
40 #include <cstdint>
41 #include <memory>
42 
43 #include "feature_processor.h"
44 
45 namespace OHOS {
46 namespace AI {
47 namespace Feature {
48 /**
49  * @brief Specifies the structure for the LogScaleProcessor configuration.
50  *
51  * @since 2.2
52  * @version 1.0
53  */
54 struct LogScaleConfig : FeatureProcessorConfig {
55     /** Indicates whether to process input data */
56     bool enableLogScale;
57     /** Weight. The output logarithm is multiplied by 2 to the power of <b>scaleShift</b>. */
58     int16_t scaleShift;
59     /** Number of bits moved by the original data's shift operation. */
60     int16_t correctionBits;
61     /** Number of input data channels. The maximum value is {@link MAX_NUM_CHANNELS}. */
62     uint32_t numChannels;
63 };
64 
65 /**
66  * @brief Defines the functions for LogScaleProcessor.
67  *
68  * @since 2.2
69  * @version 1.0
70  */
71 class LogScaleProcessor : public FeatureProcessor {
72 public:
73     /**
74      * @brief Defines the constructor for LogScaleProcessor.
75      *
76      * @since 2.2
77      * @version 1.0
78      */
79     LogScaleProcessor();
80 
81     /**
82      * @brief Defines the destructor for LogScaleProcessor.
83      *
84      * @since 2.2
85      * @version 1.0
86      */
87     virtual ~LogScaleProcessor();
88 
89     /**
90      * @brief Initializes LogScaleProcessor.
91      *
92      * @param config Indicates the pointer to the basic configuration of FeatureProcessor.
93      * The caller needs to pass in a pointer address defined by {@link LogScaleConfig}
94      * and release the pointer after using it.
95      * @return Returns {@link RETCODE_SUCCESS} if the operation is successful;
96      * returns {@link RETCODE_FAILURE} otherwise.
97      *
98      * @since 2.2
99      * @version 1.0
100      */
101     int32_t Init(const FeatureProcessorConfig *config) override;
102 
103     /**
104      * @brief Performs feature processing.
105      *
106      * @param input Indicates the input data for FeatureProcessor.
107      * The caller must pass in FeatureData of the UINT32 type defined by {@link DataType},
108      * besides the address and data length must meet the configuration requirements.
109      * @param output Indicates the output data for FeatureProcessor.
110      * The caller must pass in FeatureData of the UINT16 type defined by {@link DataType}.
111      * If and only if its address is empty and the data length is <b>0</b>,
112      * data will be filled by the FeatureProcessor.
113      * @return Returns {@link RETCODE_SUCCESS} if the operation is successful;
114      * returns {@link RETCODE_FAILURE} otherwise.
115      *
116      * @since 2.2
117      * @version 1.0
118      */
119     int32_t Process(const FeatureData &input, FeatureData &output) override;
120 
121     /**
122      * @brief Releases resources.
123      *
124      * @since 2.2
125      * @version 1.0
126      */
127     void Release() override;
128 
129 private:
130     class LogScaleImpl;
131     std::unique_ptr<LogScaleImpl> impl_;
132 };
133 } // namespace Feature
134 } // namespace AI
135 } // namespace OHOS
136 #endif // AUDIO_PREPROCESS_LOG_SCALE_PROCESSOR_H
137 /** @} */