Skip to content

Commit

Permalink
fixbug: internal memory not enough
Browse files Browse the repository at this point in the history
  • Loading branch information
78 committed Nov 6, 2024
1 parent 20deb2b commit 35cd80f
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)

set(PROJECT_VER "0.7.1")
set(PROJECT_VER "0.7.2")

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(xiaozhi)
24 changes: 12 additions & 12 deletions main/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void Application::Start() {
auto codec = board.GetAudioCodec();
opus_decode_sample_rate_ = codec->output_sample_rate();
opus_decoder_ = opus_decoder_create(opus_decode_sample_rate_, 1, NULL);
opus_encoder_.Configure(codec->input_sample_rate(), 1);
opus_encoder_.Configure(16000, 1);
if (codec->input_sample_rate() != 16000) {
input_resampler_.Configure(codec->input_sample_rate(), 16000);
reference_resampler_.Configure(codec->input_sample_rate(), 16000);
Expand Down Expand Up @@ -236,6 +236,17 @@ void Application::Start() {
}, "check_new_version", 4096 * 2, this, 1, NULL);

#ifdef CONFIG_USE_AFE_SR
audio_processor_.Initialize(codec->input_channels(), codec->input_reference());
audio_processor_.OnOutput([this](std::vector<int16_t>&& data) {
Schedule([this, data = std::move(data)]() {
if (chat_state_ == kChatStateListening) {
std::lock_guard<std::mutex> lock(mutex_);
audio_encode_queue_.emplace_back(std::move(data));
cv_.notify_all();
}
});
});

wake_word_detect_.Initialize(codec->input_channels(), codec->input_reference());
wake_word_detect_.OnVadStateChange([this](bool speaking) {
Schedule([this, speaking]() {
Expand Down Expand Up @@ -284,17 +295,6 @@ void Application::Start() {
});
});
wake_word_detect_.StartDetection();

audio_processor_.Initialize(codec->input_channels(), codec->input_reference());
audio_processor_.OnOutput([this](std::vector<int16_t>&& data) {
Schedule([this, data = std::move(data)]() {
if (chat_state_ == kChatStateListening) {
std::lock_guard<std::mutex> lock(mutex_);
audio_encode_queue_.emplace_back(std::move(data));
cv_.notify_all();
}
});
});
#endif

chat_state_ = kChatStateIdle;
Expand Down
2 changes: 1 addition & 1 deletion main/boards/esp-box-3/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#define AUDIO_INPUT_SAMPLE_RATE 16000
#define AUDIO_OUTPUT_SAMPLE_RATE 16000
#define AUDIO_DEFAULT_OUTPUT_VOLUME 90
#define AUDIO_DEFAULT_OUTPUT_VOLUME 80

#define AUDIO_INPUT_REFERENCE true

Expand Down
2 changes: 1 addition & 1 deletion main/boards/lichuang-dev/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#define AUDIO_INPUT_SAMPLE_RATE 24000
#define AUDIO_OUTPUT_SAMPLE_RATE 24000
#define AUDIO_DEFAULT_OUTPUT_VOLUME 90
#define AUDIO_DEFAULT_OUTPUT_VOLUME 80

#define AUDIO_INPUT_REFERENCE true

Expand Down
2 changes: 1 addition & 1 deletion main/boards/lichuang-dev/lichuang_dev_board.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class LichuangDevBoard : public WifiBoard {
audio_codec = new BoxAudioCodec(i2c_bus_, AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
AUDIO_I2S_GPIO_MCLK, AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN,
GPIO_NUM_NC, AUDIO_CODEC_ES8311_ADDR, AUDIO_CODEC_ES7210_ADDR, AUDIO_INPUT_REFERENCE);
// audio_codec->SetOutputVolume(AUDIO_DEFAULT_OUTPUT_VOLUME);
audio_codec->SetOutputVolume(AUDIO_DEFAULT_OUTPUT_VOLUME);
}
return audio_codec;
}
Expand Down
4 changes: 2 additions & 2 deletions main/display/st7789_display.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ St7789Display::St7789Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_h
.mirror_y = mirror_y_,
},
.flags = {
.buff_dma = 0,
.buff_spiram = 1,
.buff_dma = 1,
.buff_spiram = 0,
.sw_rotate = 0,
.full_refresh = 0,
.direct_mode = 0,
Expand Down
1 change: 1 addition & 0 deletions main/ota.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ void Ota::Upgrade(const std::string& firmware_url) {
size_t total_read = 0, recent_read = 0;
auto last_calc_time = esp_timer_get_time();
while (true) {
taskYIELD(); // Avoid watchdog timeout
int ret = http->Read(buffer, sizeof(buffer));
if (ret < 0) {
ESP_LOGE(TAG, "Failed to read HTTP data: %s", esp_err_to_name(ret));
Expand Down
9 changes: 7 additions & 2 deletions main/wake_word_detect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ WakeWordDetect::~WakeWordDetect() {
if (wake_word_encode_task_stack_ != nullptr) {
free(wake_word_encode_task_stack_);
}
if (audio_detection_task_stack_ != nullptr) {
heap_caps_free(audio_detection_task_stack_);
}

vEventGroupDelete(event_group_);
}
Expand Down Expand Up @@ -77,11 +80,13 @@ void WakeWordDetect::Initialize(int channels, bool reference) {

afe_detection_data_ = esp_afe_sr_v1.create_from_config(&afe_config);

xTaskCreate([](void* arg) {
const size_t audio_detection_task_stack_size = 4096 * 2;
audio_detection_task_stack_ = (StackType_t*)heap_caps_malloc(audio_detection_task_stack_size, MALLOC_CAP_SPIRAM);
xTaskCreateStatic([](void* arg) {
auto this_ = (WakeWordDetect*)arg;
this_->AudioDetectionTask();
vTaskDelete(NULL);
}, "audio_detection", 4096 * 2, this, 1, NULL);
}, "audio_detection", audio_detection_task_stack_size, this, 1, audio_detection_task_stack_, &audio_detection_task_buffer_);
}

void WakeWordDetect::OnWakeWordDetected(std::function<void()> callback) {
Expand Down
4 changes: 4 additions & 0 deletions main/wake_word_detect.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class WakeWordDetect {
int channels_;
bool reference_;

TaskHandle_t audio_detection_task_ = nullptr;
StaticTask_t audio_detection_task_buffer_;
StackType_t* audio_detection_task_stack_ = nullptr;

TaskHandle_t wake_word_encode_task_ = nullptr;
StaticTask_t wake_word_encode_task_buffer_;
StackType_t* wake_word_encode_task_stack_ = nullptr;
Expand Down
48 changes: 48 additions & 0 deletions release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import sys
import os
import json


def get_board_type():
with open("build/compile_commands.json") as f:
data = json.load(f)
for item in data:
if not item["file"].endswith("main.cc"):
continue
command = item["command"]
# extract -DBOARD_TYPE=xxx
board_type = command.split("-DBOARD_TYPE=\\\"")[1].split("\\\"")[0].strip()
return board_type
return None

def get_project_version():
with open("CMakeLists.txt") as f:
for line in f:
if line.startswith("set(PROJECT_VER"):
return line.split("\"")[1].split("\"")[0].strip()
return None

def merge_bin():
if os.system("idf.py merge-bin") != 0:
print("merge bin failed")
sys.exit(1)

def zip_bin(board_type, project_version):
if not os.path.exists("releases"):
os.makedirs("releases")
output_path = f"releases/v{project_version}_{board_type}.zip"
if os.path.exists(output_path):
os.remove(output_path)
if os.system(f"zip -j {output_path} build/merged-binary.bin") != 0:
print("zip bin failed")
sys.exit(1)
print(f"zip bin to {output_path} done")


if __name__ == "__main__":
merge_bin()
board_type = get_board_type()
print("board type:", board_type)
project_version = get_project_version()
print("project version:", project_version)
zip_bin(board_type, project_version)
2 changes: 2 additions & 0 deletions versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def get_board_name(folder):
return "bread-compact-wifi"
elif "KevinBox1" in basename:
return "kevin-box-1"
if basename.startswith("v0.7"):
return basename.split("_")[1]
raise Exception(f"Unknown board name: {basename}")

def read_binary(dir_path):
Expand Down

0 comments on commit 35cd80f

Please sign in to comment.