|
@@ -418,7 +418,7 @@ void Application::Start() {
|
|
|
Application* app = (Application*)arg;
|
|
Application* app = (Application*)arg;
|
|
|
app->MainLoop();
|
|
app->MainLoop();
|
|
|
vTaskDelete(NULL);
|
|
vTaskDelete(NULL);
|
|
|
- }, "main_loop", 4096 * 2, this, 3, nullptr);
|
|
|
|
|
|
|
+ }, "main_loop", 4096 , this, 3, nullptr);
|
|
|
|
|
|
|
|
/* Wait for the network to be ready */
|
|
/* Wait for the network to be ready */
|
|
|
board.StartNetwork();
|
|
board.StartNetwork();
|
|
@@ -657,18 +657,50 @@ void Application::Schedule(std::function<void()> callback) {
|
|
|
);
|
|
);
|
|
|
*
|
|
*
|
|
|
*/
|
|
*/
|
|
|
-void Application::MainLoop() {
|
|
|
|
|
- while (true) {
|
|
|
|
|
- auto bits = xEventGroupWaitBits(event_group_,
|
|
|
|
|
- SCHEDULE_EVENT | AUDIO_INPUT_READY_EVENT | AUDIO_OUTPUT_READY_EVENT,
|
|
|
|
|
|
|
+
|
|
|
|
|
+// 初始化函数中创建音频任务
|
|
|
|
|
+void Application::Init() {
|
|
|
|
|
+ // 创建音频输入任务
|
|
|
|
|
+ xTaskCreate([](void* arg) {
|
|
|
|
|
+ Application* app = (Application*)arg;
|
|
|
|
|
+ while(true) {
|
|
|
|
|
+ auto bits = xEventGroupWaitBits(app->event_group_,
|
|
|
|
|
+ AUDIO_INPUT_READY_EVENT,
|
|
|
pdTRUE, pdFALSE, portMAX_DELAY);
|
|
pdTRUE, pdFALSE, portMAX_DELAY);
|
|
|
|
|
|
|
|
- if (bits & AUDIO_INPUT_READY_EVENT) {
|
|
|
|
|
- InputAudio();
|
|
|
|
|
|
|
+ if (bits & AUDIO_INPUT_READY_EVENT) {
|
|
|
|
|
+ app->InputAudio();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ESP_LOGI(TAG, "录音中");
|
|
|
}
|
|
}
|
|
|
- if (bits & AUDIO_OUTPUT_READY_EVENT) {
|
|
|
|
|
- OutputAudio();
|
|
|
|
|
|
|
+ }, "audio_input_task", 4096*2, this, 2, &inputTaskHandle);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建音频输出任务
|
|
|
|
|
+ xTaskCreate([](void* arg) {
|
|
|
|
|
+ Application* app = (Application*)arg;
|
|
|
|
|
+ while(true) {
|
|
|
|
|
+ auto bits = xEventGroupWaitBits(app->event_group_,
|
|
|
|
|
+ AUDIO_OUTPUT_READY_EVENT,
|
|
|
|
|
+ pdTRUE, pdFALSE, portMAX_DELAY);
|
|
|
|
|
+
|
|
|
|
|
+ if (bits & AUDIO_OUTPUT_READY_EVENT) {
|
|
|
|
|
+ app->OutputAudio();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ESP_LOGI(TAG, "播放中");
|
|
|
}
|
|
}
|
|
|
|
|
+ }, "audio_output_task", 4096*2, this, 2, &outputTaskHandle);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void Application::MainLoop() {
|
|
|
|
|
+
|
|
|
|
|
+ Init();
|
|
|
|
|
+
|
|
|
|
|
+ while (true) {
|
|
|
|
|
+ auto bits = xEventGroupWaitBits(event_group_,
|
|
|
|
|
+ SCHEDULE_EVENT,
|
|
|
|
|
+ pdTRUE, pdFALSE, portMAX_DELAY);
|
|
|
if (bits & SCHEDULE_EVENT) {
|
|
if (bits & SCHEDULE_EVENT) {
|
|
|
std::unique_lock<std::mutex> lock(mutex_);
|
|
std::unique_lock<std::mutex> lock(mutex_);
|
|
|
std::list<std::function<void()>> tasks = std::move(main_tasks_);
|
|
std::list<std::function<void()>> tasks = std::move(main_tasks_);
|