Rate This Document
Findability
Accuracy
Completeness
Readability

ResampleFixed

Resamples data by using Kaiser-windowed polyphase filters on ideal low-pass filters. This function is suitable for scenarios where the input and output rates are fixed rational numbers and provides better performance than the general Resample interface.

The function calling process is as follows:

  1. Initialize the structure by calling Init.
  2. Call the main function for resampling.
  3. Call Release to release the memory allocated to the structure.

The function interface declaration is as follows:

  • Initialization:

    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);

  • Setting filter coefficients:

    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);

  • Obtaining filter coefficients:

    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);

  • Resampling:

    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);

  • Memory release:

    HmppResult HMPPS_ResamplePolyphaseFixedRelease_32f(HmppsResamplingPolyphaseFixed_32f *policy);

    HmppResult HMPPS_ResamplePolyphaseFixedRelease_16s(HmppsResamplingPolyphaseFixed_16s *policy);

Parameters

Parameter

Description

Value Range

Input/Output

inRate

Input rate for fixed factor resampling

(0, INT_MAX]

Input

outRate

Output rate for fixed factor resampling

(0, INT_MAX]

Input

len

Filter length for fixed factor resampling, or length of the input data to be resampled

Filter length: (0, (INT_MAX - 0x4) / 4). The Init function checks the value validity, which is related to inRate and outRate.

Length of the data to be resampled: (0, INT_MAX * inRate / outRate)

Input

rollf

Roll-off frequency of the filter

(0, 1.0]

Input

alpha

Parameter of the Kaiser window

(1,FLT_MAX]

Input

policy

Pointer to the resampling policy structure, or pointer to the pointer to the resampling policy structure

The value cannot be NULL.

Input/Output

hint

Resampling mode

HMPP_ALGHINT_NONE

HMPP_ALGHINT_FAST

HMPP_ALGHINT_ACCURATE

Input

fLen

Actual length of the polyphase filter

The value cannot be NULL.

Input/Output

fHeight

Number of polyphase filters

The value cannot be NULL.

Input/Output

step

Step for the filter

(0, fLen)

Input

height

Number of filters

(0, fHeight)

Input

src

Pointer to the input filter coefficient or to the input data to be resampled

The value cannot be NULL.

Input/Output

dst

Pointer to the output filter coefficient or to the output resampled data

The value cannot be NULL.

Input/Output

norm

Normalization coefficient of resampled data

Any value of the FLOAT data type

Input

time

Start time and end time of resampling

The value cannot be NULL.

Input/Output

outLen

Length of the output resampled data

The value cannot be NULL.

Input/Output

Return Value

  • Success: HMPP_STS_NO_ERR
  • Failure: An error code is returned.

Error Codes

Error Code

Description

HMPP_STS_NULL_PTR_ERR

The value of src, dst, policy, fLen, fHeight, time, or outLen is NULL.

HMPP_STS_SIZE_ERR

The value of len, step, or height is less than or equal to 0.

HMPP_STS_BAD_ARG_ERR

  1. The value of rollf is less than or equal to 0 or greater than 1.
  2. The value of alpha is less than 1.
  3. The value of height is greater than the number of filters in the structure.

HMPP_STS_MALLOC_FAILED

Memory allocation failed.

HMPP_STS_OVER_FLOW

The size of the required internal buffer exceeds the value of INT_MAX.

Example

#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;
} 

Output:

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