comparison alac.c @ 5359:4743a1e95531 libavcodec

Remove more code duplication. Based on a patch by Matthieu Castet.
author vitor
date Wed, 18 Jul 2007 06:06:21 +0000
parents f3a26c190f9a
children 6648c82e15c7
comparison
equal deleted inserted replaced
5358:f3a26c190f9a 5359:4743a1e95531
512 outputsamples = alac->setinfo_max_samples_per_frame; 512 outputsamples = alac->setinfo_max_samples_per_frame;
513 513
514 *outputsize = outputsamples * alac->bytespersample; 514 *outputsize = outputsamples * alac->bytespersample;
515 readsamplesize = alac->setinfo_sample_size - (wasted_bytes * 8) + channels - 1; 515 readsamplesize = alac->setinfo_sample_size - (wasted_bytes * 8) + channels - 1;
516 516
517 switch(channels) {
518 case 1: { /* 1 channel */
519 int ricemodifier;
520
521 if (!isnotcompressed) { 517 if (!isnotcompressed) {
522 /* so it is compressed */ 518 /* so it is compressed */
523 int16_t predictor_coef_table[32];
524 int predictor_coef_num;
525 int prediction_type;
526 int prediction_quantitization;
527 int i;
528
529 /* FIXME: skip 16 bits, not sure what they are. seem to be used in
530 * two channel case */
531 get_bits(&alac->gb, 8);
532 get_bits(&alac->gb, 8);
533
534 prediction_type = get_bits(&alac->gb, 4);
535 prediction_quantitization = get_bits(&alac->gb, 4);
536
537 ricemodifier = get_bits(&alac->gb, 3);
538 predictor_coef_num = get_bits(&alac->gb, 5);
539
540 /* read the predictor table */
541 for (i = 0; i < predictor_coef_num; i++) {
542 predictor_coef_table[i] = (int16_t)get_bits(&alac->gb, 16);
543 }
544
545 if (wasted_bytes) {
546 /* these bytes seem to have something to do with
547 * > 2 channel files.
548 */
549 av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented, unhandling of wasted_bytes\n");
550 }
551
552 bastardized_rice_decompress(alac,
553 alac->predicterror_buffer[0],
554 outputsamples,
555 readsamplesize,
556 alac->setinfo_rice_initialhistory,
557 alac->setinfo_rice_kmodifier,
558 ricemodifier * alac->setinfo_rice_historymult / 4,
559 (1 << alac->setinfo_rice_kmodifier) - 1);
560
561 if (prediction_type == 0) {
562 /* adaptive fir */
563 predictor_decompress_fir_adapt(alac->predicterror_buffer[0],
564 alac->outputsamples_buffer[0],
565 outputsamples,
566 readsamplesize,
567 predictor_coef_table,
568 predictor_coef_num,
569 prediction_quantitization);
570 } else {
571 av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type);
572 /* i think the only other prediction type (or perhaps this is just a
573 * boolean?) runs adaptive fir twice.. like:
574 * predictor_decompress_fir_adapt(predictor_error, tempout, ...)
575 * predictor_decompress_fir_adapt(predictor_error, outputsamples ...)
576 * little strange..
577 */
578 }
579
580 } else {
581 /* not compressed, easy case */
582 if (readsamplesize <= 16) {
583 int i;
584 for (i = 0; i < outputsamples; i++) {
585 int32_t audiobits = get_bits(&alac->gb, readsamplesize);
586
587 audiobits = SIGN_EXTENDED32(audiobits, readsamplesize);
588
589 alac->outputsamples_buffer[0][i] = audiobits;
590 }
591 } else {
592 int i;
593 for (i = 0; i < outputsamples; i++) {
594 int32_t audiobits;
595
596 audiobits = get_bits(&alac->gb, 16);
597 /* special case of sign extension..
598 * as we'll be ORing the low 16bits into this */
599 audiobits = audiobits << 16;
600 audiobits = audiobits >> (32 - readsamplesize);
601
602 audiobits |= get_bits(&alac->gb, readsamplesize - 16);
603
604 alac->outputsamples_buffer[0][i] = audiobits;
605 }
606 }
607 /* wasted_bytes = 0; // unused */
608 }
609
610 switch(alac->setinfo_sample_size) {
611 case 16: {
612 int i;
613 for (i = 0; i < outputsamples; i++) {
614 int16_t sample = alac->outputsamples_buffer[0][i];
615 ((int16_t*)outbuffer)[i * alac->numchannels] = sample;
616 }
617 break;
618 }
619 case 20:
620 case 24:
621 case 32:
622 av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size);
623 break;
624 default:
625 break;
626 }
627 break;
628 }
629 case 2: { /* 2 channels */
630
631 if (!isnotcompressed) {
632 /* compressed */
633 int16_t predictor_coef_table[channels][32]; 519 int16_t predictor_coef_table[channels][32];
634 int predictor_coef_num[channels]; 520 int predictor_coef_num[channels];
635 int prediction_type[channels]; 521 int prediction_type[channels];
636 int prediction_quantitization[channels]; 522 int prediction_quantitization[channels];
637 int ricemodifier[channels]; 523 int ricemodifier[channels];
653 predictor_coef_table[chan][i] = (int16_t)get_bits(&alac->gb, 16); 539 predictor_coef_table[chan][i] = (int16_t)get_bits(&alac->gb, 16);
654 } 540 }
655 } 541 }
656 542
657 if (wasted_bytes) { 543 if (wasted_bytes) {
658 /* see mono case */
659 av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented, unhandling of wasted_bytes\n"); 544 av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented, unhandling of wasted_bytes\n");
660 } 545 }
661 546
662 for (chan = 0; chan < channels; chan++) { 547 for (chan = 0; chan < channels; chan++) {
663 bastardized_rice_decompress(alac, 548 bastardized_rice_decompress(alac,
677 readsamplesize, 562 readsamplesize,
678 predictor_coef_table[chan], 563 predictor_coef_table[chan],
679 predictor_coef_num[chan], 564 predictor_coef_num[chan],
680 prediction_quantitization[chan]); 565 prediction_quantitization[chan]);
681 } else { 566 } else {
682 /* see mono case */
683 av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type[chan]); 567 av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type[chan]);
568 /* i think the only other prediction type (or perhaps this is just a
569 * boolean?) runs adaptive fir twice.. like:
570 * predictor_decompress_fir_adapt(predictor_error, tempout, ...)
571 * predictor_decompress_fir_adapt(predictor_error, outputsamples ...)
572 * little strange..
573 */
684 } 574 }
685 } 575 }
686 } else { 576 } else {
687 /* not compressed, easy case */ 577 /* not compressed, easy case */
688 if (alac->setinfo_sample_size <= 16) { 578 if (alac->setinfo_sample_size <= 16) {
690 for (chan = 0; chan < channels; chan++) { 580 for (chan = 0; chan < channels; chan++) {
691 for (i = 0; i < outputsamples; i++) { 581 for (i = 0; i < outputsamples; i++) {
692 int32_t audiobits; 582 int32_t audiobits;
693 583
694 audiobits = get_bits(&alac->gb, alac->setinfo_sample_size); 584 audiobits = get_bits(&alac->gb, alac->setinfo_sample_size);
695 audiobits = SIGN_EXTENDED32(audiobits, alac->setinfo_sample_size); 585 audiobits = SIGN_EXTENDED32(audiobits, readsamplesize);
586
696 alac->outputsamples_buffer[chan][i] = audiobits; 587 alac->outputsamples_buffer[chan][i] = audiobits;
697 } 588 }
698 } 589 }
699 } else { 590 } else {
700 int i, chan; 591 int i, chan;
701 for (chan = 0; chan < channels; chan++) { 592 for (chan = 0; chan < channels; chan++) {
702 for (i = 0; i < outputsamples; i++) { 593 for (i = 0; i < outputsamples; i++) {
703 int32_t audiobits; 594 int32_t audiobits;
704 595
705 audiobits = get_bits(&alac->gb, 16); 596 audiobits = get_bits(&alac->gb, 16);
597 /* special case of sign extension..
598 * as we'll be ORing the low 16bits into this */
706 audiobits = audiobits << 16; 599 audiobits = audiobits << 16;
707 audiobits = audiobits >> (32 - alac->setinfo_sample_size); 600 audiobits = audiobits >> (32 - alac->setinfo_sample_size);
708 audiobits |= get_bits(&alac->gb, alac->setinfo_sample_size - 16); 601 audiobits |= get_bits(&alac->gb, alac->setinfo_sample_size - 16);
709 602
710 alac->outputsamples_buffer[chan][i] = audiobits; 603 alac->outputsamples_buffer[chan][i] = audiobits;
716 interlacing_leftweight = 0; 609 interlacing_leftweight = 0;
717 } 610 }
718 611
719 switch(alac->setinfo_sample_size) { 612 switch(alac->setinfo_sample_size) {
720 case 16: { 613 case 16: {
614 if (channels == 2) {
721 deinterlace_16(alac->outputsamples_buffer[0], 615 deinterlace_16(alac->outputsamples_buffer[0],
722 alac->outputsamples_buffer[1], 616 alac->outputsamples_buffer[1],
723 (int16_t*)outbuffer, 617 (int16_t*)outbuffer,
724 alac->numchannels, 618 alac->numchannels,
725 outputsamples, 619 outputsamples,
726 interlacing_shift, 620 interlacing_shift,
727 interlacing_leftweight); 621 interlacing_leftweight);
622 } else {
623 int i;
624 for (i = 0; i < outputsamples; i++) {
625 int16_t sample = alac->outputsamples_buffer[0][i];
626 ((int16_t*)outbuffer)[i * alac->numchannels] = sample;
627 }
628 }
728 break; 629 break;
729 } 630 }
730 case 20: 631 case 20:
731 case 24: 632 case 24:
732 case 32: 633 case 32:
734 break; 635 break;
735 default: 636 default:
736 break; 637 break;
737 } 638 }
738 639
739 break;
740 }
741 }
742 640
743 return input_buffer_size; 641 return input_buffer_size;
744 } 642 }
745 643
746 static int alac_decode_init(AVCodecContext * avctx) 644 static int alac_decode_init(AVCodecContext * avctx)