1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci#ifndef FRAMEWORK_COMMON_H 17094332d3Sopenharmony_ci#define FRAMEWORK_COMMON_H 18094332d3Sopenharmony_ci 19094332d3Sopenharmony_ci#include <stdio.h> 20094332d3Sopenharmony_ci#include <stdlib.h> 21094332d3Sopenharmony_ci 22094332d3Sopenharmony_ci#ifdef IDL_SAMPLE 23094332d3Sopenharmony_ci#include "v4_0/iaudio_manager.h" 24094332d3Sopenharmony_ci#else 25094332d3Sopenharmony_ci#include "audio_manager.h" 26094332d3Sopenharmony_ci#endif 27094332d3Sopenharmony_ci 28094332d3Sopenharmony_ci#define AUDIO_FUNC_LOGE(fmt, arg...) \ 29094332d3Sopenharmony_ci do { \ 30094332d3Sopenharmony_ci printf("%s: [%s]: [%d]:[ERROR]:" fmt "\n", __FILE__, __func__, __LINE__, ##arg); \ 31094332d3Sopenharmony_ci } while (0) 32094332d3Sopenharmony_ci 33094332d3Sopenharmony_ci#define WAV_HEAD_OFFSET 44 34094332d3Sopenharmony_ci 35094332d3Sopenharmony_cistruct AudioHeadInfo { 36094332d3Sopenharmony_ci uint32_t riffId; 37094332d3Sopenharmony_ci uint32_t riffSize; 38094332d3Sopenharmony_ci uint32_t waveType; 39094332d3Sopenharmony_ci uint32_t audioFileFmtId; 40094332d3Sopenharmony_ci uint32_t audioFileFmtSize; 41094332d3Sopenharmony_ci uint16_t audioFileFormat; 42094332d3Sopenharmony_ci uint16_t audioChannelNum; 43094332d3Sopenharmony_ci uint32_t audioSampleRate; 44094332d3Sopenharmony_ci uint32_t audioByteRate; 45094332d3Sopenharmony_ci uint16_t audioBlockAlign; 46094332d3Sopenharmony_ci uint16_t audioBitsPerSample; 47094332d3Sopenharmony_ci uint32_t dataId; 48094332d3Sopenharmony_ci uint32_t dataSize; 49094332d3Sopenharmony_ci}; 50094332d3Sopenharmony_ci 51094332d3Sopenharmony_cienum AudioPcmBit { 52094332d3Sopenharmony_ci PCM_8_BIT = 8, /* 8-bit PCM */ 53094332d3Sopenharmony_ci PCM_16_BIT = 16, /* 16-bit PCM */ 54094332d3Sopenharmony_ci PCM_24_BIT = 24, /* 24-bit PCM */ 55094332d3Sopenharmony_ci PCM_32_BIT = 32, /* 32-bit PCM */ 56094332d3Sopenharmony_ci}; 57094332d3Sopenharmony_ci 58094332d3Sopenharmony_cistruct StrParaCapture { 59094332d3Sopenharmony_ci#ifdef IDL_SAMPLE 60094332d3Sopenharmony_ci struct IAudioCapture *capture; 61094332d3Sopenharmony_ci#else 62094332d3Sopenharmony_ci struct AudioCapture *capture; 63094332d3Sopenharmony_ci#endif 64094332d3Sopenharmony_ci FILE *file; 65094332d3Sopenharmony_ci struct AudioSampleAttributes attrs; 66094332d3Sopenharmony_ci uint64_t *replyBytes; 67094332d3Sopenharmony_ci char *frame; 68094332d3Sopenharmony_ci int32_t bufferSize; 69094332d3Sopenharmony_ci}; 70094332d3Sopenharmony_ci 71094332d3Sopenharmony_civoid SystemInputFail(void); 72094332d3Sopenharmony_ciuint32_t StringToInt(const char *flag); 73094332d3Sopenharmony_ciint32_t CheckPcmFormat(int32_t val, uint32_t *audioPcmFormat); 74094332d3Sopenharmony_ciuint32_t PcmFormatToBits(enum AudioFormat formatBit); 75094332d3Sopenharmony_civoid CleanStdin(void); 76094332d3Sopenharmony_civoid FileClose(FILE **file); 77094332d3Sopenharmony_ciint32_t FormatLoadLibPath(char *resolvedPath, int32_t pathLen, int choice); 78094332d3Sopenharmony_ciint32_t SelectAudioCard(struct AudioAdapterDescriptor *descs, int32_t size, int32_t *adapterIndex); 79094332d3Sopenharmony_ciint32_t SwitchAudioPort( 80094332d3Sopenharmony_ci struct AudioAdapterDescriptor *descs, enum AudioPortDirection portFlag, struct AudioPort *renderPort); 81094332d3Sopenharmony_civoid PrintLoadModeMenu(void); 82094332d3Sopenharmony_civoid PrintAudioInputTypeMenu(void); 83094332d3Sopenharmony_ciint32_t CheckWavFileHeader(FILE *file, struct AudioHeadInfo *wavHeadInfo, struct AudioSampleAttributes *attrs); 84094332d3Sopenharmony_ciint32_t AddWavFileHeader(FILE *file, const struct StrParaCapture *strParam); 85094332d3Sopenharmony_ci#endif 86