ResampleFixed
使用对理想低通滤波器加Kaiser窗的多项滤波器对数据进行重采样,仅适用于输入和输出采用率为固定有理数的情况,相比非Fixed接口提供更好的性能。
函数调用流程如下:
- 调用Init初始化结构体。
- 调用重采样主函数。
- 最后调用Release释放结构体所包含的内存。
函数接口声明如下:
- 初始化操作:
HmppResult HMPPS_ResamplePolyphaseFixedInit_32f(int32_t inRate, int32_t outRate, int32_t len, float rollf, float alpha,HmppHintAlgorithm hint, int32_t *fLen, int32_t *fHeight,HmppsResamplingPolyphaseFixed_32f **policy);
HmppResult HMPPS_ResamplePolyphaseFixedInit_16s(int32_t inRate, int32_t outRate, int32_t len, float rollf, float alpha,HmppHintAlgorithm hint, int32_t *fLen, int32_t *fHeight,HmppsResamplingPolyphaseFixed_16s **policy);
- 设置滤波器系数操作:
HmppResult HMPPS_ResamplePolyphaseSetFixedFilter_32f(const float *src, int32_t step, int32_t height,HmppsResamplingPolyphaseFixed_32f *policy);
HmppResult HMPPS_ResamplePolyphaseSetFixedFilter_16s(const int16_t *src, int32_t step, int32_t height,HmppsResamplingPolyphaseFixed_16s *policy);
- 获取滤波器系数操作:
HmppResult HMPPS_ResamplePolyphaseGetFixedFilter_32f(float *dst, int32_t step, int32_t height,const HmppsResamplingPolyphaseFixed_32f *policy);
HmppResult HMPPS_ResamplePolyphaseGetFixedFilter_16s(int16_t *dst, int32_t step, int32_t height,const HmppsResamplingPolyphaseFixed_16s *policy);
- 重采样操作:
HmppResult HMPPS_ResamplePolyphaseFixed_32f(const float *src, int32_t len, float *dst, float norm, double *time,int32_t *outLen, const HmppsResamplingPolyphaseFixed_32f *policy);
HmppResult HMPPS_ResamplePolyphaseFixed_16s(const int16_t *src, int32_t len, int16_t *dst, float norm, double *time,int32_t *outLen, const HmppsResamplingPolyphaseFixed_16s *policy);
- 释放内存操作:
HmppResult HMPPS_ResamplePolyphaseFixedRelease_32f(HmppsResamplingPolyphaseFixed_32f *policy);
HmppResult HMPPS_ResamplePolyphaseFixedRelease_16s(HmppsResamplingPolyphaseFixed_16s *policy);
参数
参数名 |
描述 |
取值范围 |
输入/输出 |
---|---|---|---|
inRate |
固定因子重采样的输入频率。 |
(0,INT_MAX] |
输入 |
outRate |
固定因子重采样的输出频率。 |
(0,INT_MAX] |
输入 |
len |
固定因子重采样滤波器的长度或者待重采样的输入数据的长度。 |
滤波器长度取值范围:Init函数中会有合法性判断,跟inRate和outRate有关,(0, (INT_MAX - 0x4) / 4) 待重采样数据长度:(0, INT_MAX * inRate / outRate) |
输入 |
rollf |
滤波器的衰减频率。 |
(0, 1.0] |
输入 |
alpha |
Kaiser窗的可调参数。 |
(1,FLT_MAX] |
输入 |
policy |
指向重采样策略结构体的指针或者指针的指针。 |
非空 |
输入、输出 |
hint |
重采样的模式。 |
HMPP_ALGHINT_NONE HMPP_ALGHINT_FAST HMPP_ALGHINT_ACCURATE |
输入 |
fLen |
多项滤波器实际的长度。 |
非空 |
输入、输出 |
fHeight |
多项滤波器的个数。 |
非空 |
输入、输出 |
step |
滤波器的步长。 |
(0, Init函数初始化的实际多项滤波器长度fLen] |
输入 |
height |
滤波器的个数。 |
(0, Init函数初始化的实际多项滤波器的高度fHeight] |
输入 |
src |
指向输入的滤波器系数或者指向输入的待重采样的数据。 |
非空 |
输入、输出 |
dst |
指向输出的滤波器系数或者指向输出的已重采样的数据。 |
非空 |
输入、输出 |
norm |
重采样数据的归一化系数。 |
float任意值 |
输入 |
time |
指向重采样的开始时间及结束时间。 |
非空 |
输入、输出 |
outLen |
指向重采样输出的数据长度。 |
非空 |
输入、输出 |
返回值
- 成功:返回HMPP_STS_NO_ERR。
- 失败:返回错误码。
错误码
错误码 |
描述 |
---|---|
HMPP_STS_NULL_PTR_ERR |
src、dst、policy、fLen、fHeight、time、outLen这几个入参中存在空指针。 |
HMPP_STS_SIZE_ERR |
len、step、height中存在小于或等于0。 |
HMPP_STS_BAD_ARG_ERR |
|
HMPP_STS_MALLOC_FAILED |
申请内存失败。 |
HMPP_STS_OVER_FLOW |
所需的内部buffer大小超过INT_MAX。 |
示例
#include <stdio.h> #include <stdint.h> #include "hmpps.h" #include "hmpp_core.h" #define BUFFER_SIZE_T 10 int main() { float src[4 + BUFFER_SIZE_T + 4] = {0, 0, 0, 0, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 0, 0, 0, 0}; int32_t inRate = 16000; int32_t outRate = 8000; int32_t inFilterLen = 6; float rollf = 0.95; float alpha = 9.0f; int32_t fLen; int32_t fHeight; float norm = 1.0; double time = 4.0; int32_t outLen; float dst[BUFFER_SIZE_T / 2]; HmppsResamplingPolyphaseFixed_32f *policy; HmppResult result = HMPPS_ResamplePolyphaseFixedInit_32f(inRate, outRate, inFilterLen, rollf, alpha, HMPP_ALGHINT_FAST, &fLen, &fHeight, &policy); if (result != HMPP_STS_NO_ERR) { return -1; } float *filter = (float *)HMPPS_Malloc_8u(fLen * fHeight * sizeof(float)); if (filter == NULL) { return -1; } result = HMPPS_ResamplePolyphaseGetFixedFilter_32f(filter, fLen, fHeight, policy); if (result != HMPP_STS_NO_ERR) { return -1; } printf("filter ="); for (int32_t i = 0; i < fHeight; i++) { for (int32_t j = 0; j < fLen; j++) { printf(" %f", *(filter + i * fLen + j)); } printf("\n"); } result = HMPPS_ResamplePolyphaseFixed_32f(src, BUFFER_SIZE_T, dst, norm, &time, &outLen, policy); printf("result = %d\n", result); if (result != HMPP_STS_NO_ERR) { return -1; } printf("dst ="); for (int32_t i = 0; i < outLen; i++) { printf(" %f", dst[i]); } printf("\n"); HMPPS_ResamplePolyphaseFixedRelease_32f(policy); HMPPS_Free(filter); return 0; }
运行结果:
filter = -0.000046 -0.012375 0.016357 0.493774 0.967378 0.493774 0.016357 -0.012375 result = 0 dst = 0.757003 1.183266 1.373958 1.570284 1.763205