📄 mp3enc_quantization.cpp
字号:
/*////////////////////////////////////////////////////////////////////////////////// INTEL CORPORATION PROPRIETARY INFORMATION// This software is supplied under the terms of a license agreement or// nondisclosure agreement with Intel Corporation and may not be copied// or disclosed except in accordance with the terms of that agreement.// Copyright(c) 2002-2005 Intel Corporation. All Rights Reserved.//*/#include "umc_mp3_enc_int.h"namespace UMC {/******************************************************************************// Name:// chooseTableLong//// Description:// The function selects proper huffman table for part of spectrum and// calculate count of bits necessary to encoding//// Input Arguments:// EC - pointer to encoder context// gr - number of granule// ch - number of channel// pInput - pointer to array of quantized samples// length - count of samples in the input array which should be encoded// table - number of part of spectrum. can be 0,1,2.// (big values are divided on three part. each is coded by using different table)//// Output Arguments:// -//// Returns:// count of bits necessary to encoding//******************************************************************************/ char *tables_info_full[16] = { "\0", "\1\2\3\5\6\7\10\11\12\13\14\15\17", "\2\3\5\6\7\10\11\12\13\14\15\17", "\5\6\7\10\11\12\13\14\15\17", "\7\10\11\12\13\14\15\17", "\7\10\11\12\13\14\15\17", "\12\13\14\15\17", "\12\13\14\15\17", "\15\17", "\15\17", "\15\17", "\15\17", "\15\17", "\15\17", "\15\17", "\0\0" }; char *tables_info_short[16] = { "\0", "\1", "\2\3", "\5\6", "\7\10\11", "\7\10\11", "\12\13\14", "\12\13\14", "\15\17", "\15\17", "\15\17", "\15\17", "\15\17", "\15\17", "\15\17", "\0\0" }; int MP3EncoderInt::chooseTableLong(int gr, int ch, short *pInput, int length, int table) { int choice0, choice1, i, tbl; int sum0, sum1; short max; ippsMax_16s(pInput, length, &max); char *tables; char tbuf[3]; if (max == 0) return 0; choice0 = 0; choice1 = 0; sum0 = sum1 = 32767; if (max >= 15) {/* * try tables with linbits */ choice0 = 15; while (htables[choice0].mav_value < max) choice0++; choice1 = 24; while (htables[choice1].mav_value < max) choice1++; tables = tbuf; tbuf[0] = (char)choice0; tbuf[1] = (char)choice1; tbuf[2] = 0; } else { if (!quant_mode_fast) tables = tables_info_full[max]; else tables = tables_info_short[max]; } for (i = 0; (tbl = tables[i]) != 0; i++) { IppsVLCEncodeSpec_32s* VLCSpec; int linbits; VLCSpec = (IppsVLCEncodeSpec_32s*)(htables[tbl].phuftable); linbits = htables[tbl].linbits; if (linbits == 0) { short tmp_src[288], *q; int j; int shift = mp3enc_VLCShifts[tbl]; int offset = mp3enc_VLCOffsets[tbl]; q = pInput; for (j = 0; j < (length >> 1); j++) { tmp_src[j] = (short)((q[0] << shift) + (q[1] + offset)); q += 2; } ippsVLCCountBits_16s32s(tmp_src, length >> 1, &sum1, VLCSpec); } else { ippsVLCCountEscBits_MP3_16s32s(pInput, length, linbits, &sum1, VLCSpec); } if (sum1 <= sum0) { choice0 = tbl; sum0 = sum1; } } si_pTableSelect[gr][ch][table] = choice0; return sum0; }/******************************************************************************// Name:// calc_bits_long//// Description:////// Input Arguments:////// Output Arguments:////// Returns:////******************************************************************************/ int MP3EncoderInt::calcBitsLong(short *pInput, int gr, int ch) { int bits = 0; if (si_address[gr][ch][0] > 0) { bits += chooseTableLong(gr, ch, pInput, si_address[gr][ch][0], 0); } if (si_address[gr][ch][1] > si_address[gr][ch][0]) { bits += chooseTableLong(gr, ch, pInput + si_address[gr][ch][0], si_address[gr][ch][1] - si_address[gr][ch][0], 1); } if (si_bigVals[gr][ch] * 2 > si_address[gr][ch][1]) { bits += chooseTableLong(gr, ch, pInput + si_address[gr][ch][1], si_bigVals[gr][ch] * 2 - si_address[gr][ch][1], 2); } return bits; }/******************************************************************************// Name:// calc_bits//// Description:////// Input Arguments:////// Output Arguments:////// Returns:////******************************************************************************/ int MP3EncoderInt::calcBits(int gr, int ch, short *ipptmp0_576) { unsigned int zero_region = 576; unsigned int bigv_region = 576; int bits = 0; int sum0 = 0; int sum1 = 0; int i; unsigned int *sfb_long, *sfb_short; int p; int *ptr_int; sfb_long = mp3enc_sfBandIndex[header.samplingFreq].l; sfb_short = mp3enc_sfBandIndex[header.samplingFreq].s; if ((si_blockType[gr][ch] != 2)) { ptr_int = (int *)&quant_ix[gr][ch][zero_region - 2]; while(zero_region > 1 && (*ptr_int-- == 0)) zero_region -= 2; bigv_region = zero_region; while(bigv_region > 3) { int p0, p1, p2, p3; p0 = quant_ix[gr][ch][bigv_region - 4]; p1 = quant_ix[gr][ch][bigv_region - 3]; p2 = quant_ix[gr][ch][bigv_region - 2]; p3 = quant_ix[gr][ch][bigv_region - 1]; if ((p0 | p1 | p2 | p3) > 1) break; bigv_region -= 4; p = (p0 << 3) | (p1 << 2) | (p2 << 1) | (p3); sum0 += mp3enc_table32[3 * p + 1]; sum1 += mp3enc_table33[3 * p + 1]; } } si_count1[gr][ch] = (zero_region - bigv_region) >> 2; si_bigVals[gr][ch] = bigv_region >> 1; if (sum0 < sum1) { bits += sum0; si_cnt1TabSel[gr][ch] = 0; } else { bits += sum1; si_cnt1TabSel[gr][ch] = 1; } if (bigv_region) { if (si_winSwitch[gr][ch] == 0) { if (!quant_mode_fast) { int bits0, bits1, bits2; int index0, index1, index2, st_reg0 = 0, st_reg1 = 0; unsigned int reg1_end; int min_bits = 1 << 30, cur_bits; int reg0, reg1; int regmax = 0; int last_reg_bits[22]; for (i = 0; i < 22; i++) last_reg_bits[i] = 0; regmax = 0; while (sfb_long[regmax] < bigv_region)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -