"Trash Metal" should be "Thrash Metal". Reported as FS#6503, checked against Winamp.
[Rockbox.git] / apps / talk.c
blobc22b70066ea922588b3cf6a4e081a1daffda01dd
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 |-----------|------------
52 | thumbnail | voice
53 | |------------
54 | | filebuf
55 | |------------
56 | | audio
57 | |------------
58 | | codec swap
59 audiobufend----------+-----------+------------
61 SWCODEC allocates dedicated buffers, MASCODEC reuses audiobuf. */
64 /***************** Constants *****************/
66 #define QUEUE_SIZE 64 /* must be a power of two */
67 #define QUEUE_MASK (QUEUE_SIZE-1)
68 const char* const dir_thumbnail_name = "_dirname.talk";
69 const char* const file_thumbnail_ext = ".talk";
71 /***************** Functional Macros *****************/
73 #define QUEUE_LEVEL ((queue_write - queue_read) & QUEUE_MASK)
75 #define LOADED_MASK 0x80000000 /* MSB */
77 #if CONFIG_CODEC == SWCODEC
78 #define MAX_THUMBNAIL_BUFSIZE 32768
79 #endif
82 /***************** Data types *****************/
84 struct clip_entry /* one entry of the index table */
86 int offset; /* offset from start of voicefile file */
87 int size; /* size of the clip */
90 struct voicefile /* file format of our voice file */
92 int version; /* version of the voicefile */
93 int table; /* offset to index table, (=header size) */
94 int id1_max; /* number of "normal" clips contained in above index */
95 int id2_max; /* number of "voice only" clips contained in above index */
96 struct clip_entry index[]; /* followed by the index tables */
97 /* and finally the bitswapped mp3 clips, not visible here */
100 struct queue_entry /* one entry of the internal queue */
102 unsigned char* buf;
103 long len;
107 /***************** Globals *****************/
109 static unsigned char* p_thumbnail = NULL; /* buffer for thumbnail */
110 static long size_for_thumbnail; /* leftover buffer size for it */
111 static struct voicefile* p_voicefile; /* loaded voicefile */
112 static bool has_voicefile; /* a voicefile file is present */
113 static struct queue_entry queue[QUEUE_SIZE]; /* queue of scheduled clips */
114 static int queue_write; /* write index of queue, by application */
115 static int queue_read; /* read index of queue, by ISR context */
116 static int sent; /* how many bytes handed over to playback, owned by ISR */
117 static unsigned char curr_hd[3]; /* current frame header, for re-sync */
118 static int filehandle = -1; /* global, so the MMC variant can keep the file open */
119 static unsigned char* p_silence; /* VOICE_PAUSE clip, used for termination */
120 static long silence_len; /* length of the VOICE_PAUSE clip */
121 static unsigned char* p_lastclip; /* address of latest clip, for silence add */
122 static unsigned long voicefile_size = 0; /* size of the loaded voice file */
123 static unsigned char last_lang[MAX_FILENAME+1]; /* name of last used lang file (in talk_init) */
124 static bool talk_initialized; /* true if talk_init has been called */
126 /***************** Private prototypes *****************/
128 static void load_voicefile(void);
129 static void mp3_callback(unsigned char** start, int* size);
130 static int shutup(void);
131 static int queue_clip(unsigned char* buf, long size, bool enqueue);
132 static int open_voicefile(void);
133 static unsigned char* get_clip(long id, long* p_size);
136 /***************** Private implementation *****************/
138 static int open_voicefile(void)
140 char buf[64];
141 char* p_lang = "english"; /* default */
143 if ( global_settings.lang_file[0] &&
144 global_settings.lang_file[0] != 0xff )
145 { /* try to open the voice file of the selected language */
146 p_lang = (char *)global_settings.lang_file;
149 snprintf(buf, sizeof(buf), LANG_DIR "/%s.voice", p_lang);
151 return open(buf, O_RDONLY);
155 /* load the voice file into the mp3 buffer */
156 static void load_voicefile(void)
158 int load_size;
159 int got_size;
160 int file_size;
161 #if CONFIG_CODEC == SWCODEC
162 int length, i;
163 unsigned char *buf, temp;
164 #endif
166 filehandle = open_voicefile();
167 if (filehandle < 0) /* failed to open */
168 goto load_err;
170 file_size = filesize(filehandle);
171 if (file_size > audiobufend - audiobuf) /* won't fit? */
172 goto load_err;
174 #ifdef HAVE_MMC /* load only the header for now */
175 load_size = offsetof(struct voicefile, index);
176 #else /* load the full file */
177 load_size = file_size;
178 #endif
180 got_size = read(filehandle, audiobuf, load_size);
181 if (got_size != load_size /* failure */)
182 goto load_err;
184 #ifdef ROCKBOX_LITTLE_ENDIAN
185 logf("Byte swapping voice file");
186 p_voicefile = (struct voicefile*)audiobuf;
187 p_voicefile->version = swap32(p_voicefile->version);
188 p_voicefile->table = swap32(p_voicefile->table);
189 p_voicefile->id1_max = swap32(p_voicefile->id1_max);
190 p_voicefile->id2_max = swap32(p_voicefile->id2_max);
191 p_voicefile = NULL;
192 #endif
194 if (((struct voicefile*)audiobuf)->table /* format check */
195 == offsetof(struct voicefile, index))
197 p_voicefile = (struct voicefile*)audiobuf;
199 #if CONFIG_CODEC != SWCODEC
200 /* MASCODEC: now use audiobuf for voice then thumbnail */
201 p_thumbnail = audiobuf + file_size;
202 p_thumbnail += (long)p_thumbnail % 2; /* 16-bit align */
203 size_for_thumbnail = audiobufend - p_thumbnail;
204 #endif
206 else
207 goto load_err;
209 #ifdef ROCKBOX_LITTLE_ENDIAN
210 for (i = 0; i < p_voicefile->id1_max + p_voicefile->id2_max; i++)
212 struct clip_entry *ce;
213 ce = &p_voicefile->index[i];
214 ce->offset = swap32(ce->offset);
215 ce->size = swap32(ce->size);
217 #endif
219 /* Do a bitswap as necessary. */
220 #if CONFIG_CODEC == SWCODEC
221 logf("Bitswapping voice file.");
222 cpu_boost(true);
223 buf = (unsigned char *)(&p_voicefile->index) +
224 (p_voicefile->id1_max + p_voicefile->id2_max) * sizeof(struct clip_entry);
225 length = file_size - (buf - (unsigned char *) p_voicefile);
227 for (i = 0; i < length; i++)
229 temp = buf[i];
230 temp = ((temp >> 4) & 0x0f) | ((temp & 0x0f) << 4);
231 temp = ((temp >> 2) & 0x33) | ((temp & 0x33) << 2);
232 buf[i] = ((temp >> 1) & 0x55) | ((temp & 0x55) << 1);
234 cpu_boost(false);
236 #endif
238 #ifdef HAVE_MMC
239 /* load the index table, now that we know its size from the header */
240 load_size = (p_voicefile->id1_max + p_voicefile->id2_max)
241 * sizeof(struct clip_entry);
242 got_size = read(filehandle,
243 (unsigned char *) p_voicefile + offsetof(struct voicefile, index), load_size);
244 if (got_size != load_size) /* read error */
245 goto load_err;
246 #else
247 close(filehandle); /* only the MMC variant leaves it open */
248 filehandle = -1;
249 #endif
251 /* make sure to have the silence clip, if available */
252 p_silence = get_clip(VOICE_PAUSE, &silence_len);
254 return;
256 load_err:
257 p_voicefile = NULL;
258 has_voicefile = false; /* don't try again */
259 if (filehandle >= 0)
261 close(filehandle);
262 filehandle = -1;
264 return;
268 /* called in ISR context if mp3 data got consumed */
269 static void mp3_callback(unsigned char** start, int* size)
271 queue[queue_read].len -= sent; /* we completed this */
272 queue[queue_read].buf += sent;
274 if (queue[queue_read].len > 0) /* current clip not finished? */
275 { /* feed the next 64K-1 chunk */
276 #if CONFIG_CODEC != SWCODEC
277 sent = MIN(queue[queue_read].len, 0xFFFF);
278 #else
279 sent = queue[queue_read].len;
280 #endif
281 *start = queue[queue_read].buf;
282 *size = sent;
283 return;
285 else if (sent > 0) /* go to next entry */
287 queue_read = (queue_read + 1) & QUEUE_MASK;
290 re_check:
292 if (QUEUE_LEVEL) /* queue is not empty? */
293 { /* start next clip */
294 #if CONFIG_CODEC != SWCODEC
295 sent = MIN(queue[queue_read].len, 0xFFFF);
296 #else
297 sent = queue[queue_read].len;
298 #endif
299 *start = p_lastclip = queue[queue_read].buf;
300 *size = sent;
301 curr_hd[0] = p_lastclip[1];
302 curr_hd[1] = p_lastclip[2];
303 curr_hd[2] = p_lastclip[3];
305 else if (p_silence != NULL /* silence clip available */
306 && p_lastclip != p_silence /* previous clip wasn't silence */
307 && p_lastclip != p_thumbnail) /* ..or thumbnail */
308 { /* add silence clip when queue runs empty playing a voice clip */
309 queue[queue_write].buf = p_silence;
310 queue[queue_write].len = silence_len;
311 queue_write = (queue_write + 1) & QUEUE_MASK;
313 goto re_check;
315 else
317 *size = 0; /* end of data */
321 /* stop the playback and the pending clips */
322 static int shutup(void)
324 #if CONFIG_CODEC != SWCODEC
325 unsigned char* pos;
326 unsigned char* search;
327 unsigned char* end;
328 #endif
330 if (QUEUE_LEVEL == 0) /* has ended anyway */
332 #if CONFIG_CODEC == SWCODEC
333 mp3_play_stop();
334 #endif
335 return 0;
337 #if CONFIG_CODEC != SWCODEC
338 #if CONFIG_CPU == SH7034
339 CHCR3 &= ~0x0001; /* disable the DMA (and therefore the interrupt also) */
340 #endif
341 /* search next frame boundary and continue up to there */
342 pos = search = mp3_get_pos();
343 end = queue[queue_read].buf + queue[queue_read].len;
345 if (pos >= queue[queue_read].buf
346 && pos <= end) /* really our clip? */
347 { /* (for strange reasons this isn't nesessarily the case) */
348 /* find the next frame boundary */
349 while (search < end) /* search the remaining data */
351 if (*search++ != 0xFF) /* quick search for frame sync byte */
352 continue; /* (this does the majority of the job) */
354 /* look at the (bitswapped) rest of header candidate */
355 if (search[0] == curr_hd[0] /* do the quicker checks first */
356 && search[2] == curr_hd[2]
357 && (search[1] & 0x30) == (curr_hd[1] & 0x30)) /* sample rate */
359 search--; /* back to the sync byte */
360 break; /* From looking at it, this is our header. */
364 if (search-pos)
365 { /* play old data until the frame end, to keep the MAS in sync */
366 sent = search-pos;
368 queue_write = (queue_read + 1) & QUEUE_MASK; /* will be empty after next callback */
369 queue[queue_read].len = sent; /* current one ends after this */
371 #if CONFIG_CPU == SH7034
372 DTCR3 = sent; /* let the DMA finish this frame */
373 CHCR3 |= 0x0001; /* re-enable DMA */
374 #endif
375 return 0;
378 #endif
380 /* nothing to do, was frame boundary or not our clip */
381 mp3_play_stop();
383 queue_write = queue_read = 0; /* reset the queue */
385 return 0;
389 /* schedule a clip, at the end or discard the existing queue */
390 static int queue_clip(unsigned char* buf, long size, bool enqueue)
392 int queue_level;
394 if (!enqueue)
395 shutup(); /* cut off all the pending stuff */
397 if (!size)
398 return 0; /* safety check */
399 #if CONFIG_CPU == SH7034
400 /* disable the DMA temporarily, to be safe of race condition */
401 CHCR3 &= ~0x0001;
402 #endif
403 queue_level = QUEUE_LEVEL; /* check old level */
405 if (queue_level < QUEUE_SIZE - 1) /* space left? */
407 queue[queue_write].buf = buf; /* populate an entry */
408 queue[queue_write].len = size;
409 queue_write = (queue_write + 1) & QUEUE_MASK;
412 if (queue_level == 0)
413 { /* queue was empty, we have to do the initial start */
414 p_lastclip = buf;
415 #if CONFIG_CODEC != SWCODEC
416 sent = MIN(size, 0xFFFF); /* DMA can do no more */
417 #else
418 sent = size;
419 #endif
420 mp3_play_data(buf, sent, mp3_callback);
421 curr_hd[0] = buf[1];
422 curr_hd[1] = buf[2];
423 curr_hd[2] = buf[3];
424 mp3_play_pause(true); /* kickoff audio */
426 else
428 #if CONFIG_CPU == SH7034
429 CHCR3 |= 0x0001; /* re-enable DMA */
430 #endif
433 return 0;
436 /* fetch a clip from the voice file */
437 static unsigned char* get_clip(long id, long* p_size)
439 long clipsize;
440 unsigned char* clipbuf;
442 if (id > VOICEONLY_DELIMITER)
443 { /* voice-only entries use the second part of the table */
444 id -= VOICEONLY_DELIMITER + 1;
445 if (id >= p_voicefile->id2_max)
446 return NULL; /* must be newer than we have */
447 id += p_voicefile->id1_max; /* table 2 is behind table 1 */
449 else
450 { /* normal use of the first table */
451 if (id >= p_voicefile->id1_max)
452 return NULL; /* must be newer than we have */
455 clipsize = p_voicefile->index[id].size;
456 if (clipsize == 0) /* clip not included in voicefile */
457 return NULL;
458 clipbuf = (unsigned char *) p_voicefile + p_voicefile->index[id].offset;
460 #ifdef HAVE_MMC /* dynamic loading, on demand */
461 if (!(clipsize & LOADED_MASK))
462 { /* clip used for the first time, needs loading */
463 lseek(filehandle, p_voicefile->index[id].offset, SEEK_SET);
464 if (read(filehandle, clipbuf, clipsize) != clipsize)
465 return NULL; /* read error */
467 p_voicefile->index[id].size |= LOADED_MASK; /* mark as loaded */
469 else
470 { /* clip is in memory already */
471 clipsize &= ~LOADED_MASK; /* without the extra bit gives true size */
473 #endif
475 *p_size = clipsize;
476 return clipbuf;
480 /* common code for talk_init() and talk_buffer_steal() */
481 static void reset_state(void)
483 queue_write = queue_read = 0; /* reset the queue */
484 p_voicefile = NULL; /* indicate no voicefile (trashed) */
485 #if CONFIG_CODEC == SWCODEC
486 /* Allocate a dedicated thumbnail buffer - once */
487 if (p_thumbnail == NULL)
489 size_for_thumbnail = audiobufend - audiobuf;
490 if (size_for_thumbnail > MAX_THUMBNAIL_BUFSIZE)
491 size_for_thumbnail = MAX_THUMBNAIL_BUFSIZE;
492 p_thumbnail = buffer_alloc(size_for_thumbnail);
494 #else
495 /* Just use the audiobuf, without allocating anything */
496 p_thumbnail = audiobuf;
497 size_for_thumbnail = audiobufend - audiobuf;
498 #endif
499 p_silence = NULL; /* pause clip not accessible */
502 /***************** Public implementation *****************/
504 void talk_init(void)
506 if (talk_initialized && !strcasecmp(last_lang, global_settings.lang_file))
508 /* not a new file, nothing to do */
509 return;
512 #ifdef HAVE_MMC
513 if (filehandle >= 0) /* MMC: An old voice file might still be open */
515 close(filehandle);
516 filehandle = -1;
518 #endif
520 talk_initialized = true;
521 strncpy((char *) last_lang, (char *)global_settings.lang_file,
522 MAX_FILENAME);
524 #if CONFIG_CODEC == SWCODEC
525 audio_get_buffer(false, NULL); /* Must tell audio to reinitialize */
526 #endif
527 reset_state(); /* use this for most of our inits */
529 filehandle = open_voicefile();
530 has_voicefile = (filehandle >= 0); /* test if we can open it */
531 voicefile_size = 0;
533 if (has_voicefile)
535 voicefile_size = filesize(filehandle);
536 #if CONFIG_CODEC == SWCODEC
537 voice_init();
538 #endif
539 close(filehandle); /* close again, this was just to detect presence */
540 filehandle = -1;
545 #if CONFIG_CODEC == SWCODEC
546 /* return if a voice codec is required or not */
547 bool talk_voice_required(void)
549 return (voicefile_size != 0) /* Voice file is available */
550 || (global_settings.talk_dir == 3) /* Thumbnail clips are required */
551 || (global_settings.talk_file == 3);
553 #endif
555 /* return size of voice file */
556 int talk_get_bufsize(void)
558 return voicefile_size;
561 /* somebody else claims the mp3 buffer, e.g. for regular play/record */
562 int talk_buffer_steal(void)
564 #if CONFIG_CODEC != SWCODEC
565 mp3_play_stop();
566 #endif
567 #ifdef HAVE_MMC
568 if (filehandle >= 0) /* only relevant for MMC */
570 close(filehandle);
571 filehandle = -1;
573 #endif
574 reset_state();
576 return 0;
580 /* play a voice ID from voicefile */
581 int talk_id(long id, bool enqueue)
583 long clipsize;
584 unsigned char* clipbuf;
585 int unit;
587 #if CONFIG_CODEC != SWCODEC
588 if (audio_status()) /* busy, buffer in use */
589 return -1;
590 #endif
592 if (p_voicefile == NULL && has_voicefile)
593 load_voicefile(); /* reload needed */
595 if (p_voicefile == NULL) /* still no voices? */
596 return -1;
598 if (id == -1) /* -1 is an indication for silence */
599 return -1;
601 /* check if this is a special ID, with a value */
602 unit = ((unsigned long)id) >> UNIT_SHIFT;
603 if (unit)
604 { /* sign-extend the value */
605 id = (unsigned long)id << (32-UNIT_SHIFT);
606 id >>= (32-UNIT_SHIFT);
607 talk_value(id, unit, enqueue); /* speak it */
608 return 0; /* and stop, end of special case */
611 clipbuf = get_clip(id, &clipsize);
612 if (clipbuf == NULL)
613 return -1; /* not present */
615 queue_clip(clipbuf, clipsize, enqueue);
617 return 0;
621 /* play a thumbnail from file */
622 int talk_file(const char* filename, bool enqueue)
624 int fd;
625 int size;
626 struct mp3entry info;
628 #if CONFIG_CODEC != SWCODEC
629 if (audio_status()) /* busy, buffer in use */
630 return -1;
631 #endif
633 if (p_thumbnail == NULL || size_for_thumbnail <= 0)
634 return -1;
636 if(mp3info(&info, filename, false)) /* use this to find real start */
638 return 0; /* failed to open, or invalid */
641 fd = open(filename, O_RDONLY);
642 if (fd < 0) /* failed to open */
644 return 0;
647 lseek(fd, info.first_frame_offset, SEEK_SET); /* behind ID data */
649 size = read(fd, p_thumbnail, size_for_thumbnail);
650 close(fd);
652 /* ToDo: find audio, skip ID headers and trailers */
654 if (size != 0 && size != size_for_thumbnail) /* Don't play missing or truncated clips */
656 #if CONFIG_CODEC != SWCODEC
657 bitswap(p_thumbnail, size);
658 #endif
659 queue_clip(p_thumbnail, size, enqueue);
662 return size;
666 /* say a numeric value, this word ordering works for english,
667 but not necessarily for other languages (e.g. german) */
668 int talk_number(long n, bool enqueue)
670 int level = 2; /* mille count */
671 long mil = 1000000000; /* highest possible "-illion" */
673 #if CONFIG_CODEC != SWCODEC
674 if (audio_status()) /* busy, buffer in use */
675 return -1;
676 #endif
678 if (!enqueue)
679 shutup(); /* cut off all the pending stuff */
681 if (n==0)
682 { /* special case */
683 talk_id(VOICE_ZERO, true);
684 return 0;
687 if (n<0)
689 talk_id(VOICE_MINUS, true);
690 n = -n;
693 while (n)
695 int segment = n / mil; /* extract in groups of 3 digits */
696 n -= segment * mil; /* remove the used digits from number */
697 mil /= 1000; /* digit place for next round */
699 if (segment)
701 int hundreds = segment / 100;
702 int ones = segment % 100;
704 if (hundreds)
706 talk_id(VOICE_ZERO + hundreds, true);
707 talk_id(VOICE_HUNDRED, true);
710 /* combination indexing */
711 if (ones > 20)
713 int tens = ones/10 + 18;
714 talk_id(VOICE_ZERO + tens, true);
715 ones %= 10;
718 /* direct indexing */
719 if (ones)
720 talk_id(VOICE_ZERO + ones, true);
722 /* add billion, million, thousand */
723 if (mil)
724 talk_id(VOICE_THOUSAND + level, true);
726 level--;
729 return 0;
732 /* singular/plural aware saying of a value */
733 int talk_value(long n, int unit, bool enqueue)
735 int unit_id;
736 static const int unit_voiced[] =
737 { /* lookup table for the voice ID of the units */
738 [0 ... UNIT_LAST-1] = -1, /* regular ID, int, signed */
739 [UNIT_MS]
740 = VOICE_MILLISECONDS, /* here come the "real" units */
741 [UNIT_SEC]
742 = VOICE_SECONDS,
743 [UNIT_MIN]
744 = VOICE_MINUTES,
745 [UNIT_HOUR]
746 = VOICE_HOURS,
747 [UNIT_KHZ]
748 = VOICE_KHZ,
749 [UNIT_DB]
750 = VOICE_DB,
751 [UNIT_PERCENT]
752 = VOICE_PERCENT,
753 [UNIT_MAH]
754 = VOICE_MILLIAMPHOURS,
755 [UNIT_PIXEL]
756 = VOICE_PIXEL,
757 [UNIT_PER_SEC]
758 = VOICE_PER_SEC,
759 [UNIT_HERTZ]
760 = VOICE_HERTZ,
761 [UNIT_MB]
762 = LANG_MEGABYTE,
763 [UNIT_KBIT]
764 = VOICE_KBIT_PER_SEC,
767 #if CONFIG_CODEC != SWCODEC
768 if (audio_status()) /* busy, buffer in use */
769 return -1;
770 #endif
772 if (unit < 0 || unit >= UNIT_LAST)
773 unit_id = -1;
774 else
775 unit_id = unit_voiced[unit];
777 if ((n==1 || n==-1) /* singular? */
778 && unit_id >= VOICE_SECONDS && unit_id <= VOICE_HOURS)
780 unit_id--; /* use the singular for those units which have */
783 /* special case with a "plus" before */
784 if (n > 0 && (unit == UNIT_SIGNED || unit == UNIT_DB))
786 talk_id(VOICE_PLUS, enqueue);
787 enqueue = true;
790 talk_number(n, enqueue); /* say the number */
791 talk_id(unit_id, true); /* say the unit, if any */
793 return 0;
796 /* spell a string */
797 int talk_spell(const char* spell, bool enqueue)
799 char c; /* currently processed char */
801 #if CONFIG_CODEC != SWCODEC
802 if (audio_status()) /* busy, buffer in use */
803 return -1;
804 #endif
806 if (!enqueue)
807 shutup(); /* cut off all the pending stuff */
809 while ((c = *spell++) != '\0')
811 /* if this grows into too many cases, I should use a table */
812 if (c >= 'A' && c <= 'Z')
813 talk_id(VOICE_CHAR_A + c - 'A', true);
814 else if (c >= 'a' && c <= 'z')
815 talk_id(VOICE_CHAR_A + c - 'a', true);
816 else if (c >= '0' && c <= '9')
817 talk_id(VOICE_ZERO + c - '0', true);
818 else if (c == '-')
819 talk_id(VOICE_MINUS, true);
820 else if (c == '+')
821 talk_id(VOICE_PLUS, true);
822 else if (c == '.')
823 talk_id(VOICE_DOT, true);
824 else if (c == ' ')
825 talk_id(VOICE_PAUSE, true);
828 return 0;