summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/talk.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/apps/talk.c b/apps/talk.c
index f65b594b92..7ba858b47d 100644
--- a/apps/talk.c
+++ b/apps/talk.c
@@ -51,9 +51,10 @@ struct clip_entry /* one entry of the index table */
51struct voicefont /* file format of our "voicefont" */ 51struct voicefont /* file format of our "voicefont" */
52{ 52{
53 int version; /* version of the voicefont */ 53 int version; /* version of the voicefont */
54 int headersize; /* size of the header, =offset to index */ 54 int table; /* offset to index table, (=header size) */
55 int id_max; /* number of clips contained */ 55 int id1_max; /* number of "normal" clips contained in above index */
56 struct clip_entry index[]; /* followed by the index table */ 56 int id2_max; /* number of "voice only" clips contained in above index */
57 struct clip_entry index[]; /* followed by the index tables */
57 /* and finally the bitswapped mp3 clips, not visible here */ 58 /* and finally the bitswapped mp3 clips, not visible here */
58}; 59};
59 60
@@ -104,7 +105,7 @@ static int load_voicefont(void)
104 105
105 size = read(fd, mp3buf, mp3end - mp3buf); 106 size = read(fd, mp3buf, mp3end - mp3buf);
106 if (size > 1000 107 if (size > 1000
107 && ((struct voicefont*)mp3buf)->headersize 108 && ((struct voicefont*)mp3buf)->table
108 == offsetof(struct voicefont, index)) 109 == offsetof(struct voicefont, index))
109 { 110 {
110 p_voicefont = (struct voicefont*)mp3buf; 111 p_voicefont = (struct voicefont*)mp3buf;
@@ -294,9 +295,12 @@ int talk_id(int id, bool enqueue)
294 if (p_voicefont == NULL) /* still no voices? */ 295 if (p_voicefont == NULL) /* still no voices? */
295 return -1; 296 return -1;
296 297
298 if (id == -1) /* -1 is an indication for silence */
299 return -1;
300
297 /* check if this is a special ID, with a value */ 301 /* check if this is a special ID, with a value */
298 unit = ((unsigned)id) >> UNIT_SHIFT; 302 unit = ((unsigned)id) >> UNIT_SHIFT;
299 if (id != -1 && unit) 303 if (unit)
300 { /* sign-extend the value */ 304 { /* sign-extend the value */
301 //splash(200, true,"unit=%d", unit); 305 //splash(200, true,"unit=%d", unit);
302 id = (unsigned)id << (32-UNIT_SHIFT); 306 id = (unsigned)id << (32-UNIT_SHIFT);
@@ -305,9 +309,19 @@ int talk_id(int id, bool enqueue)
305 return 0; /* and stop, end of special case */ 309 return 0; /* and stop, end of special case */
306 } 310 }
307 311
308 if (id < 0 || id >= p_voicefont->id_max) 312 if (id > VOICEONLY_DELIMITER)
309 return -1; 313 { /* voice-only entries use the second part of the table */
310 314 id -= VOICEONLY_DELIMITER + 1;
315 if (id >= p_voicefont->id2_max)
316 return -1; /* must be newer than we have */
317 id += p_voicefont->id1_max; /* table 2 is behind table 1 */
318 }
319 else
320 { /* normal use of the first table */
321 if (id >= p_voicefont->id1_max)
322 return -1; /* must be newer than we have */
323 }
324
311 clipsize = p_voicefont->index[id].size; 325 clipsize = p_voicefont->index[id].size;
312 if (clipsize == 0) /* clip not included in voicefont */ 326 if (clipsize == 0) /* clip not included in voicefont */
313 return -1; 327 return -1;