Resample Filter

The Resample Filter is an Audio Element designed to downsample or upsample the incoming data stream as well as to convert the data between stereo and mono.

Application Example

Implementation of this API is demonstrated in the following examples:

API Reference

Header File

Functions

esp_err_t rsp_filter_set_src_info(audio_element_handle_t self, int src_rate, int src_ch)

Set the source audio sample rate and the number of channels to be processed by the resample. If need change bits or not ensure source data infomation, please use rsp_filter_change_src_info to instead this function.

Return

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG invalid arguments

Parameters
  • self: Audio element handle

  • src_rate: The sample rate of stream data

  • src_ch: The number channels of stream data

esp_err_t rsp_filter_change_src_info(audio_element_handle_t self, int src_rate, int src_ch, int src_bit)

Set the source audio sample rate, the number of channels and bits per sample to be processed by the resample.

Return

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG invalid arguments

Parameters
  • self: Audio element handle

  • src_rate: The sample rate of stream data

  • src_ch: The number channels of stream data

  • src_bit: The bit per sample of stream data

audio_element_handle_t rsp_filter_init(rsp_filter_cfg_t *config)

Create an Audio Element handle to resample incoming data.

    Depending on configuration, there are upsampling, downsampling, as well as
    converting data between mono and dual.

    - If the esp_resample_mode_t is `RESAMPLE_DECODE_MODE`, `src_rate` and `src_ch` will be fetched from `audio_element_getinfo`.
    - If the esp_resample_mode_t is `RESAMPLE_ENCODE_MODE`, `src_rate`, `src_ch`, `dest_rate` and `dest_ch` must be configured.

Return

The audio element handler

Parameters
  • config: The configuration

Structures

struct rsp_filter_cfg_t

Resample Filter Configuration.

Public Members

int src_rate

The sampling rate of the source PCM file (in Hz)

int src_ch

The number of channel(s) of the source PCM file (Mono=1, Dual=2)

int dest_rate

The sampling rate of the destination PCM file (in Hz)

int dest_bits

The bit for sample of the destination PCM data. Currently, supported bit width :16 bits.

int dest_ch

The number of channel(s) of the destination PCM file (Mono=1, Dual=2)

int src_bits

The bit for sample of the source PCM data. Currently, supported bit width :8bits 16 bits 24bits 32bits.

esp_resample_mode_t mode

The resampling mode (the encoding mode or the decoding mode). For decoding mode, input PCM length is constant; for encoding mode, output PCM length is constant.

int max_indata_bytes

The maximum buffer size of the input PCM (in bytes)

int out_len_bytes

The buffer length of the output stream data. This parameter must be configured in encoding mode.

esp_resample_type_t type

The resampling type (Automatic, Upsampling and Downsampling)

int complexity

Indicates the complexity of the resampling. This parameter is only valid when a FIR filter is used. Range:[1, 5]; 1 indicates the lowest complexity, which means the accuracy is the lowest and the speed is the fastest; Meanwhile, 5 indicates the highest complexity, which means the accuracy is the highest and the speed is the slowest.If user set complexity less than 1, complexity can be set 1. If user set complexity more than 5, complexity can be set 5.

int down_ch_idx

Indicates the channel that is selected (the right channel or the left channel). This parameter is only valid when the complexity parameter is set to 0 and the number of channel(s) of the input file has changed from dual to mono.

esp_rsp_prefer_type_t prefer_flag

The select flag about lesser CPU usage or lower INRAM usage, refer to esp_resample.h

int out_rb_size

Output ringbuffer size

int task_stack

Task stack size

int task_core

Task running on core

int task_prio

Task priority

bool stack_in_ext

Try to allocate stack in external memory

Macros

RSP_FILTER_BUFFER_BYTE
RSP_FILTER_TASK_STACK
RSP_FILTER_TASK_CORE
RSP_FILTER_TASK_PRIO
RSP_FILTER_RINGBUFFER_SIZE
DEFAULT_RESAMPLE_FILTER_CONFIG()