⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 layer3.cpp

📁 一个自己编制的基于pocketPC的mp3播放器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
								sfb = -10;								lines = -10;							}							lines--;							i--;						} // while (lines > 0)					} // for (sfb=12 ...					sfb = sfbcnt + 1;					if (sfb > max_sfb)						max_sfb = sfb;					while(sfb < 12) {               	temp = sfBandIndex[sfreq].s[sfb];               	sb   = sfBandIndex[sfreq].s[sfb+1] - temp;                  i    = (temp << 2) - temp + j * sb;						for ( ; sb > 0; sb--) {                  	is_pos[i] = scalefac[1].s[j][sfb];							if (is_pos[i] != 7)                     	if (lsf)                           i_stereo_k_values(is_pos[i], io_type, i);                        else                        	is_ratio[i] = TAN12[is_pos[i]];							i++;						} // for (; sb>0...						sfb++;					} // while (sfb < 12)					sfb = sfBandIndex[sfreq].s[10];               sb  = sfBandIndex[sfreq].s[11] - sfb;               sfb = (sfb << 2) - sfb + j * sb;               temp  = sfBandIndex[sfreq].s[11];               sb = sfBandIndex[sfreq].s[12] - temp;               i = (temp << 2) - temp + j * sb;					for (; sb > 0; sb--) {               	is_pos[i] = is_pos[sfb];		            if (lsf) {		               k[0][i] = k[0][sfb];				         k[1][i] = k[1][sfb];		            } else {     						is_ratio[i] = is_ratio[sfb];                  }						i++;					} // for (; sb > 0 ...				 }				 if (max_sfb <= 3) {                i = 2;					 ss = 17;					 sb = -1;					 while (i >= 0) {                	if (ro[1][i][ss] != 0.0f) {                   	 sb = (i<<4) + (i<<1) + ss;							 i = -1;						} else {                      ss--;							 if (ss < 0) {                         i--;								 ss = 17;							 }						} // if (ro ...					 } // while (i>=0)					 i = 0;					 while (sfBandIndex[sfreq].l[i] <= sb)						 i++;					 sfb = i;					 i = sfBandIndex[sfreq].l[i];					 for (; sfb<8; sfb++) {                   sb = sfBandIndex[sfreq].l[sfb+1]-sfBandIndex[sfreq].l[sfb];						 for (; sb>0; sb--) {                      is_pos[i] = scalefac[1].l[sfb];                   	 if (is_pos[i] != 7)	                      if (lsf)                           i_stereo_k_values(is_pos[i], io_type, i);                         else                        	is_ratio[i] = TAN12[is_pos[i]];							 i++;						 } // for (; sb>0 ...					 } // for (; sfb<8 ...				 } // for (j=0 ...			} else { // if (gr_info->mixed_block_flag)         	for (uint32 j=0; j<3; j++) {            	int32 sfbcnt;					sfbcnt = -1;					for( sfb=12; sfb >=0; sfb-- )					{						temp = sfBandIndex[sfreq].s[sfb];                  lines = sfBandIndex[sfreq].s[sfb+1] - temp;                  i = (temp << 2) - temp + (j+1) * lines - 1;						while (lines > 0) {							if (ro[1][ss_div[i]][ss_mod[i]] != 0.0f) {                     	sfbcnt = sfb;								sfb = -10;								lines = -10;							}							lines--;							i--;						} // while (lines > 0) */					} // for (sfb=12 ...					sfb = sfbcnt + 1;					while(sfb<12) {						temp = sfBandIndex[sfreq].s[sfb];                  sb   = sfBandIndex[sfreq].s[sfb+1] - temp;                  i    = (temp << 2) - temp + j * sb;						for ( ; sb > 0; sb--) {                  	is_pos[i] = scalefac[1].s[j][sfb];							if (is_pos[i] != 7)	                      if (lsf)                           i_stereo_k_values(is_pos[i], io_type, i);                         else                        	is_ratio[i] = TAN12[is_pos[i]];							i++;						} // for (; sb>0 ...						sfb++;					} // while (sfb<12)					temp = sfBandIndex[sfreq].s[10];               temp2= sfBandIndex[sfreq].s[11];               sb   = temp2 - temp;               sfb  = (temp << 2) - temp + j * sb;               sb   = sfBandIndex[sfreq].s[12] - temp2;               i    = (temp2 << 2) - temp2 + j * sb;					for (; sb>0; sb--) {               	is_pos[i] = is_pos[sfb];		            if (lsf) {		               k[0][i] = k[0][sfb];				         k[1][i] = k[1][sfb];      		      } else {               		is_ratio[i] = is_ratio[sfb];                  }						i++;					} // for (; sb>0 ...				} // for (sfb=12			} // for (j=0 ...		} else { // if (gr_info->window_switching_flag ...      	i = 31;			ss = 17;			sb = 0;			while (i >= 0) {         	if (ro[1][i][ss] != 0.0f) {            	sb = (i<<4) + (i<<1) + ss;					i = -1;				} else {            	ss--;					if (ss < 0) {               	i--;						ss = 17;					}				}			}			i = 0;			while (sfBandIndex[sfreq].l[i] <= sb)				i++;			sfb = i;			i = sfBandIndex[sfreq].l[i];			for (; sfb<21; sfb++) {         	sb = sfBandIndex[sfreq].l[sfb+1] - sfBandIndex[sfreq].l[sfb];         	for (; sb > 0; sb--) {            	is_pos[i] = scalefac[1].l[sfb];					if (is_pos[i] != 7)                  if (lsf)                     i_stereo_k_values(is_pos[i], io_type, i);                  else                   	is_ratio[i] = TAN12[is_pos[i]];					i++;				}			}			sfb = sfBandIndex[sfreq].l[20];			for (sb = 576 - sfBandIndex[sfreq].l[21]; (sb > 0) && (i<576); sb--)			{         	is_pos[i] = is_pos[sfb]; // error here : i >=576            if (lsf) {               k[0][i] = k[0][sfb];		         k[1][i] = k[1][sfb];            } else {  					is_ratio[i] = is_ratio[sfb];            }				i++;			} // if (gr_info->mixed_block_flag)		} // if (gr_info->window_switching_flag ...	} // if (i_stereo)   	i = 0;		for(sb=0;sb<SBLIMIT;sb++)			for(ss=0;ss<SSLIMIT;ss++) {				if (is_pos[i] == 7) {					if (ms_stereo) {						lr[0][sb][ss] = (ro[0][sb][ss]+ro[1][sb][ss]) * 0.707106781f;						lr[1][sb][ss] = (ro[0][sb][ss]-ro[1][sb][ss]) * 0.707106781f;					} else {						lr[0][sb][ss] = ro[0][sb][ss];						lr[1][sb][ss] = ro[1][sb][ss];					}				}				else if (i_stereo) {            	if (lsf) {                  lr[0][sb][ss] = ro[0][sb][ss] * k[0][i];                  lr[1][sb][ss] = ro[0][sb][ss] * k[1][i];               } else {               	lr[1][sb][ss] = ro[0][sb][ss] / (real) (1 + is_ratio[i]);	  				   lr[0][sb][ss] = lr[1][sb][ss] * is_ratio[i];               }				}/*				else {					printf("Error in stereo processing\n");				} */            i++;			}    } // channels == 2}void LayerIII_Decoder::antialias(uint32 ch, uint32 gr){	int32 sb18, ss, sb18lim;   gr_info_s *gr_info = &(si->ch[ch].gr[gr]);	// 31 alias-reduction operations between each pair of sub-bands	// with 8 butterflies between each pair	if  (gr_info->window_switching_flag && (gr_info->block_type == 2) &&		 !gr_info->mixed_block_flag )       return;	if (gr_info->window_switching_flag && gr_info->mixed_block_flag &&	    (gr_info->block_type == 2)) {      sb18lim = 18;	} else {		sb18lim = 558;   }   for (sb18=0; sb18 < sb18lim; sb18+=18) {      for (ss=0;ss<8;ss++) {      	int32 src_idx1 = sb18 + 17 - ss;         int32 src_idx2 = sb18 + 18 + ss;      	real bu = out_1d[src_idx1];			real bd = out_1d[src_idx2];			out_1d[src_idx1] = (bu * cs[ss]) - (bd * ca[ss]);			out_1d[src_idx2] = (bd * cs[ss]) + (bu * ca[ss]);      }   }}void LayerIII_Decoder::hybrid(uint32 ch, uint32 gr){	real rawout[36];   uint32 bt;   int32 sb18;   gr_info_s *gr_info = &(si->ch[ch].gr[gr]);   real *tsOut;   real *prvblk;   for(sb18=0;sb18<576;sb18+=18) {		bt = (gr_info->window_switching_flag && gr_info->mixed_block_flag &&				 (sb18 < 36)) ? 0 : gr_info->block_type;		tsOut = out_1d + sb18;		inv_mdct(tsOut, rawout, bt);		// overlap addition		prvblk = &prevblck[ch][sb18];	   tsOut[0]   = rawout[0]  + prvblk[0];	   prvblk[0]  = rawout[18];	   tsOut[1]   = rawout[1]  + prvblk[1];	   prvblk[1]  = rawout[19];	   tsOut[2]   = rawout[2]  + prvblk[2];	   prvblk[2]  = rawout[20];	   tsOut[3]   = rawout[3]  + prvblk[3];	   prvblk[3]  = rawout[21];	   tsOut[4]   = rawout[4]  + prvblk[4];	   prvblk[4]  = rawout[22];	   tsOut[5]   = rawout[5]  + prvblk[5];	   prvblk[5]  = rawout[23];	   tsOut[6]   = rawout[6]  + prvblk[6];	   prvblk[6]  = rawout[24];	   tsOut[7]   = rawout[7]  + prvblk[7];	   prvblk[7]  = rawout[25];	   tsOut[8]   = rawout[8]  + prvblk[8];	   prvblk[8]  = rawout[26];	   tsOut[9]   = rawout[9]  + prvblk[9];	   prvblk[9]  = rawout[27];   	tsOut[10]  = rawout[10] + prvblk[10];   	prvblk[10] = rawout[28];   	tsOut[11]  = rawout[11] + prvblk[11];      prvblk[11] = rawout[29];   	tsOut[12]  = rawout[12] + prvblk[12];   	prvblk[12] = rawout[30];   	tsOut[13]  = rawout[13] + prvblk[13];   	prvblk[13] = rawout[31];   	tsOut[14]  = rawout[14] + prvblk[14];   	prvblk[14] = rawout[32];   	tsOut[15]  = rawout[15] + prvblk[15];   	prvblk[15] = rawout[33];   	tsOut[16]  = rawout[16] + prvblk[16];   	prvblk[16] = rawout[34];   	tsOut[17]  = rawout[17] + prvblk[17];   	prvblk[17] = rawout[35];   }}void LayerIII_Decoder::do_downmix(){	for (uint32 sb=0; sb<SSLIMIT; sb++) {   	for (uint32 ss=0; ss<SSLIMIT; ss+=3) {      	lr[0][sb][ss]   = (lr[0][sb][ss]   + lr[1][sb][ss])   * 0.5f;      	lr[0][sb][ss+1] = (lr[0][sb][ss+1] + lr[1][sb][ss+1]) * 0.5f;      	lr[0][sb][ss+2] = (lr[0][sb][ss+2] + lr[1][sb][ss+2]) * 0.5f;      }   }}void LayerIII_Decoder::decode(){	 uint32 nSlots = header->slots();    uint32 flush_main;    uint32 gr, ch, ss, sb, sb18;    int32 main_data_end;	 int32 bytes_to_discard;    int32 i;	 get_side_info();    for (i=0; i<(long)nSlots; i++)    	br->hputbuf(stream->get_bits(8));    main_data_end = br->hsstell() >> 3; // of previous frame    if (flush_main = (br->hsstell() & 7)) {         br->hgetbits(8 - flush_main);			main_data_end++;	 }	 bytes_to_discard = frame_start - main_data_end							  - si->main_data_begin;	 frame_start += nSlots;    if (bytes_to_discard < 0)			return;	 if (main_data_end > 4096) {			frame_start -= 4096;			br->rewindNbytes(4096);	 }	 for (; bytes_to_discard > 0; bytes_to_discard--)    		br->hgetbits(8);	 for (gr=0;gr<max_gr;gr++) {			for (ch=0; ch<channels; ch++) {           part2_start = br->hsstell();           if (header->version() == MPEG1)				  get_scale_factors(ch, gr);           else  // MPEG-2 LSF              get_LSF_scale_factors(ch, gr);			  huffman_decode(ch, gr);			  dequantize_sample(ro[ch], ch, gr);			}         stereo(gr);         if ((which_channels == downmix) && (channels > 1))         	do_downmix();         for (ch=first_channel; ch<=last_channel; ch++) {         		reorder(lr[ch], ch, gr);					antialias(ch, gr);               hybrid(ch, gr);					for (sb18=18;sb18<576;sb18+=36) // Frequency inversion                   for (ss=1;ss<SSLIMIT;ss+=2)                  	  out_1d[sb18 + ss] = -out_1d[sb18 + ss];					if ((ch == 0) || (which_channels == right)) {					  for (ss=0;ss<SSLIMIT;ss++) { // Polyphase synthesis                  	sb = 0;                 		for (sb18=0; sb18<576; sb18+=18) {								 filter1->input_sample(out_1d[sb18+ss], sb);                         sb++;                     }                    	filter1->calculate_pcm_samples(buffer);					  }					} else {					  for (ss=0;ss<SSLIMIT;ss++) { // Polyphase synthesis                  	sb = 0;                 		for (sb18=0; sb18<576; sb18+=18) {								 filter2->input_sample(out_1d[sb18+ss], sb);                         sb++;                     }                    	filter2->calculate_pcm_samples(buffer);					  }               }			}	// channels	 }	// granule  	 buffer->write_buffer(1);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -