ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dsps_resampler_ph.c File Reference
#include "dsps_resampler.h"
#include <math.h>
Include dependency graph for dsps_resampler_ph.c:

Go to the source code of this file.

Functions

esp_err_t dsps_resampler_ph_init (dsps_resample_ph_t *resampler, float samplerate_factor)
 Initialize the poly-phase resampler.
int32_t dsps_resampler_ph_exec (dsps_resample_ph_t *resampler, float *input, float *output, int32_t length)
 Execute the poly-phase resampler.

Function Documentation

◆ dsps_resampler_ph_exec()

int32_t dsps_resampler_ph_exec ( dsps_resample_ph_t * resampler,
float * input,
float * output,
int32_t length )

Execute the poly-phase resampler.

Parameters
resamplerPointer to the resampler structure
inputPointer to the input buffer
outputPointer to the output buffer
lengthLength of the input buffer
Returns
Length of the output buffer

Definition at line 28 of file dsps_resampler_ph.c.

29{
30 int32_t result = 0;
31 int input_pos = 0;
32 float in_x[4];
33
34 int in_pos = 0;
35 for (int pos = resampler->delay_pos; pos < 4; pos++) {
36 in_x[in_pos++] = resampler->delay[pos];
37 }
38 for (int pos = 0; pos < resampler->delay_pos; pos++) {
39 in_x[in_pos++] = resampler->delay[pos];
40 }
41
42 while (input_pos < length) {
43
44 float c0 = in_x[1];
45 float c1 = 0.5 * (in_x[2] - in_x[0]);
46 float c2 = in_x[0] - 2.5 * in_x[1] + 2 * in_x[2] - 0.5 * in_x[3];
47 float c3 = 0.5 * (in_x[3] - in_x[0]) + 1.5 * (in_x[1] - in_x[2]);
48
49 output[result] = c0 + resampler->phase * (c1 + resampler->phase * (c2 + resampler->phase * c3));
50 result++;
51 resampler->phase += resampler->step;
52
53 while (resampler->phase >= 1) {
54 resampler->phase -= 1;
55 resampler->delay[resampler->delay_pos] = input[input_pos];
56 resampler->delay_pos++;
57 if (resampler->delay_pos >= 4) {
58 resampler->delay_pos = 0;
59 }
60 input_pos++;
61 in_pos = 0;
62 for (int pos = resampler->delay_pos; pos < 4; pos++) {
63 in_x[in_pos++] = resampler->delay[pos];
64 }
65 for (int pos = 0; pos < resampler->delay_pos; pos++) {
66 in_x[in_pos++] = resampler->delay[pos];
67 }
68 }
69 }
70
71 return result;
72}

References dsps_resample_ph_s::delay, dsps_resample_ph_s::delay_pos, dsps_resample_ph_s::phase, and dsps_resample_ph_s::step.

◆ dsps_resampler_ph_init()

esp_err_t dsps_resampler_ph_init ( dsps_resample_ph_t * resampler,
float samplerate_factor )

Initialize the poly-phase resampler.

The poly-phase resampler is a implementation of the poly-phase Farrow filter that use cubic interpolation with 4 coefficients.

Parameters
resamplerPointer to the resampler structure
samplerate_factorSample rate factor
Returns
ESP_OK on success, ESP_ERR_INVALID_ARG if the parameters are invalid

Definition at line 10 of file dsps_resampler_ph.c.

11{
12 esp_err_t ret = ESP_OK;
13
14 if (samplerate_factor < 1) {
16 }
17
18 for (int i = 0; i < 4; i++) {
19 resampler->delay[i] = 0;
20 }
21 resampler->delay_pos = 0;
22
23 resampler->step = 1.0f / samplerate_factor;
24 resampler->phase = 0;
25 return ret;
26}
#define ESP_ERR_DSP_INVALID_PARAM
int esp_err_t
Definition esp_err.h:21
#define ESP_OK
Definition esp_err.h:23

References dsps_resample_ph_s::delay, dsps_resample_ph_s::delay_pos, ESP_ERR_DSP_INVALID_PARAM, ESP_OK, dsps_resample_ph_s::phase, and dsps_resample_ph_s::step.