|
9 | 9 | #include "esp_log.h" |
10 | 10 | #include "esp_gmf_oal_mem.h" |
11 | 11 | #include "esp_gmf_oal_mutex.h" |
12 | | -#include "esp_gmf_audio_element.h" |
13 | 12 | #include "esp_gmf_node.h" |
14 | 13 | #include "esp_gmf_alc.h" |
15 | 14 | #include "esp_gmf_args_desc.h" |
|
18 | 17 | #include "esp_gmf_cap.h" |
19 | 18 | #include "esp_gmf_caps_def.h" |
20 | 19 |
|
21 | | -#define GMF_DEFAULT_MAX_CHANNLE 2 |
| 20 | +#define GMF_ALC_DEFAULT_MAX_CHANNEL 2 |
22 | 21 | /** |
23 | 22 | * @brief Audio ALC context in GMF |
24 | 23 | */ |
@@ -255,7 +254,7 @@ esp_gmf_err_t esp_gmf_alc_set_gain(esp_gmf_audio_element_handle_t handle, uint8_ |
255 | 254 | { |
256 | 255 | ESP_GMF_NULL_CHECK(TAG, handle, { return ESP_GMF_ERR_INVALID_ARG;}); |
257 | 256 | esp_gmf_alc_t *alc = (esp_gmf_alc_t *)handle; |
258 | | - if(idx > alc->max_ch) { |
| 257 | + if (idx >= alc->max_ch) { |
259 | 258 | ESP_LOGE(TAG, "Gain index %d is out of range", idx); |
260 | 259 | return ESP_GMF_ERR_INVALID_ARG; |
261 | 260 | } |
@@ -301,15 +300,16 @@ esp_gmf_err_t esp_gmf_alc_init(esp_ae_alc_cfg_t *config, esp_gmf_obj_handle_t *h |
301 | 300 | esp_gmf_obj_t *obj = (esp_gmf_obj_t *)alc; |
302 | 301 | obj->new_obj = esp_gmf_alc_new; |
303 | 302 | obj->del_obj = esp_gmf_alc_destroy; |
| 303 | + alc->max_ch = GMF_ALC_DEFAULT_MAX_CHANNEL; |
304 | 304 | if (config) { |
305 | 305 | esp_ae_alc_cfg_t *cfg = esp_gmf_oal_calloc(1, sizeof(*config)); |
306 | 306 | ESP_GMF_MEM_VERIFY(TAG, cfg, {ret = ESP_GMF_ERR_MEMORY_LACK; goto ALC_INIT_FAIL;}, "alc configuration", sizeof(*config)); |
307 | | - alc->max_ch = config->channel > 0 ? config->channel : GMF_DEFAULT_MAX_CHANNLE; |
308 | | - alc->gain = esp_gmf_oal_calloc(1, alc->max_ch * sizeof(*alc->gain)); |
309 | | - ESP_GMF_MEM_VERIFY(TAG, alc->gain, goto ALC_INIT_FAIL, "alc gain", alc->max_ch * sizeof(*alc->gain)); |
| 307 | + alc->max_ch = config->channel > 0 ? config->channel : GMF_ALC_DEFAULT_MAX_CHANNEL; |
310 | 308 | memcpy(cfg, config, sizeof(*config)); |
311 | 309 | esp_gmf_obj_set_config(obj, cfg, sizeof(*config)); |
312 | 310 | } |
| 311 | + alc->gain = esp_gmf_oal_calloc(1, alc->max_ch * sizeof(int8_t)); |
| 312 | + ESP_GMF_MEM_VERIFY(TAG, alc->gain, goto ALC_INIT_FAIL, "alc gain", alc->max_ch * sizeof(int8_t)); |
313 | 313 | ret = esp_gmf_obj_set_tag(obj, "alc"); |
314 | 314 | ESP_GMF_RET_ON_NOT_OK(TAG, ret, goto ALC_INIT_FAIL, "Failed to set obj tag"); |
315 | 315 | esp_gmf_element_cfg_t el_cfg = {0}; |
|
0 commit comments