11bd4fe43Sopenharmony_ci/*
21bd4fe43Sopenharmony_ci * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
31bd4fe43Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
41bd4fe43Sopenharmony_ci * you may not use this file except in compliance with the License.
51bd4fe43Sopenharmony_ci * You may obtain a copy of the License at
61bd4fe43Sopenharmony_ci *
71bd4fe43Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
81bd4fe43Sopenharmony_ci *
91bd4fe43Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
101bd4fe43Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
111bd4fe43Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
121bd4fe43Sopenharmony_ci * See the License for the specific language governing permissions and
131bd4fe43Sopenharmony_ci * limitations under the License.
141bd4fe43Sopenharmony_ci */
151bd4fe43Sopenharmony_ci
161bd4fe43Sopenharmony_ci#ifndef __HI_RESAMPLER_API_H__
171bd4fe43Sopenharmony_ci#define __HI_RESAMPLER_API_H__
181bd4fe43Sopenharmony_ci
191bd4fe43Sopenharmony_ci#include "hi_type.h"
201bd4fe43Sopenharmony_ci
211bd4fe43Sopenharmony_ci#ifdef __cplusplus
221bd4fe43Sopenharmony_ciextern "C" {
231bd4fe43Sopenharmony_ci#endif
241bd4fe43Sopenharmony_ci
251bd4fe43Sopenharmony_ci#define MAXFRAMESIZE 2048
261bd4fe43Sopenharmony_ci
271bd4fe43Sopenharmony_ci#ifndef HI_ERR_RESAMPLE_PREFIX
281bd4fe43Sopenharmony_ci#define HI_ERR_RESAMPLE_PREFIX 0x80000000
291bd4fe43Sopenharmony_ci#endif
301bd4fe43Sopenharmony_ci
311bd4fe43Sopenharmony_ci/* input handle is invalid */
321bd4fe43Sopenharmony_ci#define HI_ERR_RESAMPLE_HANDLE (HI_ERR_RESAMPLE_PREFIX | 0x0001)
331bd4fe43Sopenharmony_ci
341bd4fe43Sopenharmony_ci/* pcm circ buffer state is invalid */
351bd4fe43Sopenharmony_ci#define HI_ERR_RESAMPLE_PCMBUF (HI_ERR_RESAMPLE_PREFIX | 0x0002)
361bd4fe43Sopenharmony_ci
371bd4fe43Sopenharmony_ci/* input sample number is more than MAXFRAMESIZE or input buffer size
381bd4fe43Sopenharmony_ci   , or input sample number is not invalid (eg. even) */
391bd4fe43Sopenharmony_ci#define HI_ERR_RESAMPLE_SAMPLE_NUMBER (HI_ERR_RESAMPLE_PREFIX | 0x0003)
401bd4fe43Sopenharmony_ci
411bd4fe43Sopenharmony_ci/* output pcm buffer space is not enough */
421bd4fe43Sopenharmony_ci#define HI_ERR_RESAMPLE_OUTPCM_SPACE (HI_ERR_RESAMPLE_PREFIX | 0x0004)
431bd4fe43Sopenharmony_ci
441bd4fe43Sopenharmony_ci/* the channels of input pcm is invalid */
451bd4fe43Sopenharmony_ci#define HI_ERR_PCM_CHANNEL (HI_ERR_RESAMPLE_PREFIX | 0x0005)
461bd4fe43Sopenharmony_ci
471bd4fe43Sopenharmony_ci/* the bit width of input pcm is invalid */
481bd4fe43Sopenharmony_ci#define HI_ERR_PCM_FORMAT (HI_ERR_RESAMPLE_PREFIX | 0x0006)
491bd4fe43Sopenharmony_ci
501bd4fe43Sopenharmony_ci/* invalid bypass flag */
511bd4fe43Sopenharmony_ci#define HI_ERR_INVALID_BYPASSFLAG (HI_ERR_RESAMPLE_PREFIX | 0x0007)
521bd4fe43Sopenharmony_ci
531bd4fe43Sopenharmony_ci/* error unknown */
541bd4fe43Sopenharmony_ci#define HI_ERR_UNKNOWN (HI_ERR_RESAMPLE_PREFIX | 0x0008)
551bd4fe43Sopenharmony_ci
561bd4fe43Sopenharmony_ci/* input Empty pointer */
571bd4fe43Sopenharmony_ci#define HI_ERR_INPUT_EMPTY_POINTER (HI_ERR_RESAMPLE_PREFIX | 0x0009)
581bd4fe43Sopenharmony_ci
591bd4fe43Sopenharmony_ci/**************************************************************************************
601bd4fe43Sopenharmony_ci * Function:    HI_Resampler_Create
611bd4fe43Sopenharmony_ci *
621bd4fe43Sopenharmony_ci * Description: allocate memory for platform-specific data
631bd4fe43Sopenharmony_ci *              clear all the user-accessible fields
641bd4fe43Sopenharmony_ci *
651bd4fe43Sopenharmony_ci * Inputs:      inrate:  8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000
661bd4fe43Sopenharmony_ci *              outrate: 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000
671bd4fe43Sopenharmony_ci *              chans:   1 or 2
681bd4fe43Sopenharmony_ci * Outputs:     none
691bd4fe43Sopenharmony_ci *
701bd4fe43Sopenharmony_ci * Return:      handle to Resampler instance, 0 if malloc fails
711bd4fe43Sopenharmony_ci **************************************************************************************/
721bd4fe43Sopenharmony_ciHI_VOID *HI_Resampler_Create(HI_S32 s32Inrate, HI_S32 s32Outrate, HI_S32 s32Chans);
731bd4fe43Sopenharmony_ci
741bd4fe43Sopenharmony_ci/**************************************************************************************
751bd4fe43Sopenharmony_ci * Function:    HI_Resampler_Process
761bd4fe43Sopenharmony_ci *
771bd4fe43Sopenharmony_ci * Description: Resample pcm data to specific samplerate, only for interlaced format
781bd4fe43Sopenharmony_ci *
791bd4fe43Sopenharmony_ci * Inputs:      inst: valid Resampler instance pointer (HResampler)
801bd4fe43Sopenharmony_ci *              inbuf:   pointer to inputbuf
811bd4fe43Sopenharmony_ci *              insamps: input number of sample pointers
821bd4fe43Sopenharmony_ci * Outputs:     outbuf:  pointer to outputbuf
831bd4fe43Sopenharmony_ci *
841bd4fe43Sopenharmony_ci * Return:      output sample number per-channel
851bd4fe43Sopenharmony_ci * Notes:       sure insamps < MAXFRAMESIZE
861bd4fe43Sopenharmony_ci
871bd4fe43Sopenharmony_ci
881bd4fe43Sopenharmony_ci **************************************************************************************/
891bd4fe43Sopenharmony_ciHI_S32 HI_Resampler_Process(HI_VOID *inst, const HI_S16 *s16Inbuf, HI_S32 s32Insamps, HI_S16 *s16Outbuf);
901bd4fe43Sopenharmony_ci
911bd4fe43Sopenharmony_ci/**************************************************************************************
921bd4fe43Sopenharmony_ci * Function:    HI_Resampler_Destroy
931bd4fe43Sopenharmony_ci *
941bd4fe43Sopenharmony_ci * Description: free platform-specific data allocated by ResamplerCreate
951bd4fe43Sopenharmony_ci *
961bd4fe43Sopenharmony_ci * Inputs:      valid Resampler instance pointer (HResampler)
971bd4fe43Sopenharmony_ci * Outputs:     none
981bd4fe43Sopenharmony_ci *
991bd4fe43Sopenharmony_ci * Return:      none
1001bd4fe43Sopenharmony_ci **************************************************************************************/
1011bd4fe43Sopenharmony_ciHI_VOID HI_Resampler_Destroy(HI_VOID *inst);
1021bd4fe43Sopenharmony_ci
1031bd4fe43Sopenharmony_ci/*******************************************************************************
1041bd4fe43Sopenharmony_ci * Function:    HI_Resampler_GetMaxOutputNum
1051bd4fe43Sopenharmony_ci *
1061bd4fe43Sopenharmony_ci * Description: Caculate max output number at specific input number
1071bd4fe43Sopenharmony_ci *
1081bd4fe43Sopenharmony_ci * Inputs:      inst:    valid Resampler instance pointer (HI_HANDLE)
1091bd4fe43Sopenharmony_ci *              insamps:  input data number per-channel, insamps must be even
1101bd4fe43Sopenharmony_ci * Outputs:     none
1111bd4fe43Sopenharmony_ci * Return:      >=0:     Success, return the max output number per-channel
1121bd4fe43Sopenharmony_ci *              other:    Fail, return error code
1131bd4fe43Sopenharmony_ci * Notes
1141bd4fe43Sopenharmony_ci * 1  if stereo(chans==2), sure insamps%2 == 0
1151bd4fe43Sopenharmony_ci ******************************************************************************/
1161bd4fe43Sopenharmony_ciHI_S32 HI_Resampler_GetMaxOutputNum(HI_VOID *inst, HI_S32 s32Insamps);
1171bd4fe43Sopenharmony_ci
1181bd4fe43Sopenharmony_ci#ifdef __cplusplus
1191bd4fe43Sopenharmony_ci}
1201bd4fe43Sopenharmony_ci#endif
1211bd4fe43Sopenharmony_ci
1221bd4fe43Sopenharmony_ci#endif
123