Revision 848a5815 libavcodec/aac.c

View differences:

libavcodec/aac.c
91 91
#include <string.h>
92 92

  
93 93
#ifndef CONFIG_HARDCODED_TABLES
94
    static float ff_aac_ivquant_tab[IVQUANT_SIZE];
95 94
    static float ff_aac_pow2sf_tab[316];
96 95
#endif /* CONFIG_HARDCODED_TABLES */
97 96

  
......
403 402
    }
404 403

  
405 404
#ifndef CONFIG_HARDCODED_TABLES
406
    for (i = 1 - IVQUANT_SIZE/2; i < IVQUANT_SIZE/2; i++)
407
        ff_aac_ivquant_tab[i + IVQUANT_SIZE/2 - 1] =  cbrt(fabs(i)) * i;
408 405
    for (i = 0; i < 316; i++)
409 406
        ff_aac_pow2sf_tab[i] = pow(2, (i - 200)/4.);
410 407
#endif /* CONFIG_HARDCODED_TABLES */
......
469 466
}
470 467

  
471 468
/**
472
 * inverse quantization
473
 *
474
 * @param   a   quantized value to be dequantized
475
 * @return  Returns dequantized value.
476
 */
477
static inline float ivquant(int a) {
478
    if (a + (unsigned int)IVQUANT_SIZE/2 - 1 < (unsigned int)IVQUANT_SIZE - 1)
479
        return ff_aac_ivquant_tab[a + IVQUANT_SIZE/2 - 1];
480
    else
481
        return cbrtf(fabsf(a)) * a;
482
}
483

  
484
/**
485 469
 * Decode band types (section_data payload); reference: table 4.46.
486 470
 *
487 471
 * @param   band_type           array of the used band type
......
535 519
    int offset[3] = { global_gain, global_gain - 90, 100 };
536 520
    int noise_flag = 1;
537 521
    static const char *sf_str[3] = { "Global gain", "Noise gain", "Intensity stereo position" };
538
    ics->intensity_present = 0;
539 522
    for (g = 0; g < ics->num_window_groups; g++) {
540 523
        for (i = 0; i < ics->max_sfb;) {
541 524
            int run_end = band_type_run_end[idx];
......
543 526
                for(; i < run_end; i++, idx++)
544 527
                    sf[idx] = 0.;
545 528
            }else if((band_type[idx] == INTENSITY_BT) || (band_type[idx] == INTENSITY_BT2)) {
546
                ics->intensity_present = 1;
547 529
                for(; i < run_end; i++, idx++) {
548 530
                    offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
549 531
                    if(offset[2] > 255U) {
......
585 567
/**
586 568
 * Decode pulse data; reference: table 4.7.
587 569
 */
588
static void decode_pulses(Pulse * pulse, GetBitContext * gb) {
570
static void decode_pulses(Pulse * pulse, GetBitContext * gb, const uint16_t * swb_offset) {
589 571
    int i;
590 572
    pulse->num_pulse = get_bits(gb, 2) + 1;
591
    pulse->start = get_bits(gb, 6);
592
    for (i = 0; i < pulse->num_pulse; i++) {
593
        pulse->offset[i] = get_bits(gb, 5);
594
        pulse->amp   [i] = get_bits(gb, 4);
573
    pulse->pos[0]    = get_bits(gb, 5) + swb_offset[get_bits(gb, 6)];
574
    pulse->amp[0]    = get_bits(gb, 4);
575
    for (i = 1; i < pulse->num_pulse; i++) {
576
        pulse->pos[i] = get_bits(gb, 5) + pulse->pos[i-1];
577
        pulse->amp[i] = get_bits(gb, 4);
595 578
    }
596 579
}
597 580

  
......
614 597
}
615 598

  
616 599
/**
617
 * Add pulses with particular amplitudes to the quantized spectral data; reference: 4.6.3.3.
618
 *
619
 * @param   pulse   pointer to pulse data struct
620
 * @param   icoef   array of quantized spectral data
621
 */
622
static void add_pulses(int icoef[1024], const Pulse * pulse, const IndividualChannelStream * ics) {
623
    int i, off = ics->swb_offset[pulse->start];
624
    for (i = 0; i < pulse->num_pulse; i++) {
625
        int ic;
626
        off += pulse->offset[i];
627
        ic = (icoef[off] - 1)>>31;
628
        icoef[off] += (pulse->amp[i]^ic) - ic;
629
    }
630
}
631

  
632
/**
633 600
 * Decode an individual_channel_stream payload; reference: table 4.44.
634 601
 *
635 602
 * @param   common_window   Channels have independent [0], or shared [1], Individual Channel Stream information.
......
638 605
 * @return  Returns error status. 0 - OK, !0 - error
639 606
 */
640 607
static int decode_ics(AACContext * ac, SingleChannelElement * sce, GetBitContext * gb, int common_window, int scale_flag) {
641
    int icoeffs[1024];
642 608
    Pulse pulse;
643 609
    TemporalNoiseShaping * tns = &sce->tns;
644 610
    IndividualChannelStream * ics = &sce->ics;
645 611
    float * out = sce->coeffs;
646 612
    int global_gain, pulse_present = 0;
647 613

  
648
    /* These two assignments are to silence some GCC warnings about the
649
     * variables being used uninitialised when in fact they always are.
614
    /* This assignment is to silence a GCC warning about the variable being used
615
     * uninitialized when in fact it always is.
650 616
     */
651 617
    pulse.num_pulse = 0;
652
    pulse.start     = 0;
653 618

  
654 619
    global_gain = get_bits(gb, 8);
655 620

  
......
670 635
                av_log(ac->avccontext, AV_LOG_ERROR, "Pulse tool not allowed in eight short sequence.\n");
671 636
                return -1;
672 637
            }
673
            decode_pulses(&pulse, gb);
638
            decode_pulses(&pulse, gb, ics->swb_offset);
674 639
        }
675 640
        if ((tns->present = get_bits1(gb)) && decode_tns(ac, tns, gb, ics))
676 641
            return -1;
......
680 645
        }
681 646
    }
682 647

  
683
    if (decode_spectrum(ac, icoeffs, gb, ics, sce->band_type) < 0)
648
    if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present, &pulse, ics, sce->band_type) < 0)
684 649
        return -1;
685
    if (pulse_present)
686
        add_pulses(icoeffs, &pulse, ics);
687
    dequant(ac, out, icoeffs, sce->sf, ics, sce->band_type);
688 650
    return 0;
689 651
}
690 652

  
......
722 684
    if (common_window && ms_present)
723 685
        apply_mid_side_stereo(cpe);
724 686

  
725
    if (cpe->ch[1].ics.intensity_present)
726
        apply_intensity_stereo(cpe, ms_present);
687
    apply_intensity_stereo(cpe, ms_present);
727 688
    return 0;
728 689
}
729 690

  
......
906 867
    float * in = sce->coeffs;
907 868
    float * out = sce->ret;
908 869
    float * saved = sce->saved;
909
    const float * lwindow      = ics->use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_aac_sine_long_1024;
910
    const float * swindow      = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_aac_sine_short_128;
911
    const float * lwindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_aac_sine_long_1024;
912
    const float * swindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_short_128 : ff_aac_sine_short_128;
870
    const float * lwindow      = ics->use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024;
871
    const float * swindow      = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128;
872
    const float * lwindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024;
873
    const float * swindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128;
913 874
    float * buf = ac->buf_mdct;
914 875
    int i;
915 876

  
......
1093 1054
    if (!ac->is_saved) {
1094 1055
        ac->is_saved = 1;
1095 1056
        *data_size = 0;
1096
        return 0;
1057
        return buf_size;
1097 1058
    }
1098 1059

  
1099 1060
    data_size_tmp = 1024 * avccontext->channels * sizeof(int16_t);

Also available in: Unified diff