55 * Author: Jack Chen <redchenjs@live.com>
66 */
77
8- #include <string.h>
9-
108#include "esp_log.h"
119
1210#include "freertos/FreeRTOS.h"
@@ -28,22 +26,6 @@ RingbufHandle_t audio_buff = NULL;
2826static uint8_t buff_data [10 * 1024 ] = {0 };
2927static StaticRingbuffer_t buff_struct = {0 };
3028
31- /* render callback for the libmad synth */
32- void render_sample_block (short * sample_ch0 , short * sample_ch1 , unsigned int sample_rate , unsigned int nch , unsigned int ns )
33- {
34- if (nch == 1 ) {
35- sample_ch1 = sample_ch0 ;
36- }
37-
38- i2s_output_set_sample_rate (sample_rate );
39-
40- size_t bytes_written = 0 ;
41- for (int i = 0 ; i < ns ; i ++ ) {
42- i2s_write (CONFIG_AUDIO_OUTPUT_I2S_NUM , sample_ch0 ++ , sizeof (short ), & bytes_written , portMAX_DELAY );
43- i2s_write (CONFIG_AUDIO_OUTPUT_I2S_NUM , sample_ch1 ++ , sizeof (short ), & bytes_written , portMAX_DELAY );
44- }
45- }
46-
4729static void audio_render_task (void * pvParameter )
4830{
4931 uint16_t delay = 0 ;
@@ -80,7 +62,7 @@ static void audio_render_task(void *pvParameter)
8062
8163 data = (uint8_t * )xRingbufferReceiveUpTo (audio_buff , & size , portMAX_DELAY , remain );
8264 } else {
83- if (++ delay < 16 ) {
65+ if (++ delay <= 256000 / a2d_sample_rate ) {
8466 vTaskDelay (1 / portTICK_RATE_MS );
8567 } else {
8668 delay = 0 ;
@@ -93,7 +75,7 @@ static void audio_render_task(void *pvParameter)
9375 continue ;
9476 }
9577 } else {
96- if (xRingbufferGetCurFreeSize (audio_buff ) > FFT_BLOCK_SIZE ) {
78+ if (xRingbufferGetCurFreeSize (audio_buff ) >= FFT_BLOCK_SIZE ) {
9779 vTaskDelay (1 / portTICK_RATE_MS );
9880 } else {
9981 start = true;
@@ -146,7 +128,6 @@ static void audio_render_task(void *pvParameter)
146128
147129void audio_render_init (void )
148130{
149- memset (& buff_struct , 0x00 , sizeof (StaticRingbuffer_t ));
150131 audio_buff = xRingbufferCreateStatic (sizeof (buff_data ), RINGBUF_TYPE_BYTEBUF , buff_data , & buff_struct );
151132
152133 xTaskCreatePinnedToCore (audio_render_task , "audioRenderT" , 1920 , NULL , configMAX_PRIORITIES - 3 , NULL , 0 );
0 commit comments