Update several codec Makefiles so that the codec libs build again on Coldfire targets...
[Rockbox.git] / apps / talk.c
blobd81aa082c9884d753f86d79758ce006501f9804e
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 "settings.h"
31 #include "mp3_playback.h"
32 #include "audio.h"
33 #include "lang.h"
34 #include "talk.h"
35 #include "id3.h"
36 #include "logf.h"
37 #include "bitswap.h"
38 #if CONFIG_CODEC == SWCODEC
39 #include "playback.h"
40 #endif
41 #include "debug.h"
44 /* Memory layout varies between targets because the
45 Archos (MASCODEC) devices cannot mix voice and audio playback
47 MASCODEC | MASCODEC | SWCODEC
48 (playing) | (stopped) |
49 audiobuf-----------+-----------+-----------
50 audio | voice | thumbnail
51 |-----------|----------- filebuf
52 | thumbnail | voice
53 | |-----------
54 | | audio
55 audiobufend----------+-----------+-----------
57 SWCODEC allocates dedicated buffers, MASCODEC reuses audiobuf. */
60 /***************** Constants *****************/
62 #define QUEUE_SIZE 64 /* must be a power of two */
63 #define QUEUE_MASK (QUEUE_SIZE-1)
64 const char* const dir_thumbnail_name = "_dirname.talk";
65 const char* const file_thumbnail_ext = ".talk";
67 /***************** Functional Macros *****************/
69 #define QUEUE_LEVEL ((queue_write - queue_read) & QUEUE_MASK)
71 #define LOADED_MASK 0x80000000 /* MSB */
73 #if CONFIG_CODEC == SWCODEC
74 #define MAX_THUMBNAIL_BUFSIZE 32768
75 #endif
78 /***************** Data types *****************/
80 struct clip_entry /* one entry of the index table */
82 int offset; /* offset from start of voicefile file */
83 int size; /* size of the clip */
86 struct voicefile /* file format of our voice file */
88 int version; /* version of the voicefile */
89 int table; /* offset to index table, (=header size) */
90 int id1_max; /* number of "normal" clips contained in above index */
91 int id2_max; /* number of "voice only" clips contained in above index */
92 struct clip_entry index[]; /* followed by the index tables */
93 /* and finally the bitswapped mp3 clips, not visible here */
96 struct queue_entry /* one entry of the internal queue */
98 unsigned char* buf;
99 long len;
103 /***************** Globals *****************/
105 static unsigned char* p_thumbnail; /* buffer for thumbnail */
106 static long size_for_thumbnail; /* leftover buffer size for it */
107 static struct voicefile* p_voicefile; /* loaded voicefile */
108 static bool has_voicefile; /* a voicefile file is present */
109 static struct queue_entry queue[QUEUE_SIZE]; /* queue of scheduled clips */
110 static int queue_write; /* write index of queue, by application */
111 static int queue_read; /* read index of queue, by ISR context */
112 static int sent; /* how many bytes handed over to playback, owned by ISR */
113 static unsigned char curr_hd[3]; /* current frame header, for re-sync */
114 static int filehandle = -1; /* global, so the MMC variant can keep the file open */
115 static unsigned char* p_silence; /* VOICE_PAUSE clip, used for termination */
116 static long silence_len; /* length of the VOICE_PAUSE clip */
117 static unsigned char* p_lastclip; /* address of latest clip, for silence add */
118 static unsigned long voicefile_size = 0; /* size of the loaded voice file */
119 static unsigned char last_lang[MAX_FILENAME+1]; /* name of last used lang file (in talk_init) */
120 static bool talk_initialized; /* true if talk_init has been called */
122 /***************** Private prototypes *****************/
124 static void load_voicefile(void);
125 static void mp3_callback(unsigned char** start, int* size);
126 static int shutup(void);
127 static int queue_clip(unsigned char* buf, long size, bool enqueue);
128 static int open_voicefile(void);
129 static unsigned char* get_clip(long id, long* p_size);
132 /***************** Private implementation *****************/
134 static int open_voicefile(void)
136 char buf[64];
137 char* p_lang = "english"; /* default */
139 if ( global_settings.lang_file[0] &&
140 global_settings.lang_file[0] != 0xff )
141 { /* try to open the voice file of the selected language */
142 p_lang = (char *)global_settings.lang_file;
145 snprintf(buf, sizeof(buf), LANG_DIR "/%s.voice", p_lang);
147 return open(buf, O_RDONLY);
151 /* load the voice file into the mp3 buffer */
152 static void load_voicefile(void)
154 int load_size;
155 int got_size;
156 int file_size;
157 #if CONFIG_CODEC == SWCODEC
158 int length, i;
159 unsigned char *buf, temp;
160 #endif
162 filehandle = open_voicefile();
163 if (filehandle < 0) /* failed to open */
164 goto load_err;
166 file_size = filesize(filehandle);
167 if (file_size > audiobufend - audiobuf) /* won't fit? */
168 goto load_err;
170 #ifdef HAVE_MMC /* load only the header for now */
171 load_size = offsetof(struct voicefile, index);
172 #else /* load the full file */
173 load_size = file_size;
174 #endif
176 got_size = read(filehandle, audiobuf, load_size);
177 if (got_size != load_size /* failure */)
178 goto load_err;
180 #ifdef ROCKBOX_LITTLE_ENDIAN
181 logf("Byte swapping voice file");
182 p_voicefile = (struct voicefile*)audiobuf;
183 p_voicefile->version = swap32(p_voicefile->version);
184 p_voicefile->table = swap32(p_voicefile->table);
185 p_voicefile->id1_max = swap32(p_voicefile->id1_max);
186 p_voicefile->id2_max = swap32(p_voicefile->id2_max);
187 p_voicefile = NULL;
188 #endif
190 if (((struct voicefile*)audiobuf)->table /* format check */
191 == offsetof(struct voicefile, index))
193 p_voicefile = (struct voicefile*)audiobuf;
195 #if CONFIG_CODEC != SWCODEC
196 /* MASCODEC: now use audiobuf for voice then thumbnail */
197 p_thumbnail = audiobuf + file_size;
198 p_thumbnail += (long)p_thumbnail % 2; /* 16-bit align */
199 size_for_thumbnail = audiobufend - p_thumbnail;
200 #endif
202 else
203 goto load_err;
205 #ifdef ROCKBOX_LITTLE_ENDIAN
206 for (i = 0; i < p_voicefile->id1_max + p_voicefile->id2_max; i++)
208 struct clip_entry *ce;
209 ce = &p_voicefile->index[i];
210 ce->offset = swap32(ce->offset);
211 ce->size = swap32(ce->size);
213 #endif
215 /* Do a bitswap as necessary. */
216 #if CONFIG_CODEC == SWCODEC
217 logf("Bitswapping voice file.");
218 cpu_boost_id(true, CPUBOOSTID_TALK);
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_id(false, CPUBOOSTID_TALK);
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, int* 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 */
483 size_for_thumbnail = audiobufend - audiobuf;
484 if (size_for_thumbnail > MAX_THUMBNAIL_BUFSIZE)
485 size_for_thumbnail = MAX_THUMBNAIL_BUFSIZE;
486 p_thumbnail = buffer_alloc(size_for_thumbnail);
487 #else
488 /* Just use the audiobuf, without allocating anything */
489 p_thumbnail = audiobuf;
490 size_for_thumbnail = audiobufend - audiobuf;
491 #endif
492 p_silence = NULL; /* pause clip not accessible */
495 /***************** Public implementation *****************/
497 void talk_init(void)
499 if (talk_initialized && !strcasecmp(last_lang, global_settings.lang_file))
501 /* not a new file, nothing to do */
502 return;
505 #ifdef HAVE_MMC
506 if (filehandle >= 0) /* MMC: An old voice file might still be open */
508 close(filehandle);
509 filehandle = -1;
511 #endif
513 talk_initialized = true;
514 strncpy((char *) last_lang, (char *)global_settings.lang_file,
515 MAX_FILENAME);
517 #if CONFIG_CODEC == SWCODEC
518 audio_stop();
519 #endif
520 reset_state(); /* use this for most of our inits */
522 filehandle = open_voicefile();
523 has_voicefile = (filehandle >= 0); /* test if we can open it */
524 voicefile_size = 0;
526 if (has_voicefile)
528 voicefile_size = filesize(filehandle);
529 #if CONFIG_CODEC == SWCODEC
530 voice_init();
531 #endif
532 close(filehandle); /* close again, this was just to detect presence */
533 filehandle = -1;
538 /* return if a voice codec is required or not */
539 bool talk_voice_required(void)
541 return (voicefile_size != 0) /* Voice file is available */
542 || (global_settings.talk_dir == 3) /* Thumbnail clips are required */
543 || (global_settings.talk_file == 3);
546 /* return size of voice file */
547 int talk_get_bufsize(void)
549 return voicefile_size;
552 /* somebody else claims the mp3 buffer, e.g. for regular play/record */
553 int talk_buffer_steal(void)
555 mp3_play_stop();
556 #ifdef HAVE_MMC
557 if (filehandle >= 0) /* only relevant for MMC */
559 close(filehandle);
560 filehandle = -1;
562 #endif
563 reset_state();
565 return 0;
569 /* play a voice ID from voicefile */
570 int talk_id(long id, bool enqueue)
572 long clipsize;
573 unsigned char* clipbuf;
574 int unit;
576 #if CONFIG_CODEC != SWCODEC
577 if (audio_status()) /* busy, buffer in use */
578 return -1;
579 #endif
581 if (p_voicefile == NULL && has_voicefile)
582 load_voicefile(); /* reload needed */
584 if (p_voicefile == NULL) /* still no voices? */
585 return -1;
587 if (id == -1) /* -1 is an indication for silence */
588 return -1;
590 /* check if this is a special ID, with a value */
591 unit = ((unsigned long)id) >> UNIT_SHIFT;
592 if (unit)
593 { /* sign-extend the value */
594 id = (unsigned long)id << (32-UNIT_SHIFT);
595 id >>= (32-UNIT_SHIFT);
596 talk_value(id, unit, enqueue); /* speak it */
597 return 0; /* and stop, end of special case */
600 clipbuf = get_clip(id, &clipsize);
601 if (clipbuf == NULL)
602 return -1; /* not present */
604 queue_clip(clipbuf, clipsize, enqueue);
606 return 0;
610 /* play a thumbnail from file */
611 int talk_file(const char* filename, bool enqueue)
613 int fd;
614 int size;
615 struct mp3entry info;
617 #if CONFIG_CODEC != SWCODEC
618 if (audio_status()) /* busy, buffer in use */
619 return -1;
620 #endif
622 if (p_thumbnail == NULL || size_for_thumbnail <= 0)
623 return -1;
625 if(mp3info(&info, filename, false)) /* use this to find real start */
627 return 0; /* failed to open, or invalid */
630 fd = open(filename, O_RDONLY);
631 if (fd < 0) /* failed to open */
633 return 0;
636 lseek(fd, info.first_frame_offset, SEEK_SET); /* behind ID data */
638 size = read(fd, p_thumbnail, size_for_thumbnail);
639 close(fd);
641 /* ToDo: find audio, skip ID headers and trailers */
643 if (size != 0 && size != size_for_thumbnail) /* Don't play missing or truncated clips */
645 #if CONFIG_CODEC != SWCODEC
646 bitswap(p_thumbnail, size);
647 #endif
648 queue_clip(p_thumbnail, size, enqueue);
651 return size;
655 /* say a numeric value, this word ordering works for english,
656 but not necessarily for other languages (e.g. german) */
657 int talk_number(long n, bool enqueue)
659 int level = 2; /* mille count */
660 long mil = 1000000000; /* highest possible "-illion" */
662 #if CONFIG_CODEC != SWCODEC
663 if (audio_status()) /* busy, buffer in use */
664 return -1;
665 #endif
667 if (!enqueue)
668 shutup(); /* cut off all the pending stuff */
670 if (n==0)
671 { /* special case */
672 talk_id(VOICE_ZERO, true);
673 return 0;
676 if (n<0)
678 talk_id(VOICE_MINUS, true);
679 n = -n;
682 while (n)
684 int segment = n / mil; /* extract in groups of 3 digits */
685 n -= segment * mil; /* remove the used digits from number */
686 mil /= 1000; /* digit place for next round */
688 if (segment)
690 int hundreds = segment / 100;
691 int ones = segment % 100;
693 if (hundreds)
695 talk_id(VOICE_ZERO + hundreds, true);
696 talk_id(VOICE_HUNDRED, true);
699 /* combination indexing */
700 if (ones > 20)
702 int tens = ones/10 + 18;
703 talk_id(VOICE_ZERO + tens, true);
704 ones %= 10;
707 /* direct indexing */
708 if (ones)
709 talk_id(VOICE_ZERO + ones, true);
711 /* add billion, million, thousand */
712 if (mil)
713 talk_id(VOICE_THOUSAND + level, true);
715 level--;
718 return 0;
721 /* singular/plural aware saying of a value */
722 int talk_value(long n, int unit, bool enqueue)
724 int unit_id;
725 static const int unit_voiced[] =
726 { /* lookup table for the voice ID of the units */
727 [0 ... UNIT_LAST-1] = -1, /* regular ID, int, signed */
728 [UNIT_MS]
729 = VOICE_MILLISECONDS, /* here come the "real" units */
730 [UNIT_SEC]
731 = VOICE_SECONDS,
732 [UNIT_MIN]
733 = VOICE_MINUTES,
734 [UNIT_HOUR]
735 = VOICE_HOURS,
736 [UNIT_KHZ]
737 = VOICE_KHZ,
738 [UNIT_DB]
739 = VOICE_DB,
740 [UNIT_PERCENT]
741 = VOICE_PERCENT,
742 [UNIT_MAH]
743 = VOICE_MILLIAMPHOURS,
744 [UNIT_PIXEL]
745 = VOICE_PIXEL,
746 [UNIT_PER_SEC]
747 = VOICE_PER_SEC,
748 [UNIT_HERTZ]
749 = VOICE_HERTZ,
750 [UNIT_MB]
751 = LANG_MEGABYTE,
752 [UNIT_KBIT]
753 = VOICE_KBIT_PER_SEC,
756 #if CONFIG_CODEC != SWCODEC
757 if (audio_status()) /* busy, buffer in use */
758 return -1;
759 #endif
761 if (unit < 0 || unit >= UNIT_LAST)
762 unit_id = -1;
763 else
764 unit_id = unit_voiced[unit];
766 if ((n==1 || n==-1) /* singular? */
767 && unit_id >= VOICE_SECONDS && unit_id <= VOICE_HOURS)
769 unit_id--; /* use the singular for those units which have */
772 /* special case with a "plus" before */
773 if (n > 0 && (unit == UNIT_SIGNED || unit == UNIT_DB))
775 talk_id(VOICE_PLUS, enqueue);
776 enqueue = true;
779 talk_number(n, enqueue); /* say the number */
780 talk_id(unit_id, true); /* say the unit, if any */
782 return 0;
785 /* spell a string */
786 int talk_spell(const char* spell, bool enqueue)
788 char c; /* currently processed char */
790 #if CONFIG_CODEC != SWCODEC
791 if (audio_status()) /* busy, buffer in use */
792 return -1;
793 #endif
795 if (!enqueue)
796 shutup(); /* cut off all the pending stuff */
798 while ((c = *spell++) != '\0')
800 /* if this grows into too many cases, I should use a table */
801 if (c >= 'A' && c <= 'Z')
802 talk_id(VOICE_CHAR_A + c - 'A', true);
803 else if (c >= 'a' && c <= 'z')
804 talk_id(VOICE_CHAR_A + c - 'a', true);
805 else if (c >= '0' && c <= '9')
806 talk_id(VOICE_ZERO + c - '0', true);
807 else if (c == '-')
808 talk_id(VOICE_MINUS, true);
809 else if (c == '+')
810 talk_id(VOICE_PLUS, true);
811 else if (c == '.')
812 talk_id(VOICE_DOT, true);
813 else if (c == ' ')
814 talk_id(VOICE_PAUSE, true);
817 return 0;