1 /* 2 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. 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 __HI_RESAMPLER_API_H__ 17 #define __HI_RESAMPLER_API_H__ 18 19 #include "hi_type.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #define MAXFRAMESIZE 2048 26 27 #ifndef HI_ERR_RESAMPLE_PREFIX 28 #define HI_ERR_RESAMPLE_PREFIX 0x80000000 29 #endif 30 31 /* input handle is invalid */ 32 #define HI_ERR_RESAMPLE_HANDLE (HI_ERR_RESAMPLE_PREFIX | 0x0001) 33 34 /* pcm circ buffer state is invalid */ 35 #define HI_ERR_RESAMPLE_PCMBUF (HI_ERR_RESAMPLE_PREFIX | 0x0002) 36 37 /* input sample number is more than MAXFRAMESIZE or input buffer size 38 , or input sample number is not invalid (eg. even) */ 39 #define HI_ERR_RESAMPLE_SAMPLE_NUMBER (HI_ERR_RESAMPLE_PREFIX | 0x0003) 40 41 /* output pcm buffer space is not enough */ 42 #define HI_ERR_RESAMPLE_OUTPCM_SPACE (HI_ERR_RESAMPLE_PREFIX | 0x0004) 43 44 /* the channels of input pcm is invalid */ 45 #define HI_ERR_PCM_CHANNEL (HI_ERR_RESAMPLE_PREFIX | 0x0005) 46 47 /* the bit width of input pcm is invalid */ 48 #define HI_ERR_PCM_FORMAT (HI_ERR_RESAMPLE_PREFIX | 0x0006) 49 50 /* invalid bypass flag */ 51 #define HI_ERR_INVALID_BYPASSFLAG (HI_ERR_RESAMPLE_PREFIX | 0x0007) 52 53 /* error unknown */ 54 #define HI_ERR_UNKNOWN (HI_ERR_RESAMPLE_PREFIX | 0x0008) 55 56 /* input Empty pointer */ 57 #define HI_ERR_INPUT_EMPTY_POINTER (HI_ERR_RESAMPLE_PREFIX | 0x0009) 58 59 /************************************************************************************** 60 * Function: HI_Resampler_Create 61 * 62 * Description: allocate memory for platform-specific data 63 * clear all the user-accessible fields 64 * 65 * Inputs: inrate: 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 66 * outrate: 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 67 * chans: 1 or 2 68 * Outputs: none 69 * 70 * Return: handle to Resampler instance, 0 if malloc fails 71 **************************************************************************************/ 72 HI_VOID *HI_Resampler_Create(HI_S32 s32Inrate, HI_S32 s32Outrate, HI_S32 s32Chans); 73 74 /************************************************************************************** 75 * Function: HI_Resampler_Process 76 * 77 * Description: Resample pcm data to specific samplerate, only for interlaced format 78 * 79 * Inputs: inst: valid Resampler instance pointer (HResampler) 80 * inbuf: pointer to inputbuf 81 * insamps: input number of sample pointers 82 * Outputs: outbuf: pointer to outputbuf 83 * 84 * Return: output sample number per-channel 85 * Notes: sure insamps < MAXFRAMESIZE 86 87 88 **************************************************************************************/ 89 HI_S32 HI_Resampler_Process(HI_VOID *inst, const HI_S16 *s16Inbuf, HI_S32 s32Insamps, HI_S16 *s16Outbuf); 90 91 /************************************************************************************** 92 * Function: HI_Resampler_Destroy 93 * 94 * Description: free platform-specific data allocated by ResamplerCreate 95 * 96 * Inputs: valid Resampler instance pointer (HResampler) 97 * Outputs: none 98 * 99 * Return: none 100 **************************************************************************************/ 101 HI_VOID HI_Resampler_Destroy(HI_VOID *inst); 102 103 /******************************************************************************* 104 * Function: HI_Resampler_GetMaxOutputNum 105 * 106 * Description: Caculate max output number at specific input number 107 * 108 * Inputs: inst: valid Resampler instance pointer (HI_HANDLE) 109 * insamps: input data number per-channel, insamps must be even 110 * Outputs: none 111 * Return: >=0: Success, return the max output number per-channel 112 * other: Fail, return error code 113 * Notes 114 * 1 if stereo(chans==2), sure insamps%2 == 0 115 ******************************************************************************/ 116 HI_S32 HI_Resampler_GetMaxOutputNum(HI_VOID *inst, HI_S32 s32Insamps); 117 118 #ifdef __cplusplus 119 } 120 #endif 121 122 #endif 123