1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #include "hi3516_common_func.h" 10 InitHwParam(struct AudioPcmHwParams * hwParam)11int32_t InitHwParam(struct AudioPcmHwParams *hwParam) 12 { 13 const uint32_t channelNum = 2; 14 const uint32_t sampleRate = 48000; 15 const uint32_t periodSize = 4096; 16 const uint32_t periodCount = 8; 17 const int format = 2; 18 const uint32_t startThreshold = 1024; 19 const uint32_t stopThreshold = 0x7fffffff; 20 const uint32_t silenceThreshold = 1024 * 16; 21 22 if (hwParam == NULL) { 23 HDF_LOGE("InitHwParam: input param is NULL."); 24 return HDF_FAILURE; 25 } 26 27 hwParam->channels = channelNum; 28 hwParam->rate = sampleRate; 29 hwParam->periodSize = periodSize; 30 hwParam->periodCount = periodCount; 31 hwParam->format = format; 32 hwParam->cardServiceName = "hdf_audio_codec_dev0"; 33 hwParam->isBigEndian = false; 34 hwParam->isSignedData = true; 35 hwParam->startThreshold = startThreshold; 36 hwParam->stopThreshold = stopThreshold; 37 hwParam->silenceThreshold = silenceThreshold; 38 hwParam->streamType = 0; // AUDIO_RENDER_STREAM 39 return HDF_SUCCESS; 40 } 41 42 GetAudioCard(struct AudioCard ** card)43int32_t GetAudioCard(struct AudioCard **card) 44 { 45 int i; 46 const char *audioServiceName[] = { 47 "hdf_audio_codec_dev0", 48 "hdf_audio_smartpa_dev0", 49 }; 50 HDF_LOGI("%s: enter", __func__); 51 if (card == NULL) { 52 HDF_LOGE("input param is NULL"); 53 return HDF_FAILURE; 54 } 55 56 for (i = 0; i < sizeof(audioServiceName) / sizeof(audioServiceName[0]); ++i) { 57 if (GetCardInstance(audioServiceName[i]) != NULL) { 58 HDF_LOGI("%s: get %s success!", __func__, audioServiceName[i]); 59 *card = GetCardInstance(audioServiceName[i]); 60 break; 61 } 62 } 63 64 if (*card == NULL) { 65 HDF_LOGE("get card instance failed"); 66 return HDF_FAILURE; 67 } 68 return HDF_SUCCESS; 69 } 70