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 parameters. 22 * 23 * @since 2.2 24 * @version 1.0 25 */ 26 27 /** 28 * @file filterbank_processor.h 29 * 30 * @brief Defines FilterBankProcessor that calculates FilterBank features based on the 16-bit PCM audio data. 31 * 32 * @since 2.2 33 * @version 1.0 34 */ 35 36 #ifndef AUDIO_PREPROCESS_FILTER_BANK_PROCESSOR_H 37 #define AUDIO_PREPROCESS_FILTER_BANK_PROCESSOR_H 38 39 #include <cstdint> 40 #include <memory> 41 #include <string> 42 43 #include "feature_processor.h" 44 45 namespace OHOS { 46 namespace AI { 47 namespace Feature { 48 /** 49 * @brief Specifies the structure for the FilterBankProcessor configuration. 50 * 51 * @since 2.2 52 * @version 1.0 53 */ 54 struct FilterBankConfig : FeatureProcessorConfig { 55 /** Number of frequency channels. The maximum value is {@link MAX_NUM_CHANNELS}. */ 56 uint32_t numChannels; 57 /** Sampling rate for time-domain audio data. */ 58 uint32_t sampleRate; 59 /** Maximum frequency. The value must be greater than <b>0</b> and the actual value depends 60 * on the specific frequency requirements. */ 61 float upperBandLimit; 62 /** Minimum frequency. The value must be greater than <b>0</b> and less than <b>upperBandLimit</b>. */ 63 float lowerBandLimit; 64 /** Number of frequency-domain samples for the Fast Fourier Transform (FFT). The maximum value is <b>4096</b>. */ 65 size_t fftSize; 66 /** Number of time-domain sample points for FFT. The maximum value is <b>16000</b>. */ 67 size_t inputSize; 68 }; 69 70 /** 71 * @brief Defines the functions for FilterBankProcessor. 72 * 73 * @since 2.2 74 * @version 1.0 75 */ 76 class FilterBankProcessor : public FeatureProcessor { 77 public: 78 /** 79 * @brief Defines the constructor for FilterBankProcessor. 80 * 81 * @since 2.2 82 * @version 1.0 83 */ 84 FilterBankProcessor(); 85 86 /** 87 * @brief Defines the destructor for FilterBankProcessor. 88 * 89 * @since 2.2 90 * @version 1.0 91 */ 92 virtual ~FilterBankProcessor(); 93 94 /** 95 * @brief Initializes FilterBankProcessor. 96 * 97 * @param config Indicates the pointer to the basic configuration of FeatureProcessor. 98 * The caller needs to pass in a pointer address defined by {@link FilterBankConfig} 99 * and release the pointer after using it. 100 * @return Returns {@link RETCODE_SUCCESS} if the operation is successful; 101 * returns {@link RETCODE_FAILURE} otherwise. 102 * 103 * @since 2.2 104 * @version 1.0 105 */ 106 int32_t Init(const FeatureProcessorConfig *config) override; 107 108 /** 109 * @brief Processes feature data to obtain FilterBank features. 110 * 111 * @param input Indicates the input data for FeatureProcessor. 112 * The caller must pass in FeatureData of the INT16 type defined by {@link DataType}, 113 * and the address and data length must meet the configuration requirements. 114 * @param output Indicates the output data for FeatureProcessor. 115 * The caller must pass in FeatureData of the UINT32 type defined by {@link DataType}. 116 * If and only if its address is empty and the data length is <b>0</b>, 117 * data will be filled by the FeatureProcessor. 118 * @return Returns {@link RETCODE_SUCCESS} if the operation is successful; 119 * returns {@link RETCODE_FAILURE} otherwise. 120 * 121 * @since 2.2 122 * @version 1.0 123 */ 124 int32_t Process(const FeatureData &input, FeatureData &output) override; 125 126 /** 127 * @brief Releases resources. 128 * 129 * @since 2.2 130 * @version 1.0 131 */ 132 void Release() override; 133 134 private: 135 class FilterBankImpl; 136 std::unique_ptr<FilterBankImpl> impl_; 137 }; 138 } // namespace Feature 139 } // namespace AI 140 } // namespace OHOS 141 #endif // AUDIO_PREPROCESS_FILTER_BANK_PROCESSOR_H 142 /** @} */