Skip to content

Commit 06f8070

Browse files
committed
audio_render: more optimization
1 parent e06aa3d commit 06f8070

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

main/src/user/audio_render.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,21 @@ static void audio_render_task(void *pvParameter)
7979
xEventGroupSetBits(user_event_group, AUDIO_RENDER_CLR_BIT);
8080
}
8181

82+
taskYIELD();
83+
8284
if (start) {
8385
uint32_t remain = sizeof(buff_data) - xRingbufferGetCurFreeSize(audio_buff);
8486

85-
if (remain >= FFT_BLOCK_SIZE) {
87+
if (remain >= FFT_BLOCK_SIZE * 2) {
8688
delay = 0;
8789

88-
data = (uint8_t *)xRingbufferReceiveUpTo(audio_buff, &size, portMAX_DELAY, FFT_BLOCK_SIZE);
90+
data = (uint8_t *)xRingbufferReceiveUpTo(audio_buff, &size, portMAX_DELAY, FFT_BLOCK_SIZE * 2);
8991
} else if (remain > 0) {
9092
delay = 0;
9193

9294
data = (uint8_t *)xRingbufferReceiveUpTo(audio_buff, &size, portMAX_DELAY, remain);
9395
} else {
94-
if (++delay < 32) {
96+
if (++delay < 16) {
9597
vTaskDelay(1 / portTICK_RATE_MS);
9698
} else {
9799
delay = 0;
@@ -104,7 +106,7 @@ static void audio_render_task(void *pvParameter)
104106
continue;
105107
}
106108
} else {
107-
if (xRingbufferGetCurFreeSize(audio_buff) > FFT_BLOCK_SIZE) {
109+
if (xRingbufferGetCurFreeSize(audio_buff) > FFT_BLOCK_SIZE * 2) {
108110
vTaskDelay(1 / portTICK_RATE_MS);
109111
} else {
110112
start = true;
@@ -135,7 +137,7 @@ static void audio_render_task(void *pvParameter)
135137

136138
#ifdef CONFIG_ENABLE_VFX
137139
uxBits = xEventGroupGetBits(user_event_group);
138-
if ((size != FFT_BLOCK_SIZE) || !(uxBits & VFX_FFT_IDLE_BIT)) {
140+
if ((size < FFT_BLOCK_SIZE) || !(uxBits & VFX_FFT_IDLE_BIT)) {
139141
vRingbufferReturnItem(audio_buff, (void *)data);
140142
continue;
141143
}

main/src/user/bt_av.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ void bt_app_a2d_data_cb(const uint8_t *data, uint32_t len)
7575
if (audio_buff) {
7676
uint32_t pkt = 0, remain = 0;
7777

78-
for (pkt = 0; pkt < len / FFT_BLOCK_SIZE; pkt++) {
79-
xRingbufferSend(audio_buff, (void *)(data + pkt * FFT_BLOCK_SIZE), FFT_BLOCK_SIZE, portMAX_DELAY);
78+
for (pkt = 0; pkt < len / FFT_BLOCK_SIZE / 2; pkt++) {
79+
xRingbufferSend(audio_buff, (void *)(data + pkt * FFT_BLOCK_SIZE * 2), FFT_BLOCK_SIZE * 2, portMAX_DELAY);
80+
taskYIELD();
8081
}
8182

82-
remain = len - pkt * FFT_BLOCK_SIZE;
83+
remain = len - pkt * FFT_BLOCK_SIZE * 2;
8384
if (remain != 0) {
84-
xRingbufferSend(audio_buff, (void *)(data + pkt * FFT_BLOCK_SIZE), remain, portMAX_DELAY);
85+
xRingbufferSend(audio_buff, (void *)(data + pkt * FFT_BLOCK_SIZE * 2), remain, portMAX_DELAY);
86+
taskYIELD();
8587
}
8688
}
8789
}

0 commit comments

Comments
 (0)