1 /* 2 * Copyright (c) 2022 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 AUDIO_UTILS_H 16 #define AUDIO_UTILS_H 17 18 #include <cstdint> 19 #include <string> 20 21 #define AUDIO_MS_PER_SECOND 1000 22 #define AUDIO_US_PER_SECOND 1000000 23 #define AUDIO_NS_PER_SECOND ((int64_t)1000000000) 24 namespace OHOS { 25 namespace AudioStandard { 26 class Trace { 27 public: 28 static void Count(const std::string &value, int64_t count, bool isEnable = true); 29 Trace(const std::string &value, bool isShowLog = false, bool isEnable = true); 30 void End(); 31 ~Trace(); 32 private: 33 std::string value_; 34 bool isShowLog_; 35 bool isEnable_; 36 bool isFinished_; 37 }; 38 39 class ClockTime { 40 public: 41 static int64_t GetCurNano(); 42 static int32_t AbsoluteSleep(int64_t nanoTime); 43 static int32_t RelativeSleep(int64_t nanoTime); 44 }; 45 46 class PermissionUtil { 47 public: 48 static bool VerifyIsSystemApp(); 49 static bool VerifySelfPermission(); 50 static bool VerifySystemPermission(); 51 }; 52 53 void AdjustStereoToMonoForPCM8Bit(int8_t *data, uint64_t len); 54 void AdjustStereoToMonoForPCM16Bit(int16_t *data, uint64_t len); 55 void AdjustStereoToMonoForPCM24Bit(int8_t *data, uint64_t len); 56 void AdjustStereoToMonoForPCM32Bit(int32_t *data, uint64_t len); 57 void AdjustAudioBalanceForPCM8Bit(int8_t *data, uint64_t len, float left, float right); 58 void AdjustAudioBalanceForPCM16Bit(int16_t *data, uint64_t len, float left, float right); 59 void AdjustAudioBalanceForPCM24Bit(int8_t *data, uint64_t len, float left, float right); 60 void AdjustAudioBalanceForPCM32Bit(int32_t *data, uint64_t len, float left, float right); 61 62 template <typename T> 63 bool GetSysPara(const char *key, T &value); 64 } // namespace AudioStandard 65 } // namespace OHOS 66 #endif // AUDIO_UTILS_H 67