• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef FRAMEWORK_COMMON_H
17 #define FRAMEWORK_COMMON_H
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 
22 #ifdef IDL_SAMPLE
23 #include "v1_0/iaudio_manager.h"
24 #else
25 #include "audio_manager.h"
26 #endif
27 
28 #define AUDIO_FUNC_LOGE(fmt, arg...)                                                     \
29     do {                                                                                 \
30         printf("%s: [%s]: [%d]:[ERROR]:" fmt "\n", __FILE__, __func__, __LINE__, ##arg); \
31     } while (0)
32 
33 #define WAV_HEAD_OFFSET 44
34 
35 struct AudioHeadInfo {
36     uint32_t riffId;
37     uint32_t riffSize;
38     uint32_t waveType;
39     uint32_t audioFileFmtId;
40     uint32_t audioFileFmtSize;
41     uint16_t audioFileFormat;
42     uint16_t audioChannelNum;
43     uint32_t audioSampleRate;
44     uint32_t audioByteRate;
45     uint16_t audioBlockAlign;
46     uint16_t audioBitsPerSample;
47     uint32_t dataId;
48     uint32_t dataSize;
49 };
50 
51 enum AudioPcmBit {
52     PCM_8_BIT = 8,   /* 8-bit PCM */
53     PCM_16_BIT = 16, /* 16-bit PCM */
54     PCM_24_BIT = 24, /* 24-bit PCM */
55     PCM_32_BIT = 32, /* 32-bit PCM */
56 };
57 
58 struct StrParaCapture {
59 #ifdef IDL_SAMPLE
60     struct IAudioCapture *capture;
61 #else
62     struct AudioCapture *capture;
63 #endif
64     FILE *file;
65     struct AudioSampleAttributes attrs;
66     uint64_t *replyBytes;
67     char *frame;
68     int32_t bufferSize;
69 };
70 
71 void SystemInputFail(void);
72 uint32_t StringToInt(const char *flag);
73 int32_t CheckPcmFormat(int32_t val, uint32_t *audioPcmFormat);
74 uint32_t PcmFormatToBits(enum AudioFormat formatBit);
75 void CleanStdin(void);
76 void FileClose(FILE **file);
77 int32_t FormatLoadLibPath(char *resolvedPath, int32_t pathLen, int choice);
78 int32_t SelectAudioCard(struct AudioAdapterDescriptor *descs, int32_t size, int32_t *adapterIndex);
79 int32_t SwitchAudioPort(
80     struct AudioAdapterDescriptor *descs, enum AudioPortDirection portFlag, struct AudioPort *renderPort);
81 void PrintLoadModeMenu(void);
82 int32_t CheckWavFileHeader(FILE *file, struct AudioHeadInfo *wavHeadInfo, struct AudioSampleAttributes *attrs);
83 int32_t AddWavFileHeader(FILE *file, const struct StrParaCapture *strParam);
84 #endif
85