summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2004-11-18 22:59:20 +0000
committerJens Arnold <amiconn@rockbox.org>2004-11-18 22:59:20 +0000
commit1a479d634d0ce3e9681d185f0987365802bfdbc7 (patch)
tree53e42eacdd541ab36b9ee9ec548f0c99481221b3
parentfee06d68c777c71c0c38a359a1dcffc9ef30f17c (diff)
downloadrockbox-1a479d634d0ce3e9681d185f0987365802bfdbc7.tar.gz
rockbox-1a479d634d0ce3e9681d185f0987365802bfdbc7.zip
Late-add the final silence clip to the queue. This ensures correct shutup() while that clip is playing. Swallowed clip beginnings should be finally gone now. Optimization of the queue pointer handling.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5425 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/talk.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/apps/talk.c b/apps/talk.c
index 3dda67a040..0d359844f9 100644
--- a/apps/talk.c
+++ b/apps/talk.c
@@ -87,7 +87,6 @@ static unsigned char curr_hd[3]; /* current frame header, for re-sync */
87static int filehandle; /* global, so the MMC variant can keep the file open */ 87static int filehandle; /* global, so the MMC variant can keep the file open */
88static unsigned char* p_silence; /* VOICE_PAUSE clip, used for termination */ 88static unsigned char* p_silence; /* VOICE_PAUSE clip, used for termination */
89static int silence_len; /* length of the VOICE_PAUSE clip */ 89static int silence_len; /* length of the VOICE_PAUSE clip */
90static bool silence_add; /* flag if trailing silence shall be added */
91static unsigned char* p_lastclip; /* address of latest clip, for silence add */ 90static unsigned char* p_lastclip; /* address of latest clip, for silence add */
92 91
93 92
@@ -201,27 +200,29 @@ static void mp3_callback(unsigned char** start, int* size)
201 } 200 }
202 else if (sent > 0) /* go to next entry */ 201 else if (sent > 0) /* go to next entry */
203 { 202 {
204 queue_read++; 203 queue_read = (queue_read + 1) & QUEUE_MASK;
205 if (queue_read >= QUEUE_SIZE)
206 queue_read = 0;
207 } 204 }
208 205
206re_check:
207
209 if (QUEUE_LEVEL) /* queue is not empty? */ 208 if (QUEUE_LEVEL) /* queue is not empty? */
210 { /* start next clip */ 209 { /* start next clip */
211 sent = MIN(queue[queue_read].len, 0xFFFF); 210 sent = MIN(queue[queue_read].len, 0xFFFF);
212 *start = p_lastclip = queue[queue_read].buf; 211 *start = p_lastclip = queue[queue_read].buf;
213 *size = sent; 212 *size = sent;
214 curr_hd[0] = (*start)[1]; 213 curr_hd[0] = p_lastclip[1];
215 curr_hd[1] = (*start)[2]; 214 curr_hd[1] = p_lastclip[2];
216 curr_hd[2] = (*start)[3]; 215 curr_hd[2] = p_lastclip[3];
217 } 216 }
218 else if (silence_add && p_silence != NULL /* want and can add silence */ 217 else if (p_silence != NULL /* silence clip available */
219 && p_lastclip < p_thumbnail) /* and wasn't playing thumbnail file */ 218 && p_lastclip != p_silence /* previous clip wasn't silence */
219 && p_lastclip < p_thumbnail) /* ..and not a thumbnail */
220 { /* add silence clip when queue runs empty playing a voice clip */ 220 { /* add silence clip when queue runs empty playing a voice clip */
221 silence_add = false; /* do this only once */ 221 queue[queue_write].buf = p_silence;
222 sent = 0; /* not part of "official" data from queue */ 222 queue[queue_write].len = silence_len;
223 *start = p_silence; 223 queue_write = (queue_write + 1) & QUEUE_MASK;
224 *size = silence_len; 224
225 goto re_check;
225 } 226 }
226 else 227 else
227 { 228 {
@@ -271,9 +272,7 @@ static int shutup(void)
271 { /* play old data until the frame end, to keep the MAS in sync */ 272 { /* play old data until the frame end, to keep the MAS in sync */
272 sent = search-pos; 273 sent = search-pos;
273 274
274 queue_write = queue_read + 1; /* will be empty after next callback */ 275 queue_write = (queue_read + 1) & QUEUE_MASK; /* will be empty after next callback */
275 if (queue_write >= QUEUE_SIZE)
276 queue_write = 0;
277 queue[queue_read].len = sent; /* current one ends after this */ 276 queue[queue_read].len = sent; /* current one ends after this */
278 277
279 DTCR3 = sent; /* let the DMA finish this frame */ 278 DTCR3 = sent; /* let the DMA finish this frame */
@@ -310,15 +309,11 @@ static int queue_clip(unsigned char* buf, int size, bool enqueue)
310 { 309 {
311 queue[queue_write].buf = buf; /* populate an entry */ 310 queue[queue_write].buf = buf; /* populate an entry */
312 queue[queue_write].len = size; 311 queue[queue_write].len = size;
313 312 queue_write = (queue_write + 1) & QUEUE_MASK;
314 queue_write++; /* increase queue */
315 if (queue_write >= QUEUE_SIZE)
316 queue_write = 0;
317 } 313 }
318 314
319 if (queue_level == 0) 315 if (queue_level == 0)
320 { /* queue was empty, we have to do the initial start */ 316 { /* queue was empty, we have to do the initial start */
321 silence_add = true;
322 p_lastclip = buf; 317 p_lastclip = buf;
323 sent = MIN(size, 0xFFFF); /* DMA can do no more */ 318 sent = MIN(size, 0xFFFF); /* DMA can do no more */
324 mp3_play_data(buf, sent, mp3_callback); 319 mp3_play_data(buf, sent, mp3_callback);