diff options
Diffstat (limited to 'apps/codecs/wavpack_enc.c')
-rw-r--r-- | apps/codecs/wavpack_enc.c | 112 |
1 files changed, 57 insertions, 55 deletions
diff --git a/apps/codecs/wavpack_enc.c b/apps/codecs/wavpack_enc.c index d908e284be..730cf0734b 100644 --- a/apps/codecs/wavpack_enc.c +++ b/apps/codecs/wavpack_enc.c | |||
@@ -389,77 +389,79 @@ static bool init_encoder(void) | |||
389 | return true; | 389 | return true; |
390 | } /* init_encoder */ | 390 | } /* init_encoder */ |
391 | 391 | ||
392 | enum codec_status codec_main(void) | 392 | /* this is the codec entry point */ |
393 | enum codec_status codec_main(enum codec_entry_call_reason reason) | ||
393 | { | 394 | { |
394 | /* initialize params and config */ | 395 | if (reason == CODEC_LOAD) { |
395 | if (!init_encoder()) | 396 | /* initialize params and config */ |
396 | return CODEC_ERROR; | 397 | if (!init_encoder()) |
398 | return CODEC_ERROR; | ||
399 | } | ||
400 | else if (reason == CODEC_UNLOAD) { | ||
401 | /* reset parameters to initial state */ | ||
402 | ci->enc_set_parameters(NULL); | ||
403 | } | ||
397 | 404 | ||
405 | return CODEC_OK; | ||
406 | } | ||
407 | |||
408 | /* this is called for each file to process */ | ||
409 | enum codec_status codec_run(void) | ||
410 | { | ||
398 | /* main encoding loop */ | 411 | /* main encoding loop */ |
399 | while(!ci->stop_codec) | 412 | while(ci->get_command(NULL) != CODEC_ACTION_HALT) |
400 | { | 413 | { |
401 | uint8_t *src; | 414 | uint8_t *src = (uint8_t *)ci->enc_get_pcm_data(PCM_CHUNK_SIZE); |
415 | struct enc_chunk_hdr *chunk; | ||
416 | bool abort_chunk; | ||
417 | uint8_t *dst; | ||
418 | uint8_t *src_end; | ||
402 | 419 | ||
403 | while ((src = ci->enc_get_pcm_data(PCM_CHUNK_SIZE)) != NULL) | 420 | if(src == NULL) |
404 | { | 421 | continue; |
405 | struct enc_chunk_hdr *chunk; | ||
406 | bool abort_chunk; | ||
407 | uint8_t *dst; | ||
408 | uint8_t *src_end; | ||
409 | |||
410 | if(ci->stop_codec) | ||
411 | break; | ||
412 | |||
413 | abort_chunk = true; | ||
414 | 422 | ||
415 | chunk = ci->enc_get_chunk(); | 423 | chunk = ci->enc_get_chunk(); |
416 | 424 | ||
417 | /* reset counts and pointer */ | 425 | /* reset counts and pointer */ |
418 | chunk->enc_size = 0; | 426 | chunk->enc_size = 0; |
419 | chunk->num_pcm = 0; | 427 | chunk->num_pcm = 0; |
420 | chunk->enc_data = NULL; | 428 | chunk->enc_data = NULL; |
421 | 429 | ||
422 | dst = ENC_CHUNK_SKIP_HDR(dst, chunk); | 430 | dst = ENC_CHUNK_SKIP_HDR(dst, chunk); |
423 | 431 | ||
424 | WavpackStartBlock(wpc, dst, dst + data_size); | 432 | WavpackStartBlock(wpc, dst, dst + data_size); |
425 | 433 | ||
426 | chunk_to_int32((uint32_t*)src); | 434 | chunk_to_int32((uint32_t*)src); |
427 | src = input_buffer; | 435 | src = input_buffer; |
428 | src_end = src + input_size; | 436 | src_end = src + input_size; |
429 | 437 | ||
430 | /* encode chunk in four steps yielding between each */ | 438 | /* encode chunk in four steps yielding between each */ |
431 | do | 439 | do |
440 | { | ||
441 | abort_chunk = true; | ||
442 | if (WavpackPackSamples(wpc, (int32_t *)src, | ||
443 | PCM_SAMP_PER_CHUNK/4)) | ||
432 | { | 444 | { |
433 | if (WavpackPackSamples(wpc, (int32_t *)src, | 445 | chunk->num_pcm += PCM_SAMP_PER_CHUNK/4; |
434 | PCM_SAMP_PER_CHUNK/4)) | 446 | ci->yield(); |
435 | { | 447 | /* could've been stopped in some way */ |
436 | chunk->num_pcm += PCM_SAMP_PER_CHUNK/4; | 448 | abort_chunk = chunk->flags & CHUNKF_ABORT; |
437 | ci->yield(); | ||
438 | /* could've been stopped in some way */ | ||
439 | abort_chunk = ci->stop_codec || | ||
440 | (chunk->flags & CHUNKF_ABORT); | ||
441 | } | ||
442 | |||
443 | src += input_step; | ||
444 | } | 449 | } |
445 | while (!abort_chunk && src < src_end); | ||
446 | 450 | ||
447 | if (!abort_chunk) | 451 | src += input_step; |
448 | { | ||
449 | chunk->enc_data = dst; | ||
450 | if (chunk->num_pcm < PCM_SAMP_PER_CHUNK) | ||
451 | ci->enc_unget_pcm_data(PCM_CHUNK_SIZE - chunk->num_pcm*4); | ||
452 | /* finish the chunk and store chunk size info */ | ||
453 | chunk->enc_size = WavpackFinishBlock(wpc); | ||
454 | ci->enc_finish_chunk(); | ||
455 | } | ||
456 | } | 452 | } |
453 | while (!abort_chunk && src < src_end); | ||
457 | 454 | ||
458 | ci->yield(); | 455 | if (!abort_chunk) |
456 | { | ||
457 | chunk->enc_data = dst; | ||
458 | if (chunk->num_pcm < PCM_SAMP_PER_CHUNK) | ||
459 | ci->enc_unget_pcm_data(PCM_CHUNK_SIZE - chunk->num_pcm*4); | ||
460 | /* finish the chunk and store chunk size info */ | ||
461 | chunk->enc_size = WavpackFinishBlock(wpc); | ||
462 | ci->enc_finish_chunk(); | ||
463 | } | ||
459 | } | 464 | } |
460 | 465 | ||
461 | /* reset parameters to initial state */ | ||
462 | ci->enc_set_parameters(NULL); | ||
463 | |||
464 | return CODEC_OK; | 466 | return CODEC_OK; |
465 | } /* codec_start */ | 467 | } |