示例#1
0
static uint8_t calc_sbr_tables(sbr_info *sbr, uint8_t start_freq, uint8_t stop_freq,
                               uint8_t samplerate_mode, uint8_t freq_scale,
                               uint8_t alter_scale, uint8_t xover_band)
{
    uint8_t result = 0;
    uint8_t k2;

    /* calculate the Master Frequency Table */
    sbr->k0 = qmf_start_channel(start_freq, samplerate_mode, sbr->sample_rate);
    k2 = qmf_stop_channel(stop_freq, sbr->sample_rate, sbr->k0);

    /* check k0 and k2 */
    if (sbr->sample_rate >= 48000)
    {
        if ((k2 - sbr->k0) > 32)
            result += 1;
    } else if (sbr->sample_rate <= 32000) {
        if ((k2 - sbr->k0) > 48)
            result += 1;
    } else { /* (sbr->sample_rate == 44100) */
        if ((k2 - sbr->k0) > 45)
            result += 1;
    }

    if (freq_scale == 0)
    {
        result += master_frequency_table_fs0(sbr, sbr->k0, k2, alter_scale);
    } else {
        result += master_frequency_table(sbr, sbr->k0, k2, freq_scale, alter_scale);
    }
    result += derived_frequency_table(sbr, xover_band, k2);

    result = (result > 0) ? 1 : 0;

    return result;
}
示例#2
0
/* table 2 */
uint8_t sbr_extension_data(bitfile *ld, sbr_info *sbr, uint16_t cnt)
{
    uint8_t result = 0;
    uint16_t num_align_bits = 0;
    uint16_t num_sbr_bits = (uint16_t)faad_get_processed_bits(ld);

#ifdef DRM
    if (!sbr->Is_DRM_SBR)
#endif
    {
        uint8_t bs_extension_type = (uint8_t)faad_getbits(ld, 4
            DEBUGVAR(1,198,"sbr_bitstream(): bs_extension_type"));

        if (bs_extension_type == EXT_SBR_DATA_CRC)
        {
            sbr->bs_sbr_crc_bits = (uint16_t)faad_getbits(ld, 10
                DEBUGVAR(1,199,"sbr_bitstream(): bs_sbr_crc_bits"));
        }
    }

    sbr->bs_header_flag = faad_get1bit(ld
        DEBUGVAR(1,200,"sbr_bitstream(): bs_header_flag"));

    if (sbr->bs_header_flag)
        sbr_header(ld, sbr);

    /* Reset? */
    sbr_reset(sbr);

    /* first frame should have a header */
    //if (!(sbr->frame == 0 && sbr->bs_header_flag == 0))
    if (sbr->header_count != 0)
    {
        if (sbr->Reset || (sbr->bs_header_flag && sbr->just_seeked))
        {
            uint8_t k2;

            /* calculate the Master Frequency Table */
            sbr->k0 = qmf_start_channel(sbr->bs_start_freq, sbr->bs_samplerate_mode,
                sbr->sample_rate);
            k2 = qmf_stop_channel(sbr->bs_stop_freq, sbr->sample_rate, sbr->k0);

            /* check k0 and k2 */
            if (sbr->sample_rate >= 48000)
            {
                if ((k2 - sbr->k0) > 32)
                    result += 1;
            } else if (sbr->sample_rate <= 32000) {
                if ((k2 - sbr->k0) > 48)
                    result += 1;
            } else { /* (sbr->sample_rate == 44100) */
                if ((k2 - sbr->k0) > 45)
                    result += 1;
            }

            if (sbr->bs_freq_scale == 0)
            {
                result += master_frequency_table_fs0(sbr, sbr->k0, k2,
                    sbr->bs_alter_scale);
            } else {
                result += master_frequency_table(sbr, sbr->k0, k2, sbr->bs_freq_scale,
                    sbr->bs_alter_scale);
            }
            result += derived_frequency_table(sbr, sbr->bs_xover_band, k2);

            result = (result > 0) ? 1 : 0;
        }

        if (result == 0)
            result = sbr_data(ld, sbr);
    } else {
        result = 1;
    }

#ifdef DRM
    if (!sbr->Is_DRM_SBR)
#endif
    {
        num_sbr_bits = (uint16_t)faad_get_processed_bits(ld) - num_sbr_bits;
        /* -4 does not apply, bs_extension_type is re-read in this function */
        num_align_bits = 8*cnt /*- 4*/ - num_sbr_bits;

        while (num_align_bits > 7)
        {
            faad_getbits(ld, 8
                DEBUGVAR(1,999,"sbr_bitstream(): num_align_bits"));
            num_align_bits -= 8;
        }
        faad_getbits(ld, num_align_bits
            DEBUGVAR(1,999,"sbr_bitstream(): num_align_bits"));
    }

    return result;
}