summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/playback.c77
1 files changed, 35 insertions, 42 deletions
diff --git a/apps/playback.c b/apps/playback.c
index a5b518aa51..fe0799e2e2 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -168,6 +168,11 @@ int filebufused;
168static volatile int buf_ridx; 168static volatile int buf_ridx;
169static volatile int buf_widx; 169static volatile int buf_widx;
170 170
171#ifndef SIMULATOR
172static unsigned char *iram_buf[2];
173#endif
174static unsigned char *dram_buf[2];
175
171/* Step count to the next unbuffered track. */ 176/* Step count to the next unbuffered track. */
172static int last_peek_offset; 177static int last_peek_offset;
173 178
@@ -227,56 +232,36 @@ bool is_filling(void)
227} 232}
228#endif 233#endif
229 234
230static void do_swap(int idx_old, int idx_new) 235static void swap_codec(void)
231{ 236{
232#ifndef SIMULATOR 237 int my_codec = current_codec;
233 unsigned char *iram_p = (unsigned char *)(CODEC_IRAM_ORIGIN);
234 unsigned char *iram_buf[2];
235#endif
236 unsigned char *dram_buf[2];
237 238
239 logf("swapping out codec:%d", current_codec);
238 240
241 /* Save our current IRAM and DRAM */
239#ifndef SIMULATOR 242#ifndef SIMULATOR
240 iram_buf[0] = &filebuf[filebuflen]; 243 memcpy(iram_buf[my_codec], (unsigned char *)CODEC_IRAM_ORIGIN,
241 iram_buf[1] = &filebuf[filebuflen+CODEC_IRAM_SIZE]; 244 CODEC_IRAM_SIZE);
242 memcpy(iram_buf[idx_old], iram_p, CODEC_IRAM_SIZE);
243 memcpy(iram_p, iram_buf[idx_new], CODEC_IRAM_SIZE);
244#endif 245#endif
246 memcpy(dram_buf[my_codec], codecbuf, CODEC_SIZE);
245 247
246 dram_buf[0] = (unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE*2]; 248 do {
247 dram_buf[1] = (unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE*2+CODEC_SIZE]; 249 /* Release my semaphore and force a task switch. */
248 memcpy(dram_buf[idx_old], codecbuf, CODEC_SIZE); 250 mutex_unlock(&mutex_codecthread);
249 memcpy(codecbuf, dram_buf[idx_new], CODEC_SIZE); 251 yield();
250} 252 mutex_lock(&mutex_codecthread);
251 253 /* Loop until the other codec has locked and run */
252static void swap_codec(void) 254 } while (my_codec == current_codec);
253{ 255 current_codec = my_codec;
254 int last_codec;
255
256 logf("swapping codec:%d", current_codec);
257
258 /* We should swap codecs' IRAM contents and code space. */
259 do_swap(current_codec, !current_codec);
260
261 last_codec = current_codec;
262 current_codec = !current_codec;
263
264 /* Release the semaphore and force a task switch. */
265 mutex_unlock(&mutex_codecthread);
266 sleep(1);
267
268 /* Waiting until we are ready to run again. */
269 mutex_lock(&mutex_codecthread);
270 256
271 /* Check if codec swap did not happen. */ 257 /* Reload our IRAM and DRAM */
272 if (current_codec != last_codec) 258#ifndef SIMULATOR
273 { 259 memcpy((unsigned char *)CODEC_IRAM_ORIGIN, iram_buf[my_codec],
274 logf("no codec switch happened!"); 260 CODEC_IRAM_SIZE);
275 do_swap(current_codec, !current_codec); 261#endif
276 current_codec = !current_codec;
277 }
278
279 invalidate_icache(); 262 invalidate_icache();
263 memcpy(codecbuf, dram_buf[my_codec], CODEC_SIZE);
264
280 logf("codec resuming:%d", current_codec); 265 logf("codec resuming:%d", current_codec);
281} 266}
282 267
@@ -2053,6 +2038,14 @@ static void reset_buffer(void)
2053 filebuf = &filebuf[talk_get_bufsize()]; 2038 filebuf = &filebuf[talk_get_bufsize()];
2054 filebuflen -= 2*CODEC_IRAM_SIZE + 2*CODEC_SIZE + talk_get_bufsize(); 2039 filebuflen -= 2*CODEC_IRAM_SIZE + 2*CODEC_SIZE + talk_get_bufsize();
2055 } 2040 }
2041
2042#ifndef SIMULATOR
2043 iram_buf[0] = &filebuf[filebuflen];
2044 iram_buf[1] = &filebuf[filebuflen+CODEC_IRAM_SIZE];
2045#endif
2046 dram_buf[0] = (unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE*2];
2047 dram_buf[1] = (unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE*2+CODEC_SIZE];
2048
2056} 2049}
2057 2050
2058void voice_codec_thread(void) 2051void voice_codec_thread(void)