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0/9.0, -6.0/9.0, 4.0/9.0, 8.0/9.0, -4.0/9.0, 4.0/9.0, 8.0/9.0, -2.0/9.0, 4.0/9.0, 8.0/9.0, 0.0, 4.0/9.0, 8.0/9.0, 2.0/9.0, 4.0/9.0, 8.0/9.0, 4.0/9.0, 4.0/9.0, 8.0/9.0, 6.0/9.0, 4.0/9.0, 8.0/9.0, 8.0/9.0, 4.0/9.0, 8.0/9.0, -8.0/9.0, 6.0/9.0, 8.0/9.0, -6.0/9.0, 6.0/9.0, 8.0/9.0, -4.0/9.0, 6.0/9.0, 8.0/9.0, -2.0/9.0, 6.0/9.0, 8.0/9.0, 0.0, 6.0/9.0, 8.0/9.0, 2.0/9.0, 6.0/9.0, 8.0/9.0, 4.0/9.0, 6.0/9.0, 8.0/9.0, 6.0/9.0, 6.0/9.0, 8.0/9.0, 8.0/9.0, 6.0/9.0, 8.0/9.0, -8.0/9.0, 8.0/9.0, 8.0/9.0, -6.0/9.0, 8.0/9.0, 8.0/9.0, -4.0/9.0, 8.0/9.0, 8.0/9.0, -2.0/9.0, 8.0/9.0, 8.0/9.0, 0.0, 8.0/9.0, 8.0/9.0, 2.0/9.0, 8.0/9.0, 8.0/9.0, 4.0/9.0, 8.0/9.0, 8.0/9.0, 6.0/9.0, 8.0/9.0, 8.0/9.0, 8.0/9.0, 8.0/9.0, 8.0/9.0};// data taken from ISO/IEC DIS 11172, Annexes 3-B.2[abcd] and 3-B.4:// subbands 0-2 in tables 3-B.2a and 2b: (index is allocation)static const uint32 table_ab1_codelength[16] = // bits per codeword{ 0, 5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };static const real *table_ab1_groupingtables[16] = // pointer to sample grouping table, or NULL-pointer if ungrouped{ 0, grouping_5bits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };static const real table_ab1_factor[16] = // factor for requantization: (real)sample * factor - 1.0 gives requantized sample{ 0.0, 1.0/2.0, 1.0/4.0, 1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0, 1.0/128.0, 1.0/256.0, 1.0/512.0, 1.0/1024.0, 1.0/2048.0, 1.0/4096.0, 1.0/8192.0, 1.0/16384.0, 1.0/32768.0 };static const real table_ab1_c[16] = // factor c for requantization from table 3-B.4{ 0.0, 1.33333333333, 1.14285714286, 1.06666666666, 1.03225806452, 1.01587301587, 1.00787401575, 1.00392156863, 1.00195694716, 1.00097751711, 1.00048851979, 1.00024420024, 1.00012208522, 1.00006103888, 1.00003051851, 1.00001525902 };static const real table_ab1_d[16] = // addend d for requantization from table 3-B.4{ 0.0, 0.50000000000, 0.25000000000, 0.12500000000, 0.06250000000, 0.03125000000, 0.01562500000, 0.00781250000, 0.00390625000, 0.00195312500, 0.00097656250, 0.00048828125, 0.00024414063, 0.00012207031, 0.00006103516, 0.00003051758 };// subbands 3-... tables 3-B.2a and 2b:static const real *table_ab234_groupingtables[16] ={ 0, grouping_5bits, grouping_7bits, 0, grouping_10bits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };// subbands 3-10 in tables 3-B.2a and 2b:static const uint32 table_ab2_codelength[16] ={ 0, 5, 7, 3, 10, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16 };static const real table_ab2_factor[16] ={ 0.0, 1.0/2.0, 1.0/4.0, 1.0/4.0, 1.0/8.0, 1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0, 1.0/128.0, 1.0/256.0, 1.0/512.0, 1.0/1024.0, 1.0/2048.0, 1.0/4096.0, 1.0/32768.0 };static const real table_ab2_c[16] ={ 0.0, 1.33333333333, 1.60000000000, 1.14285714286, 1.77777777777, 1.06666666666, 1.03225806452, 1.01587301587, 1.00787401575, 1.00392156863, 1.00195694716, 1.00097751711, 1.00048851979, 1.00024420024, 1.00012208522, 1.00001525902 };static const real table_ab2_d[16] ={ 0.0, 0.50000000000, 0.50000000000, 0.25000000000, 0.50000000000, 0.12500000000, 0.06250000000, 0.03125000000, 0.01562500000, 0.00781250000, 0.00390625000, 0.00195312500, 0.00097656250, 0.00048828125, 0.00024414063, 0.00003051758 };// subbands 11-22 in tables 3-B.2a and 2b:static const uint32 table_ab3_codelength[8] = { 0, 5, 7, 3, 10, 4, 5, 16 };static const real table_ab3_factor[8] ={ 0.0, 1.0/2.0, 1.0/4.0, 1.0/4.0, 1.0/8.0, 1.0/8.0, 1.0/16.0, 1.0/32768.0 };static const real table_ab3_c[8] ={ 0.0, 1.33333333333, 1.60000000000, 1.14285714286, 1.77777777777, 1.06666666666, 1.03225806452, 1.00001525902 };static const real table_ab3_d[8] ={ 0.0, 0.50000000000, 0.50000000000, 0.25000000000, 0.50000000000, 0.12500000000, 0.06250000000, 0.00003051758 };// subbands 23-... in tables 3-B.2a and 2b:static const uint32 table_ab4_codelength[4] = { 0, 5, 7, 16 };static const real table_ab4_factor[8] = { 0.0, 1.0/2.0, 1.0/4.0, 1.0/32768.0 };static const real table_ab4_c[4] = { 0.0, 1.33333333333, 1.60000000000, 1.00001525902 };static const real table_ab4_d[4] = { 0.0, 0.50000000000, 0.50000000000, 0.00003051758 };// subbands in tables 3-B.2c and 2d:static const uint32 table_cd_codelength[16] ={ 0, 5, 7, 10, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };static const real *table_cd_groupingtables[16] ={ 0, grouping_5bits, grouping_7bits, grouping_10bits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };static const real table_cd_factor[16] ={ 0.0, 1.0/2.0, 1.0/4.0, 1.0/8.0, 1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0, 1.0/128.0, 1.0/256.0, 1.0/512.0, 1.0/1024.0, 1.0/2048.0, 1.0/4096.0, 1.0/8192.0, 1.0/16384.0 };static const real table_cd_c[16] ={ 0.0, 1.33333333333, 1.60000000000, 1.77777777777, 1.06666666666, 1.03225806452, 1.01587301587, 1.00787401575, 1.00392156863, 1.00195694716, 1.00097751711, 1.00048851979, 1.00024420024, 1.00012208522, 1.00006103888, 1.00003051851 };static const real table_cd_d[16] ={ 0.0, 0.50000000000, 0.50000000000, 0.50000000000, 0.12500000000, 0.06250000000, 0.03125000000, 0.01562500000, 0.00781250000, 0.00390625000, 0.00195312500, 0.00097656250, 0.00048828125, 0.00024414063, 0.00012207031, 0.00006103516 };/**********************/ // used for single channel mode/*** Standard Class ***/ // and in derived class for intensity/**********************/ // stereo modeSubbandLayer2::SubbandLayer2(uint32 subbandnumber){ this->subbandnumber = subbandnumber; groupnumber = samplenumber = 0;}uint32 SubbandLayer2::get_allocationlength(Header *header){ if (header->version() == MPEG1) { uint32 channel_bitrate = header->bitrate_index(); // calculate bitrate per channel: if (header->mode() != single_channel) if (channel_bitrate == 4) channel_bitrate = 1; else channel_bitrate -= 4; if (channel_bitrate == 1 || channel_bitrate == 2) // table 3-B.2c or 3-B.2d if (subbandnumber <= 1) return 4; else return 3; else // tables 3-B.2a or 3-B.2b if (subbandnumber <= 10) return 4; else if (subbandnumber <= 22) return 3; else return 2; } else { // MPEG-2 LSF -- Jeff // table B.1 of ISO/IEC 13818-3 if (subbandnumber <= 3) return 4; else if (subbandnumber <= 10) return 3; else return 2; }}void SubbandLayer2::prepare_sample_reading(Header *header, uint32 allocation, const real **groupingtable, real *factor, uint32 *codelength, real *c, real *d){ uint32 channel_bitrate = header->bitrate_index(); // calculate bitrate per channel: if (header->mode() != single_channel) if (channel_bitrate == 4) channel_bitrate = 1; else channel_bitrate -= 4; if (channel_bitrate == 1 || channel_bitrate == 2) { // table 3-B.2c or 3-B.2d *groupingtable = table_cd_groupingtables[allocation]; *factor = table_cd_factor[allocation]; *codelength = table_cd_codelength[allocation]; *c = table_cd_c[allocation]; *d = table_cd_d[allocation]; } else { // tables 3-B.2a or 3-B.2b if (subbandnumber <= 2) { *groupingtable = table_ab1_groupingtables[allocation]; *factor = table_ab1_factor[allocation]; *codelength = table_ab1_codelength[allocation]; *c = table_ab1_c[allocation]; *d = table_ab1_d[allocation]; } else { *groupingtable = table_ab234_groupingtables[allocation]; if (subbandnumber <= 10) { *factor = table_ab2_factor[allocation]; *codelength = table_ab2_codelength[allocation]; *c = table_ab2_c[allocation]; *d = table_ab2_d[allocation]; } else if (subbandnumber <= 22) { *factor = table_ab3_factor[allocation]; *codelength = table_ab3_codelength[allocation]; *c = table_ab3_c[allocation]; *d = table_ab3_d[allocation]; } else { *factor = table_ab4_factor[allocation]; *codelength = table_ab4_codelength[allocation]; *c = table_ab4_c[allocation]; *d = table_ab4_d[allocation]; } } }}void SubbandLayer2::read_allocation(Ibitstream *stream, Header *header, Crc16 *crc){ register uint32 length = get_allocationlength(header); allocation = stream->get_bits(length); if (crc) crc->add_bits(allocation, length);}void SubbandLayer2::read_scalefactor_selection(Ibitstream *stream, Crc16 *crc){ if (allocation) { scfsi = stream->get_bits(2); if (crc) crc->add_bits(scfsi, 2); }}void SubbandLayer2::read_scalefactor(Ibitstream *stream, Header *header){ if (allocation) { switch (scfsi) { case 0: scalefactor1 = scalefactors[stream->get_bits(6)]; scalefactor2 = scalefactors[stream->get_bits(6)]; scalefactor3 = scalefactors[stream->get_bits(6)]; break; case 1: scalefactor1 = scalefactor2 = scalefactors[stream->get_bits(6)]; scalefactor3 = scalefactors[stream->get_bits(6)]; break; case 2: scalefactor1 = scalefactor2 = scalefactor3 = scalefactors[stream->get_bits(6)]; break; case 3: scalefactor1 = scalefactors[stream->get_bits(6)]; scalefactor2 = scalefactor3 = scalefactors[stream->get_bits(6)]; break; } prepare_sample_reading(header, allocation, &groupingtable, &factor, &codelength, &c, &d); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -