diff options
-rw-r--r-- | apps/debug_menu.c | 27 | ||||
-rw-r--r-- | apps/talk.c | 24 | ||||
-rw-r--r-- | apps/talk.h | 10 |
3 files changed, 49 insertions, 12 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c index bb5d3b4a8a..1ba1e30102 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c | |||
@@ -2362,33 +2362,42 @@ static const char* dbg_talk_get_name(int selected_item, void *data, | |||
2362 | switch(selected_item) | 2362 | switch(selected_item) |
2363 | { | 2363 | { |
2364 | case 0: | 2364 | case 0: |
2365 | if (talk_data) | 2365 | if (talk_data->status != TALK_STATUS_ERR_NOFILE) |
2366 | snprintf(buffer, buffer_len, "Current voice file: %s", | 2366 | snprintf(buffer, buffer_len, "Current voice file: %s", |
2367 | talk_data->voicefile); | 2367 | talk_data->voicefile); |
2368 | else | 2368 | else |
2369 | buffer = "No voice information available"; | 2369 | buffer = "No voice information available"; |
2370 | break; | 2370 | break; |
2371 | case 1: | 2371 | case 1: |
2372 | if (talk_data->status == TALK_STATUS_OK) | ||
2373 | buffer = "Talk Status: OK"; | ||
2374 | else if (talk_data->status != TALK_STATUS_ERR_INCOMPATIBLE) | ||
2375 | snprintf(buffer, buffer_len, "Talk Status: ERR (%i)", | ||
2376 | talk_data->status); | ||
2377 | else | ||
2378 | buffer = "Talk Status: ERR Incompatible voice file"; | ||
2379 | break; | ||
2380 | case 2: | ||
2372 | snprintf(buffer, buffer_len, "Number of (empty) clips in voice file: (%d) %d", | 2381 | snprintf(buffer, buffer_len, "Number of (empty) clips in voice file: (%d) %d", |
2373 | talk_data->num_empty_clips, talk_data->num_clips); | 2382 | talk_data->num_empty_clips, talk_data->num_clips); |
2374 | break; | 2383 | break; |
2375 | case 2: | 2384 | case 3: |
2376 | snprintf(buffer, buffer_len, "Min/Avg/Max size of clips: %d / %d / %d", | 2385 | snprintf(buffer, buffer_len, "Min/Avg/Max size of clips: %d / %d / %d", |
2377 | talk_data->min_clipsize, talk_data->avg_clipsize, talk_data->max_clipsize); | 2386 | talk_data->min_clipsize, talk_data->avg_clipsize, talk_data->max_clipsize); |
2378 | break; | 2387 | break; |
2379 | case 3: | 2388 | case 4: |
2380 | snprintf(buffer, buffer_len, "Memory allocated: %ld.%02ld KB", | 2389 | snprintf(buffer, buffer_len, "Memory allocated: %ld.%02ld KB", |
2381 | talk_data->memory_allocated / 1024, talk_data->memory_allocated % 1024); | 2390 | talk_data->memory_allocated / 1024, talk_data->memory_allocated % 1024); |
2382 | break; | 2391 | break; |
2383 | case 4: | 2392 | case 5: |
2384 | snprintf(buffer, buffer_len, "Memory used: %ld.%02ld KB", | 2393 | snprintf(buffer, buffer_len, "Memory used: %ld.%02ld KB", |
2385 | talk_data->memory_used / 1024, talk_data->memory_used % 1024); | 2394 | talk_data->memory_used / 1024, talk_data->memory_used % 1024); |
2386 | break; | 2395 | break; |
2387 | case 5: | 2396 | case 6: |
2388 | snprintf(buffer, buffer_len, "Number of clips in cache: %d", | 2397 | snprintf(buffer, buffer_len, "Number of clips in cache: %d", |
2389 | talk_data->cached_clips); | 2398 | talk_data->cached_clips); |
2390 | break; | 2399 | break; |
2391 | case 6: | 2400 | case 7: |
2392 | snprintf(buffer, buffer_len, "Cache hits / misses: %d / %d", | 2401 | snprintf(buffer, buffer_len, "Cache hits / misses: %d / %d", |
2393 | talk_data->cache_hits, talk_data->cache_misses); | 2402 | talk_data->cache_hits, talk_data->cache_misses); |
2394 | break; | 2403 | break; |
@@ -2405,9 +2414,9 @@ static bool dbg_talk(void) | |||
2405 | struct simplelist_info list; | 2414 | struct simplelist_info list; |
2406 | struct talk_debug_data data; | 2415 | struct talk_debug_data data; |
2407 | if (talk_get_debug_data(&data)) | 2416 | if (talk_get_debug_data(&data)) |
2408 | simplelist_info_init(&list, "Voice Information:", 7, &data); | 2417 | simplelist_info_init(&list, "Voice Information:", 8, &data); |
2409 | else | 2418 | else |
2410 | simplelist_info_init(&list, "Voice Information:", 1, NULL); | 2419 | simplelist_info_init(&list, "Voice Information:", 2, &data); |
2411 | list.scroll_all = true; | 2420 | list.scroll_all = true; |
2412 | list.hide_selection = true; | 2421 | list.hide_selection = true; |
2413 | list.timeout = HZ; | 2422 | list.timeout = HZ; |
diff --git a/apps/talk.c b/apps/talk.c index 9c53bb6da5..b561d5cde8 100644 --- a/apps/talk.c +++ b/apps/talk.c | |||
@@ -131,6 +131,7 @@ static bool need_shutup; /* is there possibly any voice playing to be shutup */ | |||
131 | static bool force_enqueue_next; /* enqueue next utterance even if enqueue is false */ | 131 | static bool force_enqueue_next; /* enqueue next utterance even if enqueue is false */ |
132 | static int queue_write; /* write index of queue, by application */ | 132 | static int queue_write; /* write index of queue, by application */ |
133 | static int queue_read; /* read index of queue, by ISR context */ | 133 | static int queue_read; /* read index of queue, by ISR context */ |
134 | static enum talk_status talk_status = TALK_STATUS_OK; | ||
134 | #if CONFIG_CODEC == SWCODEC | 135 | #if CONFIG_CODEC == SWCODEC |
135 | /* protects queue_read, queue_write and thumbnail_buf_used */ | 136 | /* protects queue_read, queue_write and thumbnail_buf_used */ |
136 | static struct mutex queue_mutex SHAREDBSS_ATTR; | 137 | static struct mutex queue_mutex SHAREDBSS_ATTR; |
@@ -595,6 +596,7 @@ static bool create_clip_buffer(size_t max_size) | |||
595 | return true; | 596 | return true; |
596 | 597 | ||
597 | alloc_err: | 598 | alloc_err: |
599 | talk_status = TALK_STATUS_ERR_ALLOC; | ||
598 | index_handle = core_free(index_handle); | 600 | index_handle = core_free(index_handle); |
599 | return false; | 601 | return false; |
600 | } | 602 | } |
@@ -603,11 +605,17 @@ alloc_err: | |||
603 | static bool load_voicefile_index(int fd) | 605 | static bool load_voicefile_index(int fd) |
604 | { | 606 | { |
605 | if (fd < 0) /* failed to open */ | 607 | if (fd < 0) /* failed to open */ |
608 | { | ||
609 | talk_status = TALK_STATUS_ERR_NOFILE; | ||
606 | return false; | 610 | return false; |
611 | } | ||
607 | 612 | ||
608 | /* load the header first */ | 613 | /* load the header first */ |
609 | if (!load_header(fd, &voicefile)) | 614 | if (!load_header(fd, &voicefile)) |
615 | { | ||
616 | talk_status = TALK_STATUS_ERR_INCOMPATIBLE; | ||
610 | return false; | 617 | return false; |
618 | } | ||
611 | 619 | ||
612 | /* format check */ | 620 | /* format check */ |
613 | if (voicefile.table == sizeof(struct voicefile_header)) | 621 | if (voicefile.table == sizeof(struct voicefile_header)) |
@@ -622,6 +630,7 @@ static bool load_voicefile_index(int fd) | |||
622 | } | 630 | } |
623 | } | 631 | } |
624 | 632 | ||
633 | talk_status = TALK_STATUS_ERR_INCOMPATIBLE; | ||
625 | logf("Incompatible voice file"); | 634 | logf("Incompatible voice file"); |
626 | logf("version %d expected %d", voicefile.version, VOICE_VERSION); | 635 | logf("version %d expected %d", voicefile.version, VOICE_VERSION); |
627 | logf("target_id %d expected %d", voicefile.target_id, TARGET_ID); | 636 | logf("target_id %d expected %d", voicefile.target_id, TARGET_ID); |
@@ -648,6 +657,7 @@ static bool load_voicefile_data(int fd) | |||
648 | if (UNLIKELY(cap < 0)) | 657 | if (UNLIKELY(cap < 0)) |
649 | { | 658 | { |
650 | logf("Not enough memory for voice. Disabling...\n"); | 659 | logf("Not enough memory for voice. Disabling...\n"); |
660 | talk_status = TALK_STATUS_ERR_OOM; | ||
651 | return false; | 661 | return false; |
652 | } | 662 | } |
653 | else if (voicebuf_size > (size_t)cap) | 663 | else if (voicebuf_size > (size_t)cap) |
@@ -1629,17 +1639,25 @@ bool talk_get_debug_data(struct talk_debug_data *data) | |||
1629 | 1639 | ||
1630 | memset(data, 0, sizeof(*data)); | 1640 | memset(data, 0, sizeof(*data)); |
1631 | 1641 | ||
1632 | if (!has_voicefile || index_handle <= 0) | 1642 | data->status = talk_status; |
1633 | return false; | ||
1634 | 1643 | ||
1635 | if (global_settings.lang_file[0] && global_settings.lang_file[0] != 0xff) | 1644 | if (global_settings.lang_file[0] && global_settings.lang_file[0] != 0xff) |
1636 | p_lang = (char *)global_settings.lang_file; | 1645 | p_lang = (char *)global_settings.lang_file; |
1637 | 1646 | ||
1647 | strlcpy(data->voicefile, p_lang, sizeof(data->voicefile)); | ||
1648 | |||
1649 | if (!has_voicefile || index_handle <= 0) | ||
1650 | { | ||
1651 | if (data->status == TALK_STATUS_OK) | ||
1652 | data->status = TALK_STATUS_ERR_NOFILE; | ||
1653 | |||
1654 | return false; | ||
1655 | } | ||
1656 | |||
1638 | struct clip_entry *clips = core_get_data(index_handle); | 1657 | struct clip_entry *clips = core_get_data(index_handle); |
1639 | int cached = 0; | 1658 | int cached = 0; |
1640 | int real_clips = 0; | 1659 | int real_clips = 0; |
1641 | 1660 | ||
1642 | strlcpy(data->voicefile, p_lang, sizeof(data->voicefile)); | ||
1643 | data->num_clips = voicefile.id1_max + voicefile.id2_max; | 1661 | data->num_clips = voicefile.id1_max + voicefile.id2_max; |
1644 | data->avg_clipsize = data->max_clipsize = 0; | 1662 | data->avg_clipsize = data->max_clipsize = 0; |
1645 | data->min_clipsize = INT_MAX; | 1663 | data->min_clipsize = INT_MAX; |
diff --git a/apps/talk.h b/apps/talk.h index a643cd4f89..bfd8e496af 100644 --- a/apps/talk.h +++ b/apps/talk.h | |||
@@ -55,6 +55,15 @@ enum { | |||
55 | UNIT_LAST /* END MARKER */ | 55 | UNIT_LAST /* END MARKER */ |
56 | }; | 56 | }; |
57 | 57 | ||
58 | /* Status of loading talk file, shown in debug_menu */ | ||
59 | enum talk_status { | ||
60 | TALK_STATUS_OK = 0, | ||
61 | TALK_STATUS_ERR_OOM, | ||
62 | TALK_STATUS_ERR_ALLOC, | ||
63 | TALK_STATUS_ERR_NOFILE, | ||
64 | TALK_STATUS_ERR_INCOMPATIBLE | ||
65 | }; | ||
66 | |||
58 | #define UNIT_SHIFT (32-5) /* this many bits left from UNIT_xx enum */ | 67 | #define UNIT_SHIFT (32-5) /* this many bits left from UNIT_xx enum */ |
59 | 68 | ||
60 | #define DECIMAL_SHIFT (32 - 8) | 69 | #define DECIMAL_SHIFT (32 - 8) |
@@ -174,6 +183,7 @@ struct talk_debug_data { | |||
174 | int cached_clips; | 183 | int cached_clips; |
175 | int cache_hits; | 184 | int cache_hits; |
176 | int cache_misses; | 185 | int cache_misses; |
186 | enum talk_status status; | ||
177 | }; | 187 | }; |
178 | 188 | ||
179 | bool talk_get_debug_data(struct talk_debug_data *data); | 189 | bool talk_get_debug_data(struct talk_debug_data *data); |