@@ -203,12 +203,11 @@ static esp_err_t rsp_open(audio_forge_t *audio_forge, int index)
203203
204204 audio_forge -> rsp_handle [index ] = esp_resample_create ((void * )& audio_forge -> rsp_info [index ], & audio_forge -> rsp_in [index ], & audio_forge -> rsp_out [index ]);
205205 AUDIO_NULL_CHECK (TAG , audio_forge -> rsp_handle [index ], return ESP_FAIL );
206- if (audio_forge -> inbuf [index ]) {
207- void * tmp = audio_forge -> inbuf [index ];
208- audio_forge -> inbuf [index ] = audio_forge -> rsp_out [index ];
209- audio_free (tmp );
206+ if ((audio_forge -> rsp_info [index ].src_ch < audio_forge -> channel ) && (index == 0 )) {
207+ audio_forge -> inbuf [index ] = audio_realloc (audio_forge -> inbuf [index ], audio_forge -> max_sample * sizeof (short ) * MAX_MEM_PARA );
208+ AUDIO_MEM_CHECK (TAG , audio_forge -> inbuf [index ], return ESP_ERR_NO_MEM );
210209 } else {
211- audio_forge -> inbuf [index ] = audio_forge -> rsp_out [index ];
210+ audio_forge -> inbuf [index ] = ( audio_forge -> inbuf [ index ] != NULL ) ? audio_forge -> inbuf [ index ] : audio_forge -> rsp_out [index ];
212211 }
213212 if (audio_forge -> downmix .source_num == 1 ) {
214213 if (audio_forge -> rsp_info [index ].src_ch != audio_forge -> channel ) {
@@ -243,12 +242,8 @@ static esp_err_t sonic_open(audio_forge_t *audio_forge)
243242 esp_sonic_set_pitch (audio_forge -> sonic_handle , audio_forge -> sonic_pitch );
244243 audio_forge -> sonic_num = (audio_forge -> sample_rate << 1 ) / SONIC_MIN_PITCH ;
245244 audio_forge -> sonic_num = audio_forge -> sonic_num / audio_forge -> max_sample + 1 ;
246- if (audio_forge -> component_select & AUDIO_FORGE_SELECT_RESAMPLE ) {
247- if (audio_forge -> inbuf [0 ] == audio_forge -> rsp_out [0 ]) {
248- audio_forge -> inbuf [0 ] = (unsigned char * )audio_calloc (1 , audio_forge -> max_sample * sizeof (short ) * MAX_MEM_PARA );
249- }
250- } else {
251- audio_forge -> inbuf [0 ] = (unsigned char * )audio_realloc (audio_forge -> inbuf [0 ], audio_forge -> max_sample * sizeof (short ) * MAX_MEM_PARA );
245+ if (audio_forge -> inbuf [0 ] == NULL ) {
246+ audio_forge -> inbuf [0 ] = (unsigned char * )audio_calloc (1 , audio_forge -> max_sample * sizeof (short ) * MAX_MEM_PARA );
252247 }
253248 AUDIO_MEM_CHECK (TAG , audio_forge -> inbuf [0 ], return ESP_ERR_NO_MEM );
254249 audio_forge -> outbuf = (unsigned char * )audio_realloc (audio_forge -> outbuf , audio_forge -> max_sample * sizeof (short ) * MAX_MEM_PARA );
@@ -669,7 +664,7 @@ static int audio_forge_process(audio_element_handle_t self, char *in_buffer, int
669664 mutex_unlock (audio_forge -> lock );
670665 return ESP_FAIL ;
671666 }
672- if (ret > 0 ) {
667+ if (ret > 0 && audio_forge -> inbuf [ i ] != audio_forge -> rsp_out [ i ] ) {
673668 memcpy (audio_forge -> inbuf [i ], audio_forge -> rsp_out [i ], audio_forge -> rsp_info [i ].out_len_bytes );
674669 }
675670 } else {
0 commit comments