Add stub STFM1000 tuner driver
[maemo-rb.git] / apps / talk.h
blob55e7208f1dc083a0f90193e0ab3d29045610b77e
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 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22 * KIND, either express or implied.
24 ****************************************************************************/
26 #ifndef __TALK_H__
27 #define __TALK_H__
29 #include <stdbool.h>
30 #include <inttypes.h>
31 #include "time.h"
33 #define VOICE_VERSION 400 /* 4.00 - if you change this, change it in voicefont too */
35 enum {
36 /* See array "unit_voiced" in talk.c function "talk_value" */
37 UNIT_INT = 1, /* plain number */
38 UNIT_SIGNED, /* number with mandatory sign (even if positive) */
39 UNIT_MS, /* milliseconds */
40 UNIT_SEC, /* seconds */
41 UNIT_MIN, /* minutes */
42 UNIT_HOUR, /* hours */
43 UNIT_KHZ, /* kHz */
44 UNIT_DB, /* dB, mandatory sign */
45 UNIT_PERCENT, /* % */
46 UNIT_MAH, /* milliAmp hours */
47 UNIT_PIXEL, /* pixels */
48 UNIT_PER_SEC, /* per second */
49 UNIT_HERTZ, /* hertz */
50 UNIT_MB, /* Megabytes */
51 UNIT_KBIT, /* kilobits per sec */
52 UNIT_PM_TICK, /* peak meter units per tick */
53 UNIT_TIME, /* time duration/interval in seconds, says hours,mins,secs */
54 UNIT_LAST /* END MARKER */
57 #define UNIT_SHIFT (32-5) /* this many bits left from UNIT_xx enum */
59 #define DECIMAL_SHIFT (32 - 8)
61 /* make a "talkable" ID from number + unit
62 unit is upper 4 bits, number the remaining (in regular 2's complement) */
63 #define TALK_ID(n,u) (((long)(u))<<UNIT_SHIFT | ((n) & ~(-1L<<UNIT_SHIFT)))
65 /* make a "talkable" ID from a decimal number + unit, the decimal number
66 is represented like x*10^d where d is the number of decimal digits */
67 #define TALK_ID_DECIMAL(n,d,u) (((long)(u))<<UNIT_SHIFT |\
68 ((long)(d))<<DECIMAL_SHIFT |\
69 ((n) & ~(-1L<<DECIMAL_SHIFT)))
71 /* convenience macro to have both virtual pointer and ID as arguments */
72 #define STR(id) ID2P(id), id
74 /* publish these strings, so they're stored only once (better than #define) */
75 extern const char* const dir_thumbnail_name; /* "_dirname.talk" */
76 extern const char* const file_thumbnail_ext; /* ".talk" for file voicing */
78 void talk_init(void);
79 #if CONFIG_CODEC == SWCODEC
80 bool talk_voice_required(void); /* returns true if voice codec required */
81 #endif
82 int talk_get_bufsize(void); /* get the loaded voice file size */
83 size_t talkbuf_init(char* bufstart);
84 void talk_buffer_steal(void); /* claim the mp3 buffer e.g. for play/record */
85 bool is_voice_queued(void); /* Are there more voice clips to be spoken? */
86 int talk_id(int32_t id, bool enqueue); /* play a voice ID from voicefont */
87 /* play a thumbnail from file */
88 int talk_file(const char *root, const char *dir, const char *file,
89 const char *ext, const long *prefix_ids, bool enqueue);
90 /* play file's thumbnail or spell name */
91 int talk_file_or_spell(const char *dirname, const char* filename,
92 const long *prefix_ids, bool enqueue);
93 #if CONFIG_CODEC == SWCODEC
94 /* play dir's thumbnail or spell name */
95 int talk_dir_or_spell(const char* filename,
96 const long *prefix_ids, bool enqueue);
97 #endif
98 int talk_number(long n, bool enqueue); /* say a number */
99 int talk_value(long n, int unit, bool enqueue); /* say a numeric value */
100 int talk_value_decimal(long n, int unit, int decimals, bool enqueue);
101 int talk_spell(const char* spell, bool enqueue); /* spell a string */
102 void talk_setting(const void *global_settings_variable); /* read a setting */
103 void talk_disable(bool disable); /* temporarily disable (or re-enable) talking (temporarily, not persisted) */
104 void talk_force_shutup(void); /* kill voice unconditionally */
105 void talk_shutup(void); /* Interrupt voice, as when enqueue is false */
107 /* helper function for speaking fractional numbers */
108 void talk_fractional(char *tbuf, int value, int unit);
110 #if CONFIG_RTC
111 void talk_time(const struct tm *tm, bool enqueue);
112 void talk_date(const struct tm *tm, bool enqueue);
113 #endif /* CONFIG_RTC */
115 /* This (otherwise invalid) ID signals the end of the array. */
116 #define TALK_FINAL_ID LANG_LAST_INDEX_IN_ARRAY
118 /* Enqueue next utterance even if enqueue parameter is false: don't
119 interrupt the current utterance. */
120 void talk_force_enqueue_next(void);
122 /* speaks one or more IDs (from an array)). */
123 int talk_idarray(const long *idarray, bool enqueue);
124 /* This makes an initializer for the array of IDs and takes care to
125 put the final sentinel element at the end. */
126 #define TALK_IDARRAY(ids...) ((long[]){ids,TALK_FINAL_ID})
127 /* And this handy macro makes it look like a variadic function. */
128 #define talk_ids(enqueue, ids...) talk_idarray(TALK_IDARRAY(ids), enqueue)
129 /* This version talks only if talking menus are enabled, and does not
130 enqueue the initial id. */
131 #define cond_talk_ids(ids...) do { \
132 if (global_settings.talk_menu) \
133 talk_ids(false, ids); \
134 } while(0)
135 /* And a version that takes the array parameter... */
136 #define cond_talk_idarray(idarray) do { \
137 if (global_settings.talk_menu \
138 talk_idarray(idarray, false); \
139 } while(0)
140 /* Convenience macro to conditionally speak something and not have
141 it interrupted. */
142 #define cond_talk_ids_fq(ids...) do { \
143 if (global_settings.talk_menu) { \
144 talk_ids(false, ids); \
145 talk_force_enqueue_next(); \
147 }while(0)
149 #endif /* __TALK_H__ */