diff options
Diffstat (limited to 'apps/talk.c')
-rw-r--r-- | apps/talk.c | 37 |
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 */ | |||
87 | static int filehandle; /* global, so the MMC variant can keep the file open */ | 87 | static int filehandle; /* global, so the MMC variant can keep the file open */ |
88 | static unsigned char* p_silence; /* VOICE_PAUSE clip, used for termination */ | 88 | static unsigned char* p_silence; /* VOICE_PAUSE clip, used for termination */ |
89 | static int silence_len; /* length of the VOICE_PAUSE clip */ | 89 | static int silence_len; /* length of the VOICE_PAUSE clip */ |
90 | static bool silence_add; /* flag if trailing silence shall be added */ | ||
91 | static unsigned char* p_lastclip; /* address of latest clip, for silence add */ | 90 | static 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 | ||
206 | re_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); |