Rate This Document
Findability
Accuracy
Completeness
Readability

Resample

Resamples data by using Kaiser-windowed polyphase filters on ideal low-pass filters. This function is suitable for data with a variable resampling rate.

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 left and right sides of the input data src to be resampled must contain the extension data required for filtering. The relationship between filterLen, factor, step, and window is as follows:

filterLen/2 = window * 0.5 + 1; factor > 1.0

filterLen/2 = window * 0.5/factor + 1.0/(factor * step); factor < 1.0

Number of data segments in the left extension line of the src: (filterLen/2) - time;

Number of data segments in the right extension line of the src: time + (filterLen/2);

That is, the src length should be the sum of len and filterLen.

The function interface declaration is as follows:

  • Initialization:

    HmppResult HMPPS_ResamplePolyphaseInit_32f(float window, int32_t step, float rollf, float alpha, HmppHintAlgorithm hint, HmppsResamplingPolyphase_32f **policy);

    HmppResult HMPPS_ResamplePolyphaseInit_16s(float window, int32_t step, float rollf, float alpha, HmppHintAlgorithm hint, HmppsResamplingPolyphase_16s **policy);

  • Resampling:

    HmppResult HMPPS_ResamplePolyphase_32f(const float *src, int32_t len, float *dst, double factor, float norm, double *time,int32_t *outLen, const HmppsResamplingPolyphase_32f *policy);

    HmppResult HMPPS_ResamplePolyphase_16s(const int16_t *src, int32_t len, int16_t *dst, double factor, float norm, double *time,int32_t *outLen, const HmppsResamplingPolyphase_16s *policy);

  • Memory release:

    HmppResult HMPPS_ResamplePolyphaseRelease_32f(HmppsResamplingPolyphase_32f *policy);

    HmppResult HMPPS_ResamplePolyphaseRelease_16s(HmppsResamplingPolyphase_16s *policy);

Parameters

Parameter

Description

Value Range

Input/Output

window

Size of the ideal low-pass filter window

(0, (INT_MAX - 0x90)/4/step)

Input

step

Step for polyphase filters

(0, (INT_MAX - 0x90)/4/window)

Input

rollf

Roll-off frequency of the filter

(0, 1.0]

Input

alpha

Parameter of the Kaiser window

(1.0, 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

src

Pointer to the input data to be resampled and the delay line

The value cannot be NULL.

Input

dst

Pointer to the output resampled data

The value cannot be NULL.

Input/Output

len

Length of the data to be resampled

If factor ≥ 1.0, the value range is (0, INT_MAX/factor).

If factor < 1.0, the value range is (0, INT_MAX).

Input

factor

Resampling factor

(0, DBL_MAX]

Input

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, time, or outLen is NULL.

HMPP_STS_SIZE_ERR

The value of len 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 window is less than 2/step.
  4. The value of factor is less than or equal to 0.

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};
    float window = 6.0;
    int32_t step = 2;
    float rollf = 0.95;
    float alpha = 9.0f;
    double factor = 0.5;
    float norm = 1.0;
    double time = 4.0;
    int32_t outLen;
    float dst[BUFFER_SIZE_T/2];
    HmppsResamplingPolyphase_32f *policy;

    HmppResult result = HMPPS_ResamplePolyphaseInit_32f(window, step, rollf, alpha, HMPP_ALGHINT_FAST, &policy);
    if (result != HMPP_STS_NO_ERR) {
        return -1;    
    }
    result = HMPPS_ResamplePolyphase_32f(src, BUFFER_SIZE_T, dst, factor, norm, &time, &outLen, policy);
    printf("result = %d, outLen = %d\n", result, outLen);
    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_ResamplePolyphaseRelease_32f(policy);

    return 0;
} 

Output:

result = 0, outLen = 5
dst = 0.761617 1.231306 1.398704 1.602798 1.842311