1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2004 Jörg Hohensohn
12 * This module collects the Talkbox and voice UI functions.
13 * (Talkbox reads directory names from mp3 clips called thumbnails,
14 * the voice UI lets menus and screens "talk" from a voicefont in memory.
16 * All files in this archive are subject to the GNU General Public License.
17 * See the file COPYING in the source tree root for full license agreement.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
30 /* See array "unit_voiced" in talk.c function "talk_value" */
31 UNIT_INT
= 1, /* plain number */
32 UNIT_SIGNED
, /* number with mandatory sign (even if positive) */
33 UNIT_MS
, /* milliseconds */
34 UNIT_SEC
, /* seconds */
35 UNIT_MIN
, /* minutes */
36 UNIT_HOUR
, /* hours */
38 UNIT_DB
, /* dB, mandatory sign */
40 UNIT_MAH
, /* milliAmp hours */
41 UNIT_PIXEL
, /* pixels */
42 UNIT_PER_SEC
, /* per second */
43 UNIT_HERTZ
, /* hertz */
44 UNIT_MB
, /* Megabytes */
45 UNIT_KBIT
, /* kilobits per sec */
46 UNIT_PM_TICK
, /* peak meter units per tick */
47 UNIT_LAST
/* END MARKER */
50 #define UNIT_SHIFT (32-5) /* this many bits left from UNIT_xx enum */
52 /* make a "talkable" ID from number + unit
53 unit is upper 4 bits, number the remaining (in regular 2's complement) */
54 #define TALK_ID(n,u) (((long)(u))<<UNIT_SHIFT | ((n) & ~(-1L<<UNIT_SHIFT)))
56 /* convenience macro to have both virtual pointer and ID as arguments */
57 #define STR(id) ID2P(id), id
59 /* publish these strings, so they're stored only once (better than #define) */
60 extern const char* const dir_thumbnail_name
; /* "_dirname.talk" */
61 extern const char* const file_thumbnail_ext
; /* ".talk" for file voicing */
64 #if CONFIG_CODEC == SWCODEC
65 bool talk_voice_required(void); /* returns true if voice codec required */
67 int talk_get_bufsize(void); /* get the loaded voice file size */
68 /* talk_buffer_steal - on SWCODEC, for use by buffer functions only */
69 int talk_buffer_steal(void); /* claim the mp3 buffer e.g. for play/record */
70 bool is_voice_queued(void); /* Are there more voice clips to be spoken? */
71 int talk_id(long id
, bool enqueue
); /* play a voice ID from voicefont */
72 int talk_file(const char* filename
, bool enqueue
); /* play a thumbnail from file */
73 int talk_number(long n
, bool enqueue
); /* say a number */
74 int talk_value(long n
, int unit
, bool enqueue
); /* say a numeric value */
75 int talk_spell(const char* spell
, bool enqueue
); /* spell a string */
76 bool talk_menus_enabled(void); /* returns true if menus should be voiced */
77 void talk_disable_menus(void); /* disable voice menus (temporarily, not persisted) */
78 void talk_enable_menus(void); /* re-enable voice menus */
83 /* This (otherwise invalid) ID signals the end of the array. */
84 #define TALK_FINAL_ID LANG_LAST_INDEX_IN_ARRAY
86 /* We don't build talk.c for hwcodec sims so we need to define these as empty */
87 #if defined(SIMULATOR) && !(CONFIG_CODEC == SWCODEC)
88 #define talk_force_enqueue_next(...)
89 #define talk_idarray(...)
91 #define cond_talk_ids(...)
92 #define cond_talk_ids_fq(...)
95 /* Enqueue next utterance even if enqueue parameter is false: don't
96 interrupt the current utterance. */
97 void talk_force_enqueue_next(void);
99 /* speaks one or more IDs (from an array)). */
100 int talk_idarray(long *idarray
, bool enqueue
);
101 /* This makes an initializer for the array of IDs and takes care to
102 put the final sentinel element at the end. */
103 #define TALK_IDARRAY(ids...) ((long[]){ids,TALK_FINAL_ID})
104 /* And this handy macro makes it look like a variadic function. */
105 #define talk_ids(enqueue, ids...) talk_idarray(TALK_IDARRAY(ids), enqueue)
106 /* This version talks only if talking menus are enabled, and does not
107 enqueue the initial id. */
108 #define cond_talk_ids(ids...) do { \
109 if (talk_menus_enabled()) \
110 talk_ids(false, ids); \
112 /* And a version that takes the array parameter... */
113 #define cond_talk_idarray(idarray) do { \
114 if (talk_menus_enabled() \
115 talk_idarray(idarray, false); \
117 /* Convenience macro to conditionally speak something and not have
119 #define cond_talk_ids_fq(ids...) do { \
120 if (talk_menus_enabled()) { \
121 talk_ids(false, ids); \
122 talk_force_enqueue_next(); \
125 #endif /*defined(SIMULATOR) && !(CONFIG_CODEC == SWCODEC)*/
126 #endif /* __TALK_H__ */