Add platform file for Ipod 1G / 2G. Now only the front image is missing for building...
[Rockbox.git] / apps / talk.c
blob1610fa95ec9e23a21fa80b16d0b6d5fd2a464c45
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 voicefile 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 #include <stdio.h>
25 #include <stddef.h>
26 #include <string.h>
27 #include "file.h"
28 #include "buffer.h"
29 #include "system.h"
30 #include "kernel.h"
31 #include "settings.h"
32 #include "mp3_playback.h"
33 #include "audio.h"
34 #include "lang.h"
35 #include "talk.h"
36 #include "id3.h"
37 #include "logf.h"
38 #include "bitswap.h"
39 #include "structec.h"
40 #if CONFIG_CODEC == SWCODEC
41 #include "playback.h"
42 #endif
43 #include "debug.h"
46 /* Memory layout varies between targets because the
47 Archos (MASCODEC) devices cannot mix voice and audio playback
49 MASCODEC | MASCODEC | SWCODEC
50 (playing) | (stopped) |
51 audiobuf-----------+-----------+------------
52 audio | voice | thumbnail
53 |-----------|------------
54 | thumbnail | voice
55 | |------------
56 | | filebuf
57 | |------------
58 | | audio
59 | |------------
60 | | codec swap
61 audiobufend----------+-----------+------------
63 SWCODEC allocates dedicated buffers, MASCODEC reuses audiobuf. */
66 /***************** Constants *****************/
68 #define QUEUE_SIZE 64 /* must be a power of two */
69 #define QUEUE_MASK (QUEUE_SIZE-1)
70 const char* const dir_thumbnail_name = "_dirname.talk";
71 const char* const file_thumbnail_ext = ".talk";
73 /***************** Functional Macros *****************/
75 #define QUEUE_LEVEL ((queue_write - queue_read) & QUEUE_MASK)
77 #define LOADED_MASK 0x80000000 /* MSB */
79 #if CONFIG_CODEC == SWCODEC
80 #define MAX_THUMBNAIL_BUFSIZE 32768
81 #endif
83 #ifndef SIMULATOR
84 extern bool audio_is_initialized;
85 #endif
87 /***************** Data types *****************/
89 struct clip_entry /* one entry of the index table */
91 int offset; /* offset from start of voicefile file */
92 int size; /* size of the clip */
95 struct voicefile /* file format of our voice file */
97 int version; /* version of the voicefile */
98 int table; /* offset to index table, (=header size) */
99 int id1_max; /* number of "normal" clips contained in above index */
100 int id2_max; /* number of "voice only" clips contained in above index */
101 struct clip_entry index[]; /* followed by the index tables */
102 /* and finally the bitswapped mp3 clips, not visible here */
105 struct queue_entry /* one entry of the internal queue */
107 unsigned char* buf;
108 long len;
112 /***************** Globals *****************/
114 static unsigned char* p_thumbnail = NULL; /* buffer for thumbnail */
115 static long size_for_thumbnail; /* leftover buffer size for it */
116 static struct voicefile* p_voicefile; /* loaded voicefile */
117 static bool has_voicefile; /* a voicefile file is present */
118 static struct queue_entry queue[QUEUE_SIZE]; /* queue of scheduled clips */
119 static int queue_write; /* write index of queue, by application */
120 static int queue_read; /* read index of queue, by ISR context */
121 static int sent; /* how many bytes handed over to playback, owned by ISR */
122 static unsigned char curr_hd[3]; /* current frame header, for re-sync */
123 static int filehandle = -1; /* global, so the MMC variant can keep the file open */
124 static unsigned char* p_silence; /* VOICE_PAUSE clip, used for termination */
125 static long silence_len; /* length of the VOICE_PAUSE clip */
126 static unsigned char* p_lastclip; /* address of latest clip, for silence add */
127 static unsigned long voicefile_size = 0; /* size of the loaded voice file */
128 static unsigned char last_lang[MAX_FILENAME+1]; /* name of last used lang file (in talk_init) */
129 static bool talk_initialized; /* true if talk_init has been called */
130 static int talk_menu_disable; /* if non-zero, temporarily disable voice UI (not saved) */
132 /***************** Private prototypes *****************/
134 static void load_voicefile(void);
135 static void mp3_callback(unsigned char** start, size_t* size);
136 static int shutup(void);
137 static int queue_clip(unsigned char* buf, long size, bool enqueue);
138 static int open_voicefile(void);
139 static unsigned char* get_clip(long id, long* p_size);
142 /***************** Private implementation *****************/
144 static int open_voicefile(void)
146 char buf[64];
147 char* p_lang = "english"; /* default */
149 if ( global_settings.lang_file[0] &&
150 global_settings.lang_file[0] != 0xff )
151 { /* try to open the voice file of the selected language */
152 p_lang = (char *)global_settings.lang_file;
155 snprintf(buf, sizeof(buf), LANG_DIR "/%s.voice", p_lang);
157 return open(buf, O_RDONLY);
161 /* load the voice file into the mp3 buffer */
162 static void load_voicefile(void)
164 int load_size;
165 int got_size;
166 int file_size;
167 #if CONFIG_CODEC == SWCODEC
168 int length, i;
169 unsigned char *buf, temp;
170 #endif
172 filehandle = open_voicefile();
173 if (filehandle < 0) /* failed to open */
174 goto load_err;
176 file_size = filesize(filehandle);
177 if (file_size > audiobufend - audiobuf) /* won't fit? */
178 goto load_err;
180 #ifdef HAVE_MMC /* load only the header for now */
181 load_size = offsetof(struct voicefile, index);
182 #else /* load the full file */
183 load_size = file_size;
184 #endif
186 got_size = read(filehandle, audiobuf, load_size);
187 if (got_size != load_size /* failure */)
188 goto load_err;
190 #ifdef ROCKBOX_LITTLE_ENDIAN
191 logf("Byte swapping voice file");
192 structec_convert(audiobuf, "llll", 1, true);
193 #endif
195 if (((struct voicefile*)audiobuf)->table /* format check */
196 == offsetof(struct voicefile, index))
198 p_voicefile = (struct voicefile*)audiobuf;
200 #if CONFIG_CODEC != SWCODEC
201 /* MASCODEC: now use audiobuf for voice then thumbnail */
202 p_thumbnail = audiobuf + file_size;
203 p_thumbnail += (long)p_thumbnail % 2; /* 16-bit align */
204 size_for_thumbnail = audiobufend - p_thumbnail;
205 #endif
207 else
208 goto load_err;
210 #ifdef ROCKBOX_LITTLE_ENDIAN
211 for (i = 0; i < p_voicefile->id1_max + p_voicefile->id2_max; i++)
212 structec_convert(&p_voicefile->index[i], "ll", 1, true);
213 #endif
215 /* Do a bitswap as necessary. */
216 #if CONFIG_CODEC == SWCODEC
217 logf("Bitswapping voice file.");
218 cpu_boost(true);
219 buf = (unsigned char *)(&p_voicefile->index) +
220 (p_voicefile->id1_max + p_voicefile->id2_max) * sizeof(struct clip_entry);
221 length = file_size - (buf - (unsigned char *) p_voicefile);
223 for (i = 0; i < length; i++)
225 temp = buf[i];
226 temp = ((temp >> 4) & 0x0f) | ((temp & 0x0f) << 4);
227 temp = ((temp >> 2) & 0x33) | ((temp & 0x33) << 2);
228 buf[i] = ((temp >> 1) & 0x55) | ((temp & 0x55) << 1);
230 cpu_boost(false);
232 #endif
234 #ifdef HAVE_MMC
235 /* load the index table, now that we know its size from the header */
236 load_size = (p_voicefile->id1_max + p_voicefile->id2_max)
237 * sizeof(struct clip_entry);
238 got_size = read(filehandle,
239 (unsigned char *) p_voicefile + offsetof(struct voicefile, index), load_size);
240 if (got_size != load_size) /* read error */
241 goto load_err;
242 #else
243 close(filehandle); /* only the MMC variant leaves it open */
244 filehandle = -1;
245 #endif
247 /* make sure to have the silence clip, if available */
248 p_silence = get_clip(VOICE_PAUSE, &silence_len);
250 return;
252 load_err:
253 p_voicefile = NULL;
254 has_voicefile = false; /* don't try again */
255 if (filehandle >= 0)
257 close(filehandle);
258 filehandle = -1;
260 return;
264 /* called in ISR context if mp3 data got consumed */
265 static void mp3_callback(unsigned char** start, size_t* size)
267 queue[queue_read].len -= sent; /* we completed this */
268 queue[queue_read].buf += sent;
270 if (queue[queue_read].len > 0) /* current clip not finished? */
271 { /* feed the next 64K-1 chunk */
272 #if CONFIG_CODEC != SWCODEC
273 sent = MIN(queue[queue_read].len, 0xFFFF);
274 #else
275 sent = queue[queue_read].len;
276 #endif
277 *start = queue[queue_read].buf;
278 *size = sent;
279 return;
281 else if (sent > 0) /* go to next entry */
283 queue_read = (queue_read + 1) & QUEUE_MASK;
286 re_check:
288 if (QUEUE_LEVEL) /* queue is not empty? */
289 { /* start next clip */
290 #if CONFIG_CODEC != SWCODEC
291 sent = MIN(queue[queue_read].len, 0xFFFF);
292 #else
293 sent = queue[queue_read].len;
294 #endif
295 *start = p_lastclip = queue[queue_read].buf;
296 *size = sent;
297 curr_hd[0] = p_lastclip[1];
298 curr_hd[1] = p_lastclip[2];
299 curr_hd[2] = p_lastclip[3];
301 else if (p_silence != NULL /* silence clip available */
302 && p_lastclip != p_silence /* previous clip wasn't silence */
303 && p_lastclip != p_thumbnail) /* ..or thumbnail */
304 { /* add silence clip when queue runs empty playing a voice clip */
305 queue[queue_write].buf = p_silence;
306 queue[queue_write].len = silence_len;
307 queue_write = (queue_write + 1) & QUEUE_MASK;
309 goto re_check;
311 else
313 *size = 0; /* end of data */
317 /* stop the playback and the pending clips */
318 static int shutup(void)
320 #if CONFIG_CODEC != SWCODEC
321 unsigned char* pos;
322 unsigned char* search;
323 unsigned char* end;
324 #endif
326 if (QUEUE_LEVEL == 0) /* has ended anyway */
328 #if CONFIG_CODEC == SWCODEC
329 mp3_play_stop();
330 #endif
331 return 0;
333 #if CONFIG_CODEC != SWCODEC
334 #if CONFIG_CPU == SH7034
335 CHCR3 &= ~0x0001; /* disable the DMA (and therefore the interrupt also) */
336 #endif
337 /* search next frame boundary and continue up to there */
338 pos = search = mp3_get_pos();
339 end = queue[queue_read].buf + queue[queue_read].len;
341 if (pos >= queue[queue_read].buf
342 && pos <= end) /* really our clip? */
343 { /* (for strange reasons this isn't nesessarily the case) */
344 /* find the next frame boundary */
345 while (search < end) /* search the remaining data */
347 if (*search++ != 0xFF) /* quick search for frame sync byte */
348 continue; /* (this does the majority of the job) */
350 /* look at the (bitswapped) rest of header candidate */
351 if (search[0] == curr_hd[0] /* do the quicker checks first */
352 && search[2] == curr_hd[2]
353 && (search[1] & 0x30) == (curr_hd[1] & 0x30)) /* sample rate */
355 search--; /* back to the sync byte */
356 break; /* From looking at it, this is our header. */
360 if (search-pos)
361 { /* play old data until the frame end, to keep the MAS in sync */
362 sent = search-pos;
364 queue_write = (queue_read + 1) & QUEUE_MASK; /* will be empty after next callback */
365 queue[queue_read].len = sent; /* current one ends after this */
367 #if CONFIG_CPU == SH7034
368 DTCR3 = sent; /* let the DMA finish this frame */
369 CHCR3 |= 0x0001; /* re-enable DMA */
370 #endif
371 return 0;
374 #endif
376 /* nothing to do, was frame boundary or not our clip */
377 mp3_play_stop();
379 queue_write = queue_read = 0; /* reset the queue */
381 return 0;
385 /* schedule a clip, at the end or discard the existing queue */
386 static int queue_clip(unsigned char* buf, long size, bool enqueue)
388 int queue_level;
390 if (!enqueue)
391 shutup(); /* cut off all the pending stuff */
393 if (!size)
394 return 0; /* safety check */
395 #if CONFIG_CPU == SH7034
396 /* disable the DMA temporarily, to be safe of race condition */
397 CHCR3 &= ~0x0001;
398 #endif
399 queue_level = QUEUE_LEVEL; /* check old level */
401 if (queue_level < QUEUE_SIZE - 1) /* space left? */
403 queue[queue_write].buf = buf; /* populate an entry */
404 queue[queue_write].len = size;
405 queue_write = (queue_write + 1) & QUEUE_MASK;
408 if (queue_level == 0)
409 { /* queue was empty, we have to do the initial start */
410 p_lastclip = buf;
411 #if CONFIG_CODEC != SWCODEC
412 sent = MIN(size, 0xFFFF); /* DMA can do no more */
413 #else
414 sent = size;
415 #endif
416 mp3_play_data(buf, sent, mp3_callback);
417 curr_hd[0] = buf[1];
418 curr_hd[1] = buf[2];
419 curr_hd[2] = buf[3];
420 mp3_play_pause(true); /* kickoff audio */
422 else
424 #if CONFIG_CPU == SH7034
425 CHCR3 |= 0x0001; /* re-enable DMA */
426 #endif
429 return 0;
432 /* fetch a clip from the voice file */
433 static unsigned char* get_clip(long id, long* p_size)
435 long clipsize;
436 unsigned char* clipbuf;
438 if (id > VOICEONLY_DELIMITER)
439 { /* voice-only entries use the second part of the table */
440 id -= VOICEONLY_DELIMITER + 1;
441 if (id >= p_voicefile->id2_max)
442 return NULL; /* must be newer than we have */
443 id += p_voicefile->id1_max; /* table 2 is behind table 1 */
445 else
446 { /* normal use of the first table */
447 if (id >= p_voicefile->id1_max)
448 return NULL; /* must be newer than we have */
451 clipsize = p_voicefile->index[id].size;
452 if (clipsize == 0) /* clip not included in voicefile */
453 return NULL;
454 clipbuf = (unsigned char *) p_voicefile + p_voicefile->index[id].offset;
456 #ifdef HAVE_MMC /* dynamic loading, on demand */
457 if (!(clipsize & LOADED_MASK))
458 { /* clip used for the first time, needs loading */
459 lseek(filehandle, p_voicefile->index[id].offset, SEEK_SET);
460 if (read(filehandle, clipbuf, clipsize) != clipsize)
461 return NULL; /* read error */
463 p_voicefile->index[id].size |= LOADED_MASK; /* mark as loaded */
465 else
466 { /* clip is in memory already */
467 clipsize &= ~LOADED_MASK; /* without the extra bit gives true size */
469 #endif
471 *p_size = clipsize;
472 return clipbuf;
476 /* common code for talk_init() and talk_buffer_steal() */
477 static void reset_state(void)
479 queue_write = queue_read = 0; /* reset the queue */
480 p_voicefile = NULL; /* indicate no voicefile (trashed) */
481 #if CONFIG_CODEC == SWCODEC
482 /* Allocate a dedicated thumbnail buffer - once */
483 if (p_thumbnail == NULL)
485 size_for_thumbnail = audiobufend - audiobuf;
486 if (size_for_thumbnail > MAX_THUMBNAIL_BUFSIZE)
487 size_for_thumbnail = MAX_THUMBNAIL_BUFSIZE;
488 p_thumbnail = buffer_alloc(size_for_thumbnail);
490 #else
491 /* Just use the audiobuf, without allocating anything */
492 p_thumbnail = audiobuf;
493 size_for_thumbnail = audiobufend - audiobuf;
494 #endif
495 p_silence = NULL; /* pause clip not accessible */
498 /***************** Public implementation *****************/
500 void talk_init(void)
502 talk_menu_disable = 0;
503 if (talk_initialized && !strcasecmp(last_lang, global_settings.lang_file))
505 /* not a new file, nothing to do */
506 return;
509 #ifdef HAVE_MMC
510 if (filehandle >= 0) /* MMC: An old voice file might still be open */
512 close(filehandle);
513 filehandle = -1;
515 #endif
517 talk_initialized = true;
518 strncpy((char *) last_lang, (char *)global_settings.lang_file,
519 MAX_FILENAME);
521 #if CONFIG_CODEC == SWCODEC
522 audio_get_buffer(false, NULL); /* Must tell audio to reinitialize */
523 #endif
524 reset_state(); /* use this for most of our inits */
526 filehandle = open_voicefile();
527 has_voicefile = (filehandle >= 0); /* test if we can open it */
528 voicefile_size = 0;
530 if (has_voicefile)
532 voicefile_size = filesize(filehandle);
533 close(filehandle); /* close again, this was just to detect presence */
534 filehandle = -1;
539 #if CONFIG_CODEC == SWCODEC
540 /* return if a voice codec is required or not */
541 bool talk_voice_required(void)
543 return (voicefile_size != 0) /* Voice file is available */
544 || (global_settings.talk_dir_clip) /* Thumbnail clips are required */
545 || (global_settings.talk_file_clip);
547 #endif
549 /* return size of voice file */
550 int talk_get_bufsize(void)
552 return voicefile_size;
555 /* somebody else claims the mp3 buffer, e.g. for regular play/record */
556 int talk_buffer_steal(void)
558 #if CONFIG_CODEC != SWCODEC
559 mp3_play_stop();
560 #endif
561 #ifdef HAVE_MMC
562 if (filehandle >= 0) /* only relevant for MMC */
564 close(filehandle);
565 filehandle = -1;
567 #endif
568 reset_state();
570 return 0;
574 /* play a voice ID from voicefile */
575 int talk_id(long id, bool enqueue)
577 long clipsize;
578 unsigned char* clipbuf;
579 int unit;
581 #if CONFIG_CODEC != SWCODEC
582 if (audio_status()) /* busy, buffer in use */
583 return -1;
584 #endif
586 if (p_voicefile == NULL && has_voicefile)
587 load_voicefile(); /* reload needed */
589 if (p_voicefile == NULL) /* still no voices? */
590 return -1;
592 if (id == -1) /* -1 is an indication for silence */
593 return -1;
595 /* check if this is a special ID, with a value */
596 unit = ((unsigned long)id) >> UNIT_SHIFT;
597 if (unit)
598 { /* sign-extend the value */
599 id = (unsigned long)id << (32-UNIT_SHIFT);
600 id >>= (32-UNIT_SHIFT);
601 talk_value(id, unit, enqueue); /* speak it */
602 return 0; /* and stop, end of special case */
605 clipbuf = get_clip(id, &clipsize);
606 if (clipbuf == NULL)
607 return -1; /* not present */
609 queue_clip(clipbuf, clipsize, enqueue);
611 return 0;
615 /* play a thumbnail from file */
616 int talk_file(const char* filename, bool enqueue)
618 int fd;
619 int size;
620 struct mp3entry info;
622 #if CONFIG_CODEC != SWCODEC
623 if (audio_status()) /* busy, buffer in use */
624 return -1;
625 #endif
627 if (p_thumbnail == NULL || size_for_thumbnail <= 0)
628 return -1;
630 if(mp3info(&info, filename, false)) /* use this to find real start */
632 return 0; /* failed to open, or invalid */
635 fd = open(filename, O_RDONLY);
636 if (fd < 0) /* failed to open */
638 return 0;
641 lseek(fd, info.first_frame_offset, SEEK_SET); /* behind ID data */
643 size = read(fd, p_thumbnail, size_for_thumbnail);
644 close(fd);
646 /* ToDo: find audio, skip ID headers and trailers */
648 if (size != 0 && size != size_for_thumbnail) /* Don't play missing or truncated clips */
650 #if CONFIG_CODEC != SWCODEC
651 bitswap(p_thumbnail, size);
652 #endif
653 queue_clip(p_thumbnail, size, enqueue);
656 return size;
660 /* say a numeric value, this word ordering works for english,
661 but not necessarily for other languages (e.g. german) */
662 int talk_number(long n, bool enqueue)
664 int level = 2; /* mille count */
665 long mil = 1000000000; /* highest possible "-illion" */
667 #if CONFIG_CODEC != SWCODEC
668 if (audio_status()) /* busy, buffer in use */
669 return -1;
670 #endif
672 if (!enqueue)
673 shutup(); /* cut off all the pending stuff */
675 if (n==0)
676 { /* special case */
677 talk_id(VOICE_ZERO, true);
678 return 0;
681 if (n<0)
683 talk_id(VOICE_MINUS, true);
684 n = -n;
687 while (n)
689 int segment = n / mil; /* extract in groups of 3 digits */
690 n -= segment * mil; /* remove the used digits from number */
691 mil /= 1000; /* digit place for next round */
693 if (segment)
695 int hundreds = segment / 100;
696 int ones = segment % 100;
698 if (hundreds)
700 talk_id(VOICE_ZERO + hundreds, true);
701 talk_id(VOICE_HUNDRED, true);
704 /* combination indexing */
705 if (ones > 20)
707 int tens = ones/10 + 18;
708 talk_id(VOICE_ZERO + tens, true);
709 ones %= 10;
712 /* direct indexing */
713 if (ones)
714 talk_id(VOICE_ZERO + ones, true);
716 /* add billion, million, thousand */
717 if (mil)
718 talk_id(VOICE_THOUSAND + level, true);
720 level--;
723 return 0;
726 /* singular/plural aware saying of a value */
727 int talk_value(long n, int unit, bool enqueue)
729 int unit_id;
730 static const int unit_voiced[] =
731 { /* lookup table for the voice ID of the units */
732 [0 ... UNIT_LAST-1] = -1, /* regular ID, int, signed */
733 [UNIT_MS]
734 = VOICE_MILLISECONDS, /* here come the "real" units */
735 [UNIT_SEC]
736 = VOICE_SECONDS,
737 [UNIT_MIN]
738 = VOICE_MINUTES,
739 [UNIT_HOUR]
740 = VOICE_HOURS,
741 [UNIT_KHZ]
742 = VOICE_KHZ,
743 [UNIT_DB]
744 = VOICE_DB,
745 [UNIT_PERCENT]
746 = VOICE_PERCENT,
747 [UNIT_MAH]
748 = VOICE_MILLIAMPHOURS,
749 [UNIT_PIXEL]
750 = VOICE_PIXEL,
751 [UNIT_PER_SEC]
752 = VOICE_PER_SEC,
753 [UNIT_HERTZ]
754 = VOICE_HERTZ,
755 [UNIT_MB]
756 = LANG_MEGABYTE,
757 [UNIT_KBIT]
758 = VOICE_KBIT_PER_SEC,
761 #if CONFIG_CODEC != SWCODEC
762 if (audio_status()) /* busy, buffer in use */
763 return -1;
764 #endif
766 if (unit < 0 || unit >= UNIT_LAST)
767 unit_id = -1;
768 else
769 unit_id = unit_voiced[unit];
771 if ((n==1 || n==-1) /* singular? */
772 && unit_id >= VOICE_SECONDS && unit_id <= VOICE_HOURS)
774 unit_id--; /* use the singular for those units which have */
777 /* special case with a "plus" before */
778 if (n > 0 && (unit == UNIT_SIGNED || unit == UNIT_DB))
780 talk_id(VOICE_PLUS, enqueue);
781 enqueue = true;
784 talk_number(n, enqueue); /* say the number */
785 talk_id(unit_id, true); /* say the unit, if any */
787 return 0;
790 /* spell a string */
791 int talk_spell(const char* spell, bool enqueue)
793 char c; /* currently processed char */
795 #if CONFIG_CODEC != SWCODEC
796 if (audio_status()) /* busy, buffer in use */
797 return -1;
798 #endif
800 if (!enqueue)
801 shutup(); /* cut off all the pending stuff */
803 while ((c = *spell++) != '\0')
805 /* if this grows into too many cases, I should use a table */
806 if (c >= 'A' && c <= 'Z')
807 talk_id(VOICE_CHAR_A + c - 'A', true);
808 else if (c >= 'a' && c <= 'z')
809 talk_id(VOICE_CHAR_A + c - 'a', true);
810 else if (c >= '0' && c <= '9')
811 talk_id(VOICE_ZERO + c - '0', true);
812 else if (c == '-')
813 talk_id(VOICE_MINUS, true);
814 else if (c == '+')
815 talk_id(VOICE_PLUS, true);
816 else if (c == '.')
817 talk_id(VOICE_DOT, true);
818 else if (c == ' ')
819 talk_id(VOICE_PAUSE, true);
822 return 0;
825 bool talk_menus_enabled(void)
827 return (global_settings.talk_menu && talk_menu_disable == 0);
831 void talk_disable_menus(void)
833 talk_menu_disable++;
836 void talk_enable_menus(void)
838 talk_menu_disable--;