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 ****************************************************************************/
31 #define VOICE_VERSION 400 /* 4.00 - if you change this, change it in voicefont too */
34 /* See array "unit_voiced" in talk.c function "talk_value" */
35 UNIT_INT
= 1, /* plain number */
36 UNIT_SIGNED
, /* number with mandatory sign (even if positive) */
37 UNIT_MS
, /* milliseconds */
38 UNIT_SEC
, /* seconds */
39 UNIT_MIN
, /* minutes */
40 UNIT_HOUR
, /* hours */
42 UNIT_DB
, /* dB, mandatory sign */
44 UNIT_MAH
, /* milliAmp hours */
45 UNIT_PIXEL
, /* pixels */
46 UNIT_PER_SEC
, /* per second */
47 UNIT_HERTZ
, /* hertz */
48 UNIT_MB
, /* Megabytes */
49 UNIT_KBIT
, /* kilobits per sec */
50 UNIT_PM_TICK
, /* peak meter units per tick */
51 UNIT_TIME_EXACT
,/* time duration/interval in seconds, says hours,mins,secs*/
52 UNIT_TIME
, /* as above but less verbose */
53 UNIT_LAST
/* END MARKER */
56 #define UNIT_SHIFT (32-5) /* this many bits left from UNIT_xx enum */
58 #define DECIMAL_SHIFT (32 - 8)
60 /* make a "talkable" ID from number + unit
61 unit is upper 4 bits, number the remaining (in regular 2's complement) */
62 #define TALK_ID(n,u) (((long)(u))<<UNIT_SHIFT | ((n) & ~(-1L<<UNIT_SHIFT)))
64 /* make a "talkable" ID from a decimal number + unit, the decimal number
65 is represented like x*10^d where d is the number of decimal digits */
66 #define TALK_ID_DECIMAL(n,d,u) (((long)(u))<<UNIT_SHIFT |\
67 ((long)(d))<<DECIMAL_SHIFT |\
68 ((n) & ~(-1L<<DECIMAL_SHIFT)))
70 /* convenience macro to have both virtual pointer and ID as arguments */
71 #define STR(id) ID2P(id), id
73 /* publish these strings, so they're stored only once (better than #define) */
74 extern const char* const dir_thumbnail_name
; /* "_dirname.talk" */
75 extern const char* const file_thumbnail_ext
; /* ".talk" for file voicing */
78 #if CONFIG_CODEC == SWCODEC
79 bool talk_voice_required(void); /* returns true if voice codec required */
81 int talk_get_bufsize(void); /* get the loaded voice file size */
82 void talk_buffer_steal(void); /* claim the mp3 buffer e.g. for play/record */
83 bool is_voice_queued(void); /* Are there more voice clips to be spoken? */
84 int talk_id(int32_t id
, bool enqueue
); /* play a voice ID from voicefont */
85 int talk_file(const char* filename
, bool enqueue
); /* play a thumbnail from file */
86 int talk_number(long n
, bool enqueue
); /* say a number */
87 int talk_value(long n
, int unit
, bool enqueue
); /* say a numeric value */
88 int talk_value_decimal(long n
, int unit
, int decimals
, bool enqueue
);
89 int talk_spell(const char* spell
, bool enqueue
); /* spell a string */
90 void talk_setting(const void *global_settings_variable
); /* read a setting */
91 void talk_disable(bool disable
); /* temporarily disable (or re-enable) talking (temporarily, not persisted) */
92 void talk_force_shutup(void); /* kill voice unconditionally */
93 void talk_shutup(void); /* Interrupt voice, as when enqueue is false */
95 /* helper function for speaking fractional numbers */
96 void talk_fractional(char *tbuf
, int value
, int unit
);
99 void talk_time(struct tm
*tm
, bool enqueue
);
100 void talk_date(struct tm
*tm
, bool enqueue
);
101 #endif /* CONFIG_RTC */
103 /* This (otherwise invalid) ID signals the end of the array. */
104 #define TALK_FINAL_ID LANG_LAST_INDEX_IN_ARRAY
106 /* Enqueue next utterance even if enqueue parameter is false: don't
107 interrupt the current utterance. */
108 void talk_force_enqueue_next(void);
110 /* speaks one or more IDs (from an array)). */
111 int talk_idarray(long *idarray
, bool enqueue
);
112 /* This makes an initializer for the array of IDs and takes care to
113 put the final sentinel element at the end. */
114 #define TALK_IDARRAY(ids...) ((long[]){ids,TALK_FINAL_ID})
115 /* And this handy macro makes it look like a variadic function. */
116 #define talk_ids(enqueue, ids...) talk_idarray(TALK_IDARRAY(ids), enqueue)
117 /* This version talks only if talking menus are enabled, and does not
118 enqueue the initial id. */
119 #define cond_talk_ids(ids...) do { \
120 if (global_settings.talk_menu) \
121 talk_ids(false, ids); \
123 /* And a version that takes the array parameter... */
124 #define cond_talk_idarray(idarray) do { \
125 if (global_settings.talk_menu \
126 talk_idarray(idarray, false); \
128 /* Convenience macro to conditionally speak something and not have
130 #define cond_talk_ids_fq(ids...) do { \
131 if (global_settings.talk_menu) { \
132 talk_ids(false, ids); \
133 talk_force_enqueue_next(); \
137 #endif /* __TALK_H__ */