summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2010-03-08 12:08:29 +0000
committerNils Wallménius <nils@rockbox.org>2010-03-08 12:08:29 +0000
commitd0a170c1769f13f1e42bc306979f6a36085f7344 (patch)
tree381644305b99fb215d345a5f29d0d82e1fe1b0f6 /apps/plugins
parenta5ffb4dabfef73994f6dc597413c35411dcddb3f (diff)
downloadrockbox-d0a170c1769f13f1e42bc306979f6a36085f7344.tar.gz
rockbox-d0a170c1769f13f1e42bc306979f6a36085f7344.zip
Use the same output func for wav writing and checksum calculation, simplifying the code and possibly speeding up checksum calculation slightly
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25068 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/test_codec.c116
1 files changed, 12 insertions, 104 deletions
diff --git a/apps/plugins/test_codec.c b/apps/plugins/test_codec.c
index e556453464..03c2daa30b 100644
--- a/apps/plugins/test_codec.c
+++ b/apps/plugins/test_codec.c
@@ -262,104 +262,8 @@ static void pcmbuf_insert_null(const void *ch1, const void *ch2, int count)
262 rb->reset_poweroff_timer(); 262 rb->reset_poweroff_timer();
263} 263}
264 264
265static void pcmbuf_insert_checksum(const void *ch1, const void *ch2, int count) 265/* WAV output or calculate crc32 of output*/
266{ 266static void pcmbuf_insert_wav_checksum(const void *ch1, const void *ch2, int count)
267 const int16_t* data1_16;
268 const int16_t* data2_16;
269 const int32_t* data1_32;
270 const int32_t* data2_32;
271 const int scale = wavinfo.sampledepth - 15;
272 const int dc_bias = 1 << (scale - 1);
273 int channels = (wavinfo.stereomode == STEREO_MONO) ? 1 : 2;
274
275 /* Prevent idle poweroff */
276 rb->reset_poweroff_timer();
277
278 if (use_dsp) {
279 count = process_dsp(ch1, ch2, count);
280 wavinfo.totalsamples += count;
281 if (channels == 1)
282 {
283 unsigned char *s = dspbuffer, *d = dspbuffer;
284 int c = count;
285 while (c-- > 0)
286 {
287 *d++ = *s++;
288 *d++ = *s++;
289 s++;
290 s++;
291 }
292 }
293 crc32 = rb->crc_32(dspbuffer, count * 2 * channels, crc32);
294 }
295 else
296 {
297 if (wavinfo.sampledepth <= 16) {
298 data1_16 = ch1;
299 data2_16 = ch2;
300
301 switch(wavinfo.stereomode)
302 {
303 case STEREO_INTERLEAVED:
304 while (count--) {
305 crc32 = rb->crc_32(data1_16, 4, crc32);
306 data1_16 += 2;
307 }
308 break;
309
310 case STEREO_NONINTERLEAVED:
311 while (count--) {
312 crc32 = rb->crc_32(data1_16++, 2, crc32);
313 crc32 = rb->crc_32(data2_16++, 2, crc32);
314 }
315 break;
316
317 case STEREO_MONO:
318 while (count--) {
319 crc32 = rb->crc_32(data1_16++, 2, crc32);
320 }
321 break;
322 }
323 }
324 else
325 {
326 data1_32 = ch1;
327 data2_32 = ch2;
328
329 switch(wavinfo.stereomode)
330 {
331 case STEREO_INTERLEAVED:
332 while (count--) {
333 int16_t s = clip_sample((*data1_32++ + dc_bias) >> scale);
334 crc32 = rb->crc_32(&s, 2, crc32);
335 s = clip_sample((*data1_32++ + dc_bias) >> scale);
336 crc32 = rb->crc_32(&s, 2, crc32);
337 }
338 break;
339
340 case STEREO_NONINTERLEAVED:
341 while (count--) {
342 int16_t s = clip_sample((*data1_32++ + dc_bias) >> scale);
343 crc32 = rb->crc_32(&s, 2, crc32);
344 s = clip_sample((*data2_32++ + dc_bias) >> scale);
345 crc32 = rb->crc_32(&s, 2, crc32);
346 }
347
348 break;
349
350 case STEREO_MONO:
351 while (count--) {
352 int16_t s = clip_sample((*data1_32++ + dc_bias) >> scale);
353 crc32 = rb->crc_32(&s, 2, crc32);
354 }
355 break;
356 }
357 }
358 }
359}
360
361/* WAV output */
362static void pcmbuf_insert_wav(const void *ch1, const void *ch2, int count)
363{ 267{
364 const int16_t* data1_16; 268 const int16_t* data1_16;
365 const int16_t* data2_16; 269 const int16_t* data2_16;
@@ -388,7 +292,10 @@ static void pcmbuf_insert_wav(const void *ch1, const void *ch2, int count)
388 s++; 292 s++;
389 } 293 }
390 } 294 }
391 rb->write(wavinfo.fd, dspbuffer, count * 2 * channels); 295 if (checksum)
296 crc32 = rb->crc_32(dspbuffer, count * 2 * channels, crc32);
297 else
298 rb->write(wavinfo.fd, dspbuffer, count * 2 * channels);
392 } 299 }
393 else 300 else
394 { 301 {
@@ -459,7 +366,10 @@ static void pcmbuf_insert_wav(const void *ch1, const void *ch2, int count)
459 } 366 }
460 367
461 wavinfo.totalsamples += count; 368 wavinfo.totalsamples += count;
462 rb->write(wavinfo.fd, wavbuffer, p - wavbuffer); 369 if (checksum)
370 crc32 = rb->crc_32(wavbuffer, p - wavbuffer, crc32);
371 else
372 rb->write(wavinfo.fd, wavbuffer, p - wavbuffer);
463 } /* else */ 373 } /* else */
464} 374}
465 375
@@ -582,10 +492,8 @@ static void init_ci(void)
582 492
583 ci.codec_get_buffer = codec_get_buffer; 493 ci.codec_get_buffer = codec_get_buffer;
584 494
585 if (wavinfo.fd >= 0) { 495 if (wavinfo.fd >= 0 || checksum) {
586 ci.pcmbuf_insert = pcmbuf_insert_wav; 496 ci.pcmbuf_insert = pcmbuf_insert_wav_checksum;
587 } else if (checksum){
588 ci.pcmbuf_insert = pcmbuf_insert_checksum;
589 } else { 497 } else {
590 ci.pcmbuf_insert = pcmbuf_insert_null; 498 ci.pcmbuf_insert = pcmbuf_insert_null;
591 } 499 }