• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #ifndef VOLUME_RAMP_H
16 #define VOLUME_RAMP_H
17 
18 #include <cstdint>
19 #include <string>
20 #include <map>
21 #include <mutex>
22 #include <cmath>
23 
24 namespace OHOS {
25 namespace AudioStandard {
26 
27 enum RampDirection {
28     RAMP_UP = 0,
29     RAMP_DOWN = 1,
30 };
31 
32 class VolumeRamp {
33 public:
34     VolumeRamp();
35     ~VolumeRamp() = default;
36     void SetVolumeRampConfig(float targetVolume, float currStreamVolume, int32_t duration);
37     float GetRampVolume();
38     bool IsActive();
39     void Terminate();
40 
41 private:
42     void SetVolumeCurve(std::vector<float> &volumes);
43     float GetScaledTime(int64_t currentTime);
44     float FindRampVolume(float time);
45 
46     int32_t duration_ = 0;
47     RampDirection rampDirection_ = RAMP_UP;
48     std::mutex curveMapMutex_;
49     std::map<float, float> curvePoints_;
50     int64_t initTime_ = 0;
51     float scale_ = 0.0f;
52     bool isVolumeRampActive_ = false;
53     float rampVolume_ = 0.0f;
54 };
55 } // namespace AudioStandard
56 } // namespace OHOS
57 #endif // VOLUME_RAMP_H
58