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 #include "audio_utils.h"
17
18 #include "aie_log.h"
19
20 namespace OHOS {
21 namespace AI {
22 namespace AudioUtils {
IsAudioCoderFormatSupported(AudioCodecFormat format)23 bool IsAudioCoderFormatSupported(AudioCodecFormat format)
24 {
25 if ((format < AAC_LC) || (format > AAC_ELD)) {
26 HILOGE("[AudioUtils]Invalid format = %d", format);
27 return false;
28 }
29 return true;
30 }
31
GetProfileFromAudioCoderFormat(AudioCodecFormat format)32 Profile GetProfileFromAudioCoderFormat(AudioCodecFormat format)
33 {
34 switch (format) {
35 case AAC_LC:
36 return AAC_LC_PROFILE;
37 case AAC_HE_V1:
38 return AAC_HE_V1_PROFILE;
39 case AAC_HE_V2:
40 return AAC_HE_V2_PROFILE;
41 case AAC_LD:
42 return AAC_LD_PROFILE;
43 case AAC_ELD:
44 return AAC_ELD_PROFILE;
45 default:
46 HILOGW("[AudioUtils]Invalid format = 0x%.8x, replace with default", format);
47 return AAC_LC_PROFILE;
48 }
49 }
50
ConvertSampleRateForCoder(uint32_t sampleRate)51 AudioSampleRate ConvertSampleRateForCoder(uint32_t sampleRate)
52 {
53 switch (sampleRate) {
54 case AUD_SAMPLE_RATE_8000:
55 case AUD_SAMPLE_RATE_11025:
56 case AUD_SAMPLE_RATE_12000:
57 case AUD_SAMPLE_RATE_16000:
58 case AUD_SAMPLE_RATE_22050:
59 case AUD_SAMPLE_RATE_24000:
60 case AUD_SAMPLE_RATE_32000:
61 case AUD_SAMPLE_RATE_44100:
62 case AUD_SAMPLE_RATE_48000:
63 case AUD_SAMPLE_RATE_64000:
64 case AUD_SAMPLE_RATE_96000:
65 return static_cast<AudioSampleRate>(sampleRate);
66 default:
67 HILOGW("[AudioUtils]Invalid sampleRate = %u, replace with default", sampleRate);
68 return AUD_SAMPLE_RATE_48000;
69 }
70 }
71
ConvertSoundModeForCoder(uint32_t channelCount)72 AudioSoundMode ConvertSoundModeForCoder(uint32_t channelCount)
73 {
74 switch (channelCount) {
75 case AUDIO_CHANNEL_MONO:
76 return AUD_SOUND_MODE_MONO;
77 case AUDIO_CHANNEL_STEREO:
78 return AUD_SOUND_MODE_STEREO;
79 default:
80 HILOGW("[AudioUtils]Invalid soundMode: %u, replace with default", channelCount);
81 return AUD_SOUND_MODE_MONO;
82 }
83 }
84 } // namespace AudioUtils
85 } // namespace AI
86 } // namespace OHOS