1 /* 2 * Copyright (c) 2023 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 <cmath> 22 #include "audio_info.h" 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_; 47 RampDirection rampDirection_; 48 std::map<float, float> curvePoints_; 49 int64_t initTime_; 50 float scale_; 51 bool isVolumeRampActive_; 52 float rampVolume_; 53 }; 54 } // namespace AudioStandard 55 } // namespace OHOS 56 #endif // VOLUME_RAMP_H 57