Sonic

The Sonic component acts as a multidimensional filter that lets you adjust audio parameters of a WAV stream. This functionality may be useful to e.g. increase playback speed of an audio recording by a user selectable rate.

The following parameters can be adjusted:

  • speed

  • pitch

  • interpolation type

The adjustments of the first two parameters are represented by float values that provide the rate of adjustment. For example, to increase the speed of an audio sample by 2 times, call sonic_set_pitch_and_speed_info(el, 1.0, 2.0). To keep the speed as it is, call sonic_set_pitch_and_speed_info(el, 1.0, 1.0).

For the interpolation type you may select either faster but less accurate linear interpolation, or slower but more accurate FIR interpolation.

Application Example

Implementation of this API is demonstrated in audio_processing/pipeline_sonic example.

API Reference

Header File

Functions

esp_err_t sonic_set_info(audio_element_handle_t self, int rate, int ch)

Sets the audio sample rate and the number of channels to be processed by the sonic.

Return

ESP_OK ESP_FAIL

Parameters
  • self: Audio element handle

  • rate: The sample rate of stream data

  • ch: The number channels of stream data

esp_err_t sonic_set_pitch_and_speed_info(audio_element_handle_t self, float pitch, float speed)

Sets the audio pitch and speed to be processed by the sonic.

Return

ESP_OK ESP_FAIL

Parameters
  • self: Audio element handle

  • pitch: Scale factor of pitch of audio file. 0 means the original pitch. The range is [0.2 4.0].

  • speed: Scale factor of speed of audio file. 0 means the original speed. The range is [0.1 8.0].

audio_element_handle_t sonic_init(sonic_cfg_t *config)

Creates an Audio Element handle for sonic.

Return

The sonic audio element handle

Parameters
  • config: The sonic configuration

Structures

struct sonic_info_t

Information on audio file and configuration parameters required by sonic to process the file.

Public Members

int samplerate

Audio file sample rate (in Hz)

int channel

Number of audio file channels (Mono=1, Dual=2)

int resample_linear_interpolate

Flag of using simple linear interpolation. 1 indicates using simple linear interpolation. 0 indicates not using simple linear interpolation.

float pitch

Scale factor of pitch of audio file. If the value of ‘pitch’ is 0.3, the pitch of audio file processed by sonic islower than the original. If the value of ‘pitch’ is 1.3, the pitch of audio file processed by sonic is 30% higher than the original.

float speed

Scale factor of speed of audio file. If the value of ‘speed’ is 0.3, the speed of audio file processed by sonic is 70% slower than the original. If the value of ‘speed’ is 1.3, the speed of audio file processed by sonic is 30% faster than the original.

struct sonic_cfg_t

Sonic configuration.

Public Members

sonic_info_t sonic_info

Information of sonic

int out_rb_size

Size of output ring buffer

int task_stack

Task stack size

int task_core

Task running in core

int task_prio

Task priority

bool stack_in_ext

Try to allocate stack in external memory

Macros

SONIC_SET_VALUE_FOR_INITIALIZATION
SONIC_TASK_STACK
SONIC_TASK_CORE
SONIC_TASK_PRIO
SONIC_RINGBUFFER_SIZE
DEFAULT_SONIC_CONFIG()