Fixes a problem where the sim would try to start the WPS on HAVE_RTC_ALARM sims ...
[Rockbox.git] / apps / talk.h
blobe25a11c70242c98fb1dc9a485601f8041e8a0138
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
24 #ifndef __TALK_H__
25 #define __TALK_H__
27 #include <stdbool.h>
28 #include "time.h"
30 enum {
31 /* See array "unit_voiced" in talk.c function "talk_value" */
32 UNIT_INT = 1, /* plain number */
33 UNIT_SIGNED, /* number with mandatory sign (even if positive) */
34 UNIT_MS, /* milliseconds */
35 UNIT_SEC, /* seconds */
36 UNIT_MIN, /* minutes */
37 UNIT_HOUR, /* hours */
38 UNIT_KHZ, /* kHz */
39 UNIT_DB, /* dB, mandatory sign */
40 UNIT_PERCENT, /* % */
41 UNIT_MAH, /* milliAmp hours */
42 UNIT_PIXEL, /* pixels */
43 UNIT_PER_SEC, /* per second */
44 UNIT_HERTZ, /* hertz */
45 UNIT_MB, /* Megabytes */
46 UNIT_KBIT, /* kilobits per sec */
47 UNIT_PM_TICK, /* peak meter units per tick */
48 UNIT_LAST /* END MARKER */
51 #define UNIT_SHIFT (32-5) /* this many bits left from UNIT_xx enum */
53 /* make a "talkable" ID from number + unit
54 unit is upper 4 bits, number the remaining (in regular 2's complement) */
55 #define TALK_ID(n,u) (((long)(u))<<UNIT_SHIFT | ((n) & ~(-1L<<UNIT_SHIFT)))
57 /* convenience macro to have both virtual pointer and ID as arguments */
58 #define STR(id) ID2P(id), id
60 /* publish these strings, so they're stored only once (better than #define) */
61 extern const char* const dir_thumbnail_name; /* "_dirname.talk" */
62 extern const char* const file_thumbnail_ext; /* ".talk" for file voicing */
64 void talk_init(void);
65 #if CONFIG_CODEC == SWCODEC
66 bool talk_voice_required(void); /* returns true if voice codec required */
67 #endif
68 int talk_get_bufsize(void); /* get the loaded voice file size */
69 /* talk_buffer_steal - on SWCODEC, for use by buffer functions only */
70 int talk_buffer_steal(void); /* claim the mp3 buffer e.g. for play/record */
71 bool is_voice_queued(void); /* Are there more voice clips to be spoken? */
72 int talk_id(long id, bool enqueue); /* play a voice ID from voicefont */
73 int talk_file(const char* filename, bool enqueue); /* play a thumbnail from file */
74 int talk_number(long n, bool enqueue); /* say a number */
75 int talk_value(long n, int unit, bool enqueue); /* say a numeric value */
76 int talk_spell(const char* spell, bool enqueue); /* spell a string */
77 bool talk_menus_enabled(void); /* returns true if menus should be voiced */
78 void talk_disable_menus(void); /* disable voice menus (temporarily, not persisted) */
79 void talk_enable_menus(void); /* re-enable voice menus */
80 int do_shutup(void); /* kill voice unconditionally */
81 int shutup(void); /* Interrupt voice, as when enqueue is false */
83 #if CONFIG_RTC
84 /* this is in talk.c which isnt compiled for hwcodec simulator */
85 #if !defined(SIMULATOR) || CONFIG_CODEC == SWCODEC
86 void talk_date_time(struct tm *time, bool speak_current_time_string);
87 #else
88 #define talk_date_time(t, s)
89 #endif
90 #endif /* CONFIG_RTC */
92 /* This (otherwise invalid) ID signals the end of the array. */
93 #define TALK_FINAL_ID LANG_LAST_INDEX_IN_ARRAY
95 /* We don't build talk.c for hwcodec sims so we need to define these as empty */
96 #if defined(SIMULATOR) && !(CONFIG_CODEC == SWCODEC)
97 #define talk_force_enqueue_next(...)
98 #define talk_idarray(...)
99 #define talk_ids(...)
100 #define cond_talk_ids(...)
101 #define cond_talk_ids_fq(...)
102 #define shutup(...)
103 #else
105 /* Enqueue next utterance even if enqueue parameter is false: don't
106 interrupt the current utterance. */
107 void talk_force_enqueue_next(void);
109 /* speaks one or more IDs (from an array)). */
110 int talk_idarray(long *idarray, bool enqueue);
111 /* This makes an initializer for the array of IDs and takes care to
112 put the final sentinel element at the end. */
113 #define TALK_IDARRAY(ids...) ((long[]){ids,TALK_FINAL_ID})
114 /* And this handy macro makes it look like a variadic function. */
115 #define talk_ids(enqueue, ids...) talk_idarray(TALK_IDARRAY(ids), enqueue)
116 /* This version talks only if talking menus are enabled, and does not
117 enqueue the initial id. */
118 #define cond_talk_ids(ids...) do { \
119 if (talk_menus_enabled()) \
120 talk_ids(false, ids); \
121 } while(0)
122 /* And a version that takes the array parameter... */
123 #define cond_talk_idarray(idarray) do { \
124 if (talk_menus_enabled() \
125 talk_idarray(idarray, false); \
126 } while(0)
127 /* Convenience macro to conditionally speak something and not have
128 it interrupted. */
129 #define cond_talk_ids_fq(ids...) do { \
130 if (talk_menus_enabled()) { \
131 talk_ids(false, ids); \
132 talk_force_enqueue_next(); \
134 }while(0)
135 #endif /*defined(SIMULATOR) && !(CONFIG_CODEC == SWCODEC)*/
136 #endif /* __TALK_H__ */