• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef AUDIO_LIMITER_H
17 #define AUDIO_LIMITER_H
18 
19 #include <cstdio>
20 #include <cstdint>
21 #include <string>
22 namespace OHOS {
23 namespace AudioStandard {
24 
25 class AudioLimiter {
26 public:
27     AudioLimiter(int32_t sinkIndex);
28     ~AudioLimiter();
29     int32_t SetConfig(int32_t maxRequest, int32_t biteSize, int32_t sampleRate, int32_t channels);
30     int32_t Process(int32_t frameLen, float *inBuffer, float *outBuffer);
31     uint32_t GetLatency();
32 private:
33     void ProcessAlgo(int algoFrameLen, float *inBuffer, float *outBuffer);
34     void ReleaseBuffer();
35     uint32_t latency_;
36     int32_t sinkIndex_;
37     int32_t algoFrameLen_;
38     int32_t format_;
39     float nextLev_;
40     float curMaxLev_;
41     float threshold_;
42     float gain_;
43     float levelAttack_;
44     float levelRelease_;
45     float gainAttack_;
46     float gainRelease_;
47     float *bufHis_;
48     uint32_t sampleRate_;
49     uint32_t channels_;
50     FILE *dumpFileInput_ = nullptr;
51     FILE *dumpFileOutput_ = nullptr;
52     std::string dumpFileNameIn_ = "";
53     std::string dumpFileNameOut_ = "";
54 };
55 
56 } // namespace AudioStandard
57 } // namespace OHOS
58 #endif // AUDIO_LIMITER_H