Downmix¶
This API is intended for mixing of two audio files (streams), defined as the base audio file and the newcome audio file, into one output audio file.
The newcome audio file will be downmixed into the base audio file with individual gains applied to each file.
The number of channel(s) of the output audio file will be the same with that of the base audio file. The number of channel(s) of the newcome audio file will also be changed to the same with the base audio file, if it is different from that of the base audio file.
The downmix process has 3 states:
- Bypass Downmixing – Only the base audio file will be processed;
- Switch on Downmixing – The base audio file and the target audio file will first enter the transition period, during which the gains of these two files will be changed from the original level to the target level; then enter the stable period, sharing a same target gain;
- Switch off Downmixing – The base audio file and the target audio file will first enter the transition period, during which the gains of these two files will be changed back to their original levels; then enter the stable period, with their original gains, respectively. After that, the downmix process enters the bypass state.
Note that, the sample rates of the base audio file and the newcome audio file must be the same, otherwise an error occurs.
Application Example¶
Implementation of this API is demonstrated in advanced_examples/downmix_pipeline example.
API Reference¶
Header File¶
Functions¶
-
void
downmix_set_input_rb_timeout
(audio_element_handle_t self, int ticks_to_wait)¶ Sets the downmix timeout.
- Parameters
self
: audio element handleticks_to_wait
: input ringbuffer timeout
-
void
downmix_set_input_rb
(audio_element_handle_t self, ringbuf_handle_t rb, int index)¶ Sets the downmix input ringbuffer. refer to
ringbuf.h
- Parameters
self
: audio element handlerb
: handle of ringbufferindex
: The index of multi input ringbuffer.
-
esp_err_t
downmix_set_output_type
(audio_element_handle_t self, esp_downmix_output_type_t output_type)¶ Passes number of channels for output stream. Only supported mono and dual.
- Return
- ESP_OK ESP_FAIL
- Parameters
self
: audio element handleoutput_type
: down-mixer output type.
-
esp_err_t
downmix_set_work_mode
(audio_element_handle_t self, esp_downmix_work_mode_t mode)¶ Sets BYPASS, ON or OFF status of down-mixer.
- Return
- ESP_OK ESP_FAIL
- Parameters
self
: audio element handlemode
: down-mixer work mode.
-
esp_err_t
downmix_set_out_ctx_info
(audio_element_handle_t self, esp_downmix_out_ctx_type_t out_ctx)¶ Passes content of per channel output stream by down-mixer.
- Return
- ESP_OK ESP_FAIL
- Parameters
self
: audio element handleout_ctx
: content of output stream.
-
esp_err_t
downmix_set_source_stream_info
(audio_element_handle_t self, int rate, int ch, int index)¶ Sets the sample rate and the number of channels of input stream to be processed.
- Return
- ESP_OK ESP_FAIL
- Parameters
self
: audio element handlerate
: sample rate of the input streamch
: number of channel(s) of the input streamindex
: The index of input stream. The index must be in [0, SOURCE_NUM_MAX - 1] range.
-
esp_err_t
downmix_set_gain_info
(audio_element_handle_t self, float *gain, int index)¶ Sets the audio gain to be processed.
- Return
- ESP_OK ESP_FAIL
- Parameters
self
: audio element handlegain
: the reset value ofgain
. Thegain
is an array of two elements.index
: The index of input stream. The index must be in [0, SOURCE_NUM_MAX - 1] range.
-
esp_err_t
downmix_set_transit_time_info
(audio_element_handle_t self, int transit_time, int index)¶ Sets the audio
transit_time
to be processed.- Return
- ESP_OK ESP_FAIL
- Parameters
self
: audio element handletransit_time
: the reset value oftransit_time
index
: The index of input stream. The index must be in [0, SOURCE_NUM_MAX - 1] range
-
esp_err_t
source_info_init
(audio_element_handle_t self, esp_downmix_input_info_t *source_num)¶ Initializes information of the source streams for downmixing.
- Return
- ESP_OK ESP_FAIL
- Parameters
self
: audio element handlesource_num
: The information array of source streams
-
audio_element_handle_t
downmix_init
(downmix_cfg_t *config)¶ Initializes the Audio Element handle for downmixing.
- Return
- The initialized Audio Element handle
- Parameters
config
: the configuration