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

📄 musicin.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 页 / 共 5 页
字号:
	        layer_names[info->lay-1], mode_names[info->mode],	        info->mode_ext, *psy);    if (info->bitrate_index != 0)    {	if (bitrate[info->lay-1][info->bitrate_index] == 1000)	    printf ("samp frq=%.1f kHz   total bitrate=dynamic bitrate\n",		    s_freq[info->sampling_frequency]);	else	    printf ("samp frq=%.1f kHz   mpeg1 bitrate=%d kbps\n",		    s_freq[info->sampling_frequency],		    bitrate[info->lay-1][info->bitrate_index]);	if (info->ext_bit_stream_present)	    printf ("ext bitrate=%d kbps\n", (int) (info->ext_length * s_freq[info->sampling_frequency] / 144));    }    if (info->multiling_ch > 0)    {        printf ("%d multilingual channels ", info->multiling_ch);        if (info->multiling_fs == 1)	    printf ("LSF coded.\n");        else	    printf ("full sample rate coded.\n");    }    else	printf ("No multilingual coding.\n");    printf ("de-emph=%d   c/right=%d   orig=%d   errprot=%d\n",            info->emphasis, info->copyright, info->original,            info->error_protection);    printf ("matrix=%d  center=%d  surround=%d  stereo=%d  stereomc=%d  stereoaug=%d\n",            info->matrix, info->center, info->surround,	    fr_ps->stereo, fr_ps->stereomc, fr_ps->stereoaug);    printf ("input file: '%s'   output file: '%s'\n", inPath, outPath);    fflush (stdout);} /************************************************************************/*/* main/*/* PURPOSE:  MPEG I Encoder supporting layers 1 and 2, and/* psychoacoustic models 1 (MUSICAM) and 2 (AT&T),now portated/* to multichannel (two front channels, one center and three surround/* channels. There are different possibilities to code the AIFF-signal,/* like coding only the surround channels or the front channels,/* different bitrates for front and surropund channels etc./* dec1992 sr./*/* SEMANTICS:  One overlapping frame of audio of up to 2 channels are/* processed at a time in the following order:/* (associated routines are in parentheses)/*/* 1.  Filter sliding window of data to get 32 subband/* samples per channel./* (window_subband,filter_subband)/*/* 2.  If joint stereo mode, combine left and right channels/* for subbands above #jsbound#./* (*_combine_LR)/*/* 3.  Calculate scalefactors for the frame, and if layer 2,/* also calculate scalefactor select information./* (*_scale_factor_calc)/*/* 4.  Calculate psychoacoustic masking levels using selected/* psychoacoustic model./* (*_Psycho_One, psycho_anal)/*/* 5.  Perform iterative bit allocation for subbands with low/* mask_to_noise ratios using masking levels from step 4./* (*_main_bit_allocation)/*/* 6.  If error protection flag is active, add redundancy for/* error protection./* (*_CRC_calc)/*/* 7.  Pack bit allocation, scalefactors, and scalefactor select/* information (layer 2) onto bitstream./* (*_encode_bit_alloc,*_encode_scale,II_transmission_pattern)/*/* 8.  Quantize subbands and pack them into bitstream/* (*_subband_quantization, *_sample_encoding)/*/************************************************************************/#ifdef MS_DOSextern unsigned _stklen = 16384;#endiftypedef double JSBS[2][3][12][SBLIMIT];typedef double IN[14][HAN_SIZE];		/* JMZ 08/03/1995 */typedef unsigned int SUB[14][3][12][SBLIMIT]; /* JMZ 08/03/1995 */typedef double SAM[12];typedef unsigned int LSB[12];main (int argc, char **argv){    double  sb_sample[14][3][12][SBLIMIT];	/* JMZ 08/03/1995 */    JSBS    *j_sample;    IN	    *win_que;    SUB	    *subband;    SAM	    *lfe_sample;    LSB	    *lfe_sbband;     frame_params fr_ps;    layer info;        char original_file_name[MAX_NAME_SIZE];    char encoded_file_name[MAX_NAME_SIZE];    char encoded_file_name_ext[MAX_NAME_SIZE];    char encoded_file_name_mpg[MAX_NAME_SIZE];    double *win_buf[14];				/* JMZ 08/03/1995 */    static double buffer[14][1152];			/* JMZ 08/03/1995 */			    double spiki[14][SBLIMIT];				/* JMZ 08/03/1995 */    static unsigned int bit_alloc[14][SBLIMIT], scfsi[14][SBLIMIT], scfsi_dyn[14][SBLIMIT];						/* JMZ 08/03/1995 */    static unsigned int scalar[14][3][SBLIMIT], j_scale[2][3][SBLIMIT],  scalar_dyn[14][3][SBLIMIT];    static double ltmin[14][SBLIMIT], lgmin[14][SBLIMIT], max_sc[14][SBLIMIT], smr[14][SBLIMIT];							/* JMZ 08/03/1995 */    static unsigned int lfe_alloc;    static unsigned int lfe_scalar;     FLOAT snr32[32];    short sam[14][1056];					/* JMZ 08/03/1995 */    double buffer_matr[14][1152];			/* JMZ 08/03/1995 */    int whole_SpF, extra_slot = 0;    double avg_slots_per_frame, frac_SpF, slot_lag;    int model, stereo, error_protection, stereomc, stereoaug;    static unsigned int crc, crcmc, crcaug, crcext;    int i, j, k, adb, p, l, m, lfe, s;    unsigned long bitsPerSlot, samplesPerFrame, frameNum = 0;    unsigned long frameBits, sentBits = 0;    unsigned long num_samples;    unsigned long num_samples_ml;	               /* 08/03/1995 JMZ Multilingual */    int odd_ml = 1;                                    /* LSF MultiLingual: audio inputting only at odd frames , WtK 7/8/95 */    int ml_eof = 0;                                    /* MultiLingual: frame loop stops if either audio or ML-file has been exhausted , WtK 7/8/95 */    IFF_AIFF aiff_ptr;    IFF_AIFF aiff_ptr_ml;	                       /* 08/03/1995 JMZ Multilingual */    int aiff = 0;                                      /* misused to indicate mc-input */    int byte_per_sample = 0;    int mat_mode = 0;    int aug_mat_mode = 0;    int cha_sw = -2;    int aug_cha_sw = 0;    int dyn_cr = 0;    int dyn_cr_LR = 0;    int aug_dyn_cr = 0;    int predis = 0;    int bit_rate = 0;    unsigned int crc_buffer[15];    int lfe_bits = 0;    int sentBits1, frameBits1;    int hi,  hu,  ho;/*    char *blubb = "rm ";*/	    char blubb[128];	/* Corrected BUG JMZ 29/03/1995*/    int  ancillaryUse = 0;  /* YBKim060695 ancillary */    #ifdef  PRINTOUT    int       loop_channel,loop_subband;        al_table  *loop_alloc; /* a pointer to a table */    sb_alloc  loop_struct; /* a structure of 4 int's */    alloc_ptr loop_str_ptr; /* a pointer to an sb_alloc structure */    float     loop_bits;#endif#ifdef  MACINTOSH    console_options.nrows = MAC_WINDOW_SIZE;    argc = ccommand(&argv);#endif    program_information();    /* Most large variables are declared dynamically to ensure       compatibility with smaller machines */    j_sample = (JSBS *) mem_alloc (sizeof (JSBS), "j_sample");       win_que = (IN *) mem_alloc (sizeof (IN), "Win_que");           subband = (SUB *) mem_alloc (sizeof (SUB),"subband");            lfe_sample = (SAM *) mem_alloc (sizeof (SAM), "lfe_sample");    lfe_sbband = (LSB *) mem_alloc (sizeof (LSB),"lfe_sbband");     /* clear buffers */    memset ((char *) buffer, 0, sizeof (buffer));    memset ((char *) bit_alloc, 0, sizeof (bit_alloc));    memset ((char *) scalar, 0, sizeof (scalar));    memset ((char *) j_scale, 0, sizeof (j_scale));    memset ((char *) scfsi, 0, sizeof (scfsi));    memset ((char *) ltmin, 0, sizeof (ltmin));    memset ((char *) lgmin, 0, sizeof (lgmin));    memset ((char *) max_sc, 0, sizeof (max_sc));    memset ((char *) snr32, 0, sizeof (snr32));    memset ((char *) sam, 0, sizeof (sam));     fr_ps.header = &info;    info.mode_ext = 0;    fr_ps.tab_num = -1;             /* no table loaded */    fr_ps.tab_num_mc = -1;    fr_ps.tab_num_ml = -1;    fr_ps.alloc = NULL;    fr_ps.alloc_mc = NULL;    fr_ps.alloc_ml = NULL;    info.version = MPEG_AUDIO_ID;    info.bitrate_index = 0;    info.lfe = 0;	    /* no low frequency effect channel present! */    info.center = 0;     info.surround = 0;     info.multiling_ch  = 0;    info.multiling_fs  = 0;    info.multiling_lay = 0;    info.matrix = 0;#ifdef Augmentation_7ch    info.aug_mtx_proc = 0;#endif    info.ext_bit_stream_present = 0;    info.n_ad_bytes = DFLT_NADB;    info.audio_mix = 0;    info.dyn_cross_LR = 0;    /* C out of Lo */    info.mc_prediction_on = 0;	           info.ext_length = 0;    info.ext_bit = 0;    info.copy_ident_bit = 0;    info.copy_ident_start = 0;    fr_ps.config = 0;    fr_ps.phantom_c = 0;    fr_ps.stereomc = 0;    fr_ps.stereoaug = 0;    programName = argv[0];    if (argc == 1)			    /* no command-line args */	obtain_parameters (&fr_ps, &model, &num_samples, &num_samples_ml, original_file_name,			   encoded_file_name, &aiff_ptr, &aiff_ptr_ml, &aiff, &byte_per_sample, 			   &mat_mode, &aug_mat_mode, &cha_sw, &aug_cha_sw,			   encoded_file_name_ext, &bit_rate, encoded_file_name_mpg,			   &dyn_cr, &dyn_cr_LR, &aug_dyn_cr, &ancillaryUse, &verbosity);    else        parse_args(argc, argv, &fr_ps, &model, &num_samples, &num_samples_ml, original_file_name,			   encoded_file_name, &aiff_ptr, &aiff_ptr_ml, &aiff, &byte_per_sample, 			   &mat_mode, &aug_mat_mode, &cha_sw, &aug_cha_sw,			   encoded_file_name_ext, &bit_rate, encoded_file_name_mpg,			   &dyn_cr, &dyn_cr_LR, &aug_dyn_cr, &ancillaryUse, &verbosity);    hdr_to_frps (&fr_ps);    if (aiff != 1) fr_ps.stereomc = 0;    print_config (&fr_ps, &model, &num_samples,		  original_file_name, encoded_file_name, &aiff);      stereo = fr_ps.stereo;    stereomc = fr_ps.stereomc;    stereoaug = fr_ps.stereoaug;    lfe = info.lfe;    error_protection = info.error_protection;     if (info.lay == 1) { bitsPerSlot = 32; samplesPerFrame = 384;  }    else               { bitsPerSlot = 8;  samplesPerFrame = 1152; }    /* Figure average number of 'slots' per frame. */    /* Bitrate means TOTAL for both channels, not per side. */    if (bit_rate == 0) bit_rate = bitrate[info.lay-1][info.bitrate_index];    if (verbosity >= 2) printf("bit_rate = %d\n", bit_rate);    fflush(stderr);        avg_slots_per_frame = ((double) samplesPerFrame / s_freq[info.sampling_frequency]) *			  ((double) bit_rate / (double) bitsPerSlot);    whole_SpF = (int) avg_slots_per_frame;	 /* Bytes per frame within datastream*/    if (verbosity >= 2)	printf ("slots/frame = %d\n", whole_SpF);    frac_SpF  = avg_slots_per_frame - (double) whole_SpF;    slot_lag  = -frac_SpF;    if (verbosity >= 2)	printf("frac SpF=%.3f, tot bit_rate=%d kbps, s freq=%.1f kHz\n",                frac_SpF, bit_rate, s_freq[info.sampling_frequency]);     if (frac_SpF != 0)    {	if (verbosity >= 2)	    printf ("Fractional number of slots, padding required\n");    }    else	info.padding = 0;#ifdef PRINTOUT    if (verbosity >= 3)    {	printf ("\nFrame ");	for (loop_subband = 0; loop_subband < SBLIMIT; loop_subband++)	    printf ("%3d",loop_subband);	printf ("\n");    }#endif     while (              ( get_audio (musicin, buffer, num_samples, stereo, &aiff_ptr,	                  stereomc, stereoaug, &fr_ps, &aiff, &byte_per_sample,	                  buffer_matr) > 0 ) &&	     ( !ml_eof )	  )    {	/****************************************************************/	/*                                                              */	/*                  START OF FRAME LOOP                         */	/*                                                              */	/****************************************************************/	/* the following allocation must happen within the while-loop. 1/5/93, SR */	  	if (mat_mode == -1)	{	    if (fr_ps.config == 320 || fr_ps.config == 310)		info.matrix = rand () % 4;	    else	    {		info.matrix = rand () % 3;		if (info.matrix == 2)		    info.matrix++;	    }	}	else	    info.matrix = mat_mode;	init_mc_pred (&fr_ps);	info.tc_sbgr_select = 1;	info.dyn_cross_on = 0;  	if (dyn_cr != 0 || fr_ps.config == 302 || fr_ps.config == 202)	    if (dyn_cr_LR == -1)		info.dyn_cross_LR = rand () % 2;	    else		info.dyn_cross_LR = dyn_cr_LR;	else	    info.dyn_cross_LR = 0;#ifdef Augmentation_7ch	if (aug_mat_mode == -1)	{	    info.aug_mtx_proc = rand () % 3;	    if (info.aug_mtx_proc == 2)		info.aug_mtx_proc++;	}	else	    info.aug_mtx_proc = aug_mat_mode;	info.aug_dyn_cross_on = 0;    	info.aug_future_ext = 0;#endif	for (i = 0; i < 12; i++)	{	    info.tc_alloc[i] = 0;	    info.dyn_cross[i] = 0;	    info.dyn_second_stereo[i] = 0;#ifdef Augmentation_7ch	    info.aug_tc_alloc[i] = 0;	    info.aug_dyn_cross[i] = 0;#endif	}		lfe_alloc = 0;  	if (stereomc > 0 && (fr_ps.header->center == 1 || fr_ps.header->center==3))	{	    if (fr_ps.phantom_c == 1) fr_ps.header->center = 3;	    if (fr_ps.phantom_c == 0) fr_ps.header->center = 1;	}          if (verbosity >= 1)	{	    fprintf (stderr, "{%4lu}\r", frameNum++);	    fflush (stderr);	}	win_buf[0] = &buffer[0][0];	win_buf[1] = &buffer[1][0];	win_buf[2] = &buffer[2][0];	win_buf[3] = &buffer[3][0];	win_buf[4] = &buffer[4][0];	win_buf[5] = &buffer[5][0];	win_buf[6] = &buffer[6][0];	win_buf[7] = &buffer[7][0];	/* JMZ 08/03/1995 Multilingual */	win_buf[8] = &buffer[8][0];	/* JMZ 08/03/1995 Multilingual */	win_buf[9] = &buffer[9][0];	/* JMZ 08/03/1995 Multilingual */	win_buf[10] = &buffer[10][0];	/* JMZ 08/03/1995 Multilingual */	win_buf[11] = &buffer[11][0];	/* JMZ 08/03/1995 Multilingual */	win_buf[12] = &buffer[12][0];	/* JMZ 08/03/1995 Multilingual */	win_buf[13] = &buffer[13][0];	/* JMZ 08/03/1995 Multilingual */        if (frac_SpF != 0)	{	    if (slot_lag > (frac_SpF - 1.0))	    {	        slot_lag -= frac_SpF;	        extra_s

⌨️ 快捷键说明

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