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

📄 predisto.c

📁 ISO mp3 sources (distribution 10) Layer 1/2/3, C Source, 512 k Sources of the Mpeg 1,2 layer 1,2
💻 C
📖 第 1 页 / 共 3 页
字号:
/********************************************************************** * ISO MPEG Audio Subgroup Software Simulation Group (1996) * ISO 13818-3 MPEG-2 Audio Multichannel Encoder * * $Id: predisto.c 1.6 1996/02/12 07:13:35 rowlands Exp $ * * $Log: predisto.c $ * Revision 1.6  1996/02/12 07:13:35  rowlands * Release following Munich meeting * * Revision 1.5  1996/02/12 05:51:17  rowlands * Added verbosity switch to control text output. * Fixed uninitialized variable d in subband_quantization_pre. * * Revision 1.3.2.1  1995/11/06  04:19:12  rowlands * Received from Uwe Felderhoff (IRT) * * Revision 1.4  1995/08/14  08:06:01  tenkate * ML-LSF added Warner ten Kate 7/8/95 (Philips) * change alloc and sblimit into alloc_ml and sblimit_ml where appropriate * **********************************************************************/ /********************************************************************* *                                                                    * *                                                                    * *  MPEG/audio Phase 2 coding/decoding multichannel                   * *                                                                    * *                                                                    * *                                                                    * *  Version 4.0    Susanne Ritscher, IRT Munich                       * *                                                                    * *  9/20/93        Implemented Prediction written by                  * *                 Heiko Purnhagen,  Uni Hannover in                  * *                 new source-file called prediction.c                * *                                                                    * *                                                                    * *                                                                    * *  version 4.1    Susanne Ritscher, IRT Munich                       * *                                                                    * *  9/20/93        channel-switching is only performed at a           * *                 certain limit of TC_ALLOC dB, which is included    * *                 in encoder.h                                       * *                                                                    * * 01/16/94        prediction will not work with trans._pat._errsig   * *		   Have to do a new strategy with a new bal for       * *		   the add. channels                                  * *                                                                    * * 04/08/94	   started with predistortion                         * *                                                                    * * 06/28/94        started with predistortion according to the DIS    * *		   and the tc_table                                   * *                                                                    * *                                                                    * *  version 5.0    Susanne Ritscher,  IRT Munich                      * *                                                                    * *  7/12/94        bitstream according to DIS                         * *                 extension bitstream is working                     * *                 predistortion is working                           * *                                                                    * *  Version 1.1                                                       * *                                                                    * *  02/23/95	   Susanne Ritscher,  IRT Munich                      * *                 corrected some bugs                                * *                 extension bitstream is working                     * *                                                                    * *  Version 2.0                                                       * *                                                                    * *  01/28/97       Frans de Bont, Philips Sound & Vision, Eindhoven   * *		    - dynamic crosstalk working for all configurations* *		    - prediction working for all configurations	      * *		    - extension bitstream fixed			      * *		    - fully compliant to DIS 13818-3.2                * *                                                                    *				      *		     *********************************************************************/ /********************************************************************** *  *  This program computes the predistortion. *  The three additional channels are AFTER THE BITALLOCATION *  quantized and dequantized. With these dequantized samples *  the frontchannels are matriced again in order to dematrice them in a *  more exact way. This should improve the quality of matriced signals. *  *  In case of prediction the whole process of decoding predicted signals *  is worked off???? *  **************************************************************************/#include "common.h"#include "encoder.h"void predistortion(double (*sb_sample)[3][12][32], unsigned int (*scalar)[3][32], 		    unsigned int (*bit_alloc)[32], unsigned int (*subband)[3][12][32], 		    frame_params *fr_ps, double (*perm_smr)[32], unsigned int (*scfsi)[32], 		    int *adb, unsigned int (*scfsi_dyn)[32]){    double sbs_sample[7][3][12][SBLIMIT];  /*predistortion*/    int l, m, i, n, k;    int sblimit;    int ch, gr, sb;    int ad;    sblimit = fr_ps->sblimit;    l = 2; m = 7;        pre_quant(sbs_sample, l, m, sb_sample, scalar, bit_alloc, subband, fr_ps);	        matri(sbs_sample, fr_ps, sb_sample, scalar, sblimit, scfsi, scfsi_dyn,          bit_alloc, subband);    l = 0; m = 2;        /*II_scale_factor_calc(sb_sample,scalar,sblimit, l, m);*/    trans_pattern(scalar, scfsi, fr_ps,scfsi_dyn);          bit_all(perm_smr, scfsi, bit_alloc, adb, fr_ps);}static double snr[18] = { 0.00,  6.03, 11.80, 15.81, /* 0, 3, 5, 7 */			 19.03, 23.50, 29.82, 35.99, /* 9,15,31,63 */			 42.08, 48.13, 54.17, 60.20, /* 127, ...   */			 66.22, 72.25, 78.27, 84.29, /* 2047, ...  */			 90.31, 96.33};              /* 16383, ... *//* Multilingual TEST 17/03/1995 JMZ */int bit_all(double (*perm_smr)[32], unsigned int (*scfsi)[32], unsigned int (*bit_alloc)[32], int *adb, frame_params *fr_ps)                              /* minimum masking level *//* bit_all() recalculates allocation for compatible signals Lo and Ro *//* which are channels k==0 and k==1. This recalculation is performed  *//* because of signal modifications by predistortion.                  *//* WtK 7/8/95. Information from SR.                                   */                             {    int n_ml_ch = fr_ps->header->multiling_ch; 	/*JMZ 17/03/95 Multilingual */    int i, min_ch, min_sb, oth_ch, k, increment, scale, seli, ba, j, l;    int adb_hlp, adb_hlp1, adb_hlp2;    int bspl, bscf, bsel, ad, noisy_sbs;    int bspl_mpg1, bscf_mpg1, bsel_mpg1;    double mnr[14][SBLIMIT], small;				/*JMZ 17/03/95 Multilingual */    char used[14][SBLIMIT];						/*JMZ 17/03/95 Multilingual */    int stereo	= fr_ps->stereo;    int stereomc = fr_ps->stereomc;    int stereoaug = fr_ps->stereoaug;    int sblimit = fr_ps->sblimit;    int sblimit_mc = fr_ps->sblimit_mc;    int sblimit_ml = fr_ps->sblimit_ml;    int jsbound = fr_ps->jsbound;    al_table *alloc = fr_ps->alloc;    al_table *alloc_mc = fr_ps->alloc_mc;    al_table *alloc_ml = fr_ps->alloc_ml;    double dynsmr = 0.0;  /* border of SMR for dynamic datarate */    static char init= 0;    static int banc, berr;    int bbal, bancmc, pred, bancext, bbal_mpg1;    int ll, pci, adb_mpg1;    int bits = 0; /*bits already used for the front-channels*/    static int sfsPerScfsi[] = { 3,2,1,2 };    /* lookup # sfs per scfsi */        banc = 32; /* banc: bits for header */;    /* 960627 FdB reserve extra bits wrt bugs */    banc += 200;    if (fr_ps->header->error_protection)	berr = 16;    else	berr = 0; /* added 92-08-11 shn */    pred = 0;    bancmc = 0;    bancext = 0;    bbal = 0;    bbal_mpg1 = 0;    adb_mpg1 = bitrate[fr_ps->header->lay-1][fr_ps->header->bitrate_index] * 24;#ifdef DEBUGif (verbosity >= 3) printf("stereo+stereomc+stereoaug+n_ml_ch=%d\n", stereo+stereomc+stereoaug+n_ml_ch);#endif 	    if (fr_ps->header->mode == MPG_MD_STEREO)    {	for (i = 0; i < sblimit; ++i)	    bbal += (stereo) * (*alloc)[i][0].bits;	for (i = 0; i < sblimit_mc; ++i)	    bbal += (stereomc+stereoaug) * (*alloc)[i][0].bits;	for (i = 0; i < sblimit_ml; ++i)	    bbal += (n_ml_ch) * (*alloc_ml)[i][0].bits;    }	     if (fr_ps->header->mode == MPG_MD_JOINT_STEREO)    {	for (i = 0; i < jsbound; ++i)	    bbal += (stereo) * (*alloc)[i][0].bits;	for (i = jsbound; i < sblimit; ++i)	    bbal += (stereo-1) * (*alloc)[i][0].bits;	for (i = 0; i < sblimit_mc; ++i)	    bbal += (stereomc+stereoaug) * (*alloc)[i][0].bits;	for (i = 0; i < sblimit_ml; ++i)	    bbal += (n_ml_ch) * (*alloc_ml)[i][0].bits;    }    if (fr_ps->header->center == 3) bbal -= 41;     if (fr_ps->header->ext_bit_stream_present == 0)	bancmc += 35;      /* mc_header + crc + tc_sbgr_select+ dyn_cross_on + 			      mc_prediction_on  01/05/94,  SR  new! 05/04/94,  SR*/    else    {	bancmc += 43;			    	bancext = 40;    }      			        if (fr_ps->header->tc_sbgr_select == 0)	bancmc += 36;    else	bancmc += 3;	    if (fr_ps->header->dyn_cross_on == 1)	bancmc += 49;      /* now with dyn_cross_LR,  505/04/94,  SR*/    if (fr_ps->header->mc_prediction_on == 1)    {	for (i = 0; i < 8; i++)   /*now only 8 sb_groups, 05/04/94, SR*/	{	    bancmc += 1;	    if (fr_ps->header->mc_pred[i] == 1)		bancmc += n_pred_coef[fr_ps->header->dyn_cross[i]] * 2;	}	for (i = 0; i < 8; i++) 	    if (fr_ps->header->mc_pred[i] == 1)		for (j = 0; j < n_pred_coef[fr_ps->header->dyn_cross[i]]; j++)		    if (fr_ps->header->predsi[i][j] != 0)		    {			pred += 3;			for (pci = 0; pci < fr_ps->header->predsi[i][j]; pci++)			    pred += 8;		    }	    }  	    for (l = 0; l < sblimit; l++)	for (k = 0; k < 2; k++)	    used[k][l] = 0;        for (l = 0; l < SBLIMIT; l++)		  /* searching for the sb min SMR */    {	i = sbgrp[l];	for (j = stereo; j < stereo+stereomc+stereoaug; j++)	    if ((j < stereo && l < sblimit) ||		(j >= stereo && l < sblimit_mc))	    {		/* k = transmission_channel5[fr_ps->header->tc_alloc[i]][j]; */	  	k = transmission_channel (fr_ps, i, j);		if (j < stereo)		    bits += 12 * ((*alloc)[l][bit_alloc[k][l]].group *				  (*alloc)[l][bit_alloc[k][l]].bits);		else if (j < 7 || n_ml_ch == 0) /* Multichannel */ 		    bits += 12 * ((*alloc_mc)[l][bit_alloc[k][l]].group *				  (*alloc_mc)[l][bit_alloc[k][l]].bits);		else /* MultiLingual */ 		    bits += 12 * ((*alloc_ml)[l][bit_alloc[k][l]].group *				  (*alloc_ml)[l][bit_alloc[k][l]].bits);		if (bit_alloc[k][l] != 0)		{		    bits += 2;		    switch (scfsi[k][l])		    {			case 0: bits += 18; break;			case 1: bits += 12; break;					case 2: bits += 6; break;			case 3: bits += 12; break;				    }   		}	    }    }    for (i = 0; i < 12; i++)    {	if ((fr_ps->header->tc_alloc[i] == 1) || (fr_ps->header->tc_alloc[i] == 7))	{	    bits += 12 * ((*alloc)[l][bit_alloc[0][l]].group *			  (*alloc)[l][bit_alloc[0][l]].bits);	    if (bit_alloc[0][l] != 0)	    {		bits += 2;		switch(scfsi[0][l])		{		    case 0: bits += 18; break;		    case 1: bits += 12; break;				    case 2: bits += 6; break;		    case 3: bits += 12; break;				}   	    }	    used[0][l] = 2;	}	if ((fr_ps->header->tc_alloc[i] == 2) || (fr_ps->header->tc_alloc[i] == 6))	{	    bits += 12 * ((*alloc)[l][bit_alloc[1][l]].group *			  (*alloc)[l][bit_alloc[1][l]].bits);	    if (bit_alloc[1][l] != 0)	    {		bits += 2;		switch(scfsi[1][l])		{		    case 0: bits += 18; break;		    case 1: bits += 12; break;				    case 2: bits += 6; break;		    case 3: bits += 12; break;				}   	    }	    used[1][l] = 2;	}    }	      	if(fr_ps->header->ext_bit_stream_present == 0)    	    *adb -= bbal + berr + banc + bancmc + pred + bits;	else	{	    *adb = *adb - bbal - berr - banc - bancmc - pred - bits - 	    bancext - (fr_ps->header->n_ad_bytes * 8);	    for(i = 0; i < sblimit; ++i)		 bbal_mpg1 += 2 * (*alloc)[i][0].bits;	    adb_mpg1 -= bbal_mpg1 + berr + banc + bancmc +	     (fr_ps->header->n_ad_bytes * 8);	 }           ad = *adb; 	    for(l = 0;l < sblimit; l++)	    {		for( k = 0; k < 2; k++)		{				mnr[k][l]=snr[0]-perm_smr[k][l];				if(used[k][l] == 0)			        bit_alloc[k][l] = 0;		}			    }   /********************************************************************//* JMZ 08/03/1995 Multilingual */  	for (i = 0; i < sblimit_ml; i++) 		for (k = 7; k < 7+n_ml_ch; k++) 		{		mnr[k][i]=snr[0]-perm_smr[k][i];		 /* mask-to-noise-level = signal-to-noise-level - minimum-masking-*/		 /* threshold*/		bit_alloc[k][i] = 0;		used[k][i] = 0;		}/* JMZ 08/03/1995 Multilingual */   /********************************************************************/         	bspl = bscf = bsel = bspl_mpg1 = bscf_mpg1 = bsel_mpg1 = 0;     do  {	small = 999999.0;	min_sb = -1;	min_ch = -1;        for(i = 0; i < sblimit; i++)	{	     for( k = 0; k < 2; k++)		{		    if ((used[k][i] != 2) && (small > mnr[k][i])) 		    {			small = mnr[k][i];			min_sb = i;  min_ch = k;		    }		}  	 }	 

⌨️ 快捷键说明

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