blob: e73164486d13ea326c0983819032bb8bd86adc63 [file] [log] [blame]
Jörg Hohensohnfa97f162004-03-19 22:15:53 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
Nicolas Pennequin357ffb32008-05-05 10:32:46 +000010 * Copyright (C) 2004 Jörg Hohensohn
Jörg Hohensohnfa97f162004-03-19 22:15:53 +000011 *
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.
15 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000016 * 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.
Jörg Hohensohnfa97f162004-03-19 22:15:53 +000020 *
21 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22 * KIND, either express or implied.
23 *
24 ****************************************************************************/
25
26#ifndef __TALK_H__
27#define __TALK_H__
28
29#include <stdbool.h>
Nils Wallméniusacbd7802007-11-20 19:50:52 +000030#include <inttypes.h>
Jonathan Gordond7d6b782007-10-07 08:12:01 +000031#include "time.h"
Jörg Hohensohnfa97f162004-03-19 22:15:53 +000032
Michael Sevakis99617d72007-11-18 17:12:19 +000033#define VOICE_VERSION 400 /* 4.00 - if you change this, change it in voicefont too */
Nils Wallméniusf8017142007-11-15 19:32:15 +000034
Jörg Hohensohnfa97f162004-03-19 22:15:53 +000035enum {
Michael Sevakis287deb02006-09-26 17:44:43 +000036 /* See array "unit_voiced" in talk.c function "talk_value" */
Jörg Hohensohnfa97f162004-03-19 22:15:53 +000037 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, /* % */
Jörg Hohensohnbeec2e92004-03-20 16:49:58 +000046 UNIT_MAH, /* milliAmp hours */
47 UNIT_PIXEL, /* pixels */
48 UNIT_PER_SEC, /* per second */
49 UNIT_HERTZ, /* hertz */
Martin Scarratt9130a2a2006-07-22 17:23:05 +000050 UNIT_MB, /* Megabytes */
Michael Sevakis4fc717a2006-08-28 22:38:41 +000051 UNIT_KBIT, /* kilobits per sec */
Peter D'Hoyeebcf06d2007-08-18 23:03:03 +000052 UNIT_PM_TICK, /* peak meter units per tick */
Stéphane Doyon8b8785b2007-11-03 03:43:12 +000053 UNIT_TIME_EXACT,/* time duration/interval in seconds, says hours,mins,secs*/
54 UNIT_TIME, /* as above but less verbose */
Jörg Hohensohnfa97f162004-03-19 22:15:53 +000055 UNIT_LAST /* END MARKER */
56};
57
Michael Sevakis287deb02006-09-26 17:44:43 +000058#define UNIT_SHIFT (32-5) /* this many bits left from UNIT_xx enum */
Jörg Hohensohnfa97f162004-03-19 22:15:53 +000059
Nils Wallménius05d2bfd2008-04-19 13:19:04 +000060#define DECIMAL_SHIFT (32 - 8)
61
Jörg Hohensohnfa97f162004-03-19 22:15:53 +000062/* make a "talkable" ID from number + unit
63 unit is upper 4 bits, number the remaining (in regular 2's complement) */
Jean-Philippe Bernardy45e0de32005-02-12 11:26:36 +000064#define TALK_ID(n,u) (((long)(u))<<UNIT_SHIFT | ((n) & ~(-1L<<UNIT_SHIFT)))
Jörg Hohensohnfa97f162004-03-19 22:15:53 +000065
Nils Wallménius05d2bfd2008-04-19 13:19:04 +000066/* make a "talkable" ID from a decimal number + unit, the decimal number
Nils Wallménius2521bf52008-04-20 11:02:42 +000067 is represented like x*10^d where d is the number of decimal digits */
Nils Wallménius05d2bfd2008-04-19 13:19:04 +000068#define TALK_ID_DECIMAL(n,d,u) (((long)(u))<<UNIT_SHIFT |\
69 ((long)(d))<<DECIMAL_SHIFT |\
70 ((n) & ~(-1L<<DECIMAL_SHIFT)))
71
Jörg Hohensohnb1403ee2004-07-23 23:01:20 +000072/* convenience macro to have both virtual pointer and ID as arguments */
73#define STR(id) ID2P(id), id
Jörg Hohensohnfa97f162004-03-19 22:15:53 +000074
Jörg Hohensohn40ae63b2004-10-21 18:34:48 +000075/* publish these strings, so they're stored only once (better than #define) */
Jörg Hohensohnd4844202004-10-06 21:37:46 +000076extern const char* const dir_thumbnail_name; /* "_dirname.talk" */
Jörg Hohensohn40ae63b2004-10-21 18:34:48 +000077extern const char* const file_thumbnail_ext; /* ".talk" for file voicing */
Jörg Hohensohnfa97f162004-03-19 22:15:53 +000078
79void talk_init(void);
Jens Arnold2597a132006-12-25 14:01:47 +000080#if CONFIG_CODEC == SWCODEC
Linus Nielsen Feltzing42f0ad32006-08-15 18:01:42 +000081bool talk_voice_required(void); /* returns true if voice codec required */
Jens Arnold2597a132006-12-25 14:01:47 +000082#endif
Miika Pekkarinen159c52d2005-08-20 11:13:19 +000083int talk_get_bufsize(void); /* get the loaded voice file size */
Steve Bavin32a95752007-10-19 15:31:42 +000084void talk_buffer_steal(void); /* claim the mp3 buffer e.g. for play/record */
Nils Wallménius5b769362007-08-06 13:08:36 +000085bool is_voice_queued(void); /* Are there more voice clips to be spoken? */
Nils Wallméniusacbd7802007-11-20 19:50:52 +000086int talk_id(int32_t id, bool enqueue); /* play a voice ID from voicefont */
Jens Arnold8fb33612004-08-18 01:09:31 +000087int talk_file(const char* filename, bool enqueue); /* play a thumbnail from file */
Jean-Philippe Bernardy45e0de32005-02-12 11:26:36 +000088int talk_number(long n, bool enqueue); /* say a number */
89int talk_value(long n, int unit, bool enqueue); /* say a numeric value */
Nils Wallménius05d2bfd2008-04-19 13:19:04 +000090int talk_value_decimal(long n, int unit, int decimals, bool enqueue);
Jens Arnold8fb33612004-08-18 01:09:31 +000091int talk_spell(const char* spell, bool enqueue); /* spell a string */
Steve Bavincd88e2a2008-03-25 15:24:03 +000092void talk_setting(const void *global_settings_variable); /* read a setting */
Steve Bavin32a95752007-10-19 15:31:42 +000093void talk_disable(bool disable); /* temporarily disable (or re-enable) talking (temporarily, not persisted) */
94void talk_force_shutup(void); /* kill voice unconditionally */
95void talk_shutup(void); /* Interrupt voice, as when enqueue is false */
Nils Wallménius1ff0c352007-08-06 15:01:45 +000096
Nils Wallménius2521bf52008-04-20 11:02:42 +000097/* helper function for speaking fractional numbers */
98void talk_fractional(char *tbuf, int value, int unit);
99
Jonathan Gordond7d6b782007-10-07 08:12:01 +0000100#if CONFIG_RTC
Steve Bavin072a3c52007-10-24 12:32:12 +0000101void talk_time(struct tm *tm, bool enqueue);
102void talk_date(struct tm *tm, bool enqueue);
Jonathan Gordond7d6b782007-10-07 08:12:01 +0000103#endif /* CONFIG_RTC */
104
Nils Wallménius1ff0c352007-08-06 15:01:45 +0000105/* This (otherwise invalid) ID signals the end of the array. */
106#define TALK_FINAL_ID LANG_LAST_INDEX_IN_ARRAY
107
Nils Wallménius5b769362007-08-06 13:08:36 +0000108/* Enqueue next utterance even if enqueue parameter is false: don't
109 interrupt the current utterance. */
110void talk_force_enqueue_next(void);
111
112/* speaks one or more IDs (from an array)). */
113int talk_idarray(long *idarray, bool enqueue);
Nils Wallménius5b769362007-08-06 13:08:36 +0000114/* This makes an initializer for the array of IDs and takes care to
115 put the final sentinel element at the end. */
116#define TALK_IDARRAY(ids...) ((long[]){ids,TALK_FINAL_ID})
117/* And this handy macro makes it look like a variadic function. */
118#define talk_ids(enqueue, ids...) talk_idarray(TALK_IDARRAY(ids), enqueue)
119/* This version talks only if talking menus are enabled, and does not
120 enqueue the initial id. */
121#define cond_talk_ids(ids...) do { \
Steve Bavin32a95752007-10-19 15:31:42 +0000122 if (global_settings.talk_menu) \
Nils Wallménius5b769362007-08-06 13:08:36 +0000123 talk_ids(false, ids); \
124 } while(0)
125/* And a version that takes the array parameter... */
126#define cond_talk_idarray(idarray) do { \
Steve Bavin32a95752007-10-19 15:31:42 +0000127 if (global_settings.talk_menu \
Nils Wallménius5b769362007-08-06 13:08:36 +0000128 talk_idarray(idarray, false); \
129 } while(0)
130/* Convenience macro to conditionally speak something and not have
131 it interrupted. */
132#define cond_talk_ids_fq(ids...) do { \
Steve Bavin32a95752007-10-19 15:31:42 +0000133 if (global_settings.talk_menu) { \
Nils Wallménius5b769362007-08-06 13:08:36 +0000134 talk_ids(false, ids); \
135 talk_force_enqueue_next(); \
136 } \
137 }while(0)
Jonathan Gordonc14430a2007-11-07 09:28:07 +0000138
Jörg Hohensohnfa97f162004-03-19 22:15:53 +0000139#endif /* __TALK_H__ */