示例#1
0
void timestatus ( const int samp_rate, 
                  const int frameNum,
                  const int totalframes,
                  const int framesize )
{
    static timestatus_t  real_time;
    static timestatus_t  proc_time;
    int                  percent;
    static int           init = 0; /* What happens here? A work around instead of a bug fix ??? */
    double               tmx,delta;


    if ( frameNum == 0 ) {
        real_time.last_time = GetRealTime ();
        proc_time.last_time = GetCPUTime  ();
        real_time.elapsed_time = 0;
        proc_time.elapsed_time = 0;
    }

    /* we need rollover protection for GetCPUTime, and maybe GetRealTime(): */
    tmx=GetRealTime();
    delta=tmx-real_time.last_time;
    if (delta<0) delta=0;  /* ignore, clock has rolled over */
    real_time.elapsed_time += delta;
    real_time.last_time     = tmx;


    tmx=GetCPUTime();
    delta=tmx-proc_time.last_time;
    if (delta<0) delta=0;  /* ignore, clock has rolled over */
    proc_time.elapsed_time += delta;
    proc_time.last_time     = tmx;

    if ( frameNum == 0 && init == 0 ) {
        fprintf ( stderr,
	    "\r"
	    "    Frame          |  CPU time/estim | REAL time/estim | play/CPU |    ETA \n"
            "     0/       ( 0%%)|    0:00/     :  |    0:00/     :  |         " SPEED_CHAR "|     :  \r"
	    /* , Console_IO.str_clreoln, Console_IO.str_clreoln */ );
	init = 1;
        return;
    }  
    /* reset init counter for next time we are called with frameNum==0 */
    if (frameNum > 0) 
        init = 0;

    ts_calc_times ( &real_time, samp_rate, frameNum, totalframes, framesize );
    ts_calc_times ( &proc_time, samp_rate, frameNum, totalframes, framesize );

    if ( frameNum < totalframes  ) {
        percent = (int) (100. * frameNum / totalframes + 0.5 );
    } else {
        percent = 100;
    }
	
    fprintf ( stderr, "\r%6i/%-6i", frameNum, totalframes );
    fprintf ( stderr, percent < 100 ? " (%2d%%)|" : "(%3.3d%%)|", percent );
    ts_time_decompose ( (unsigned long)proc_time.elapsed_time  , '/' );
    ts_time_decompose ( (unsigned long)proc_time.estimated_time, '|' );
    ts_time_decompose ( (unsigned long)real_time.elapsed_time  , '/' );
    ts_time_decompose ( (unsigned long)real_time.estimated_time, '|' );
    fprintf ( stderr, proc_time.speed_index <= 1.  ?  
              "%9.4f" SPEED_CHAR "|"  :  "%#9.5g" SPEED_CHAR "|",
	      SPEED_MULT * proc_time.speed_index );
    ts_time_decompose ( (unsigned long)(real_time.estimated_time - real_time.elapsed_time), ' ' );
    fflush  ( stderr );
}
示例#2
0
static void
timestatus(const lame_global_flags * const gfp)
{
    timestatus_t* real_time = &global_encoder_progress.real_time;
    timestatus_t* proc_time = &global_encoder_progress.proc_time;
    int     percent;
    double  tmx, delta;
    int samp_rate     = lame_get_out_samplerate(gfp)
      , frameNum      = lame_get_frameNum(gfp)
      , totalframes   = lame_get_totalframes(gfp)
      , framesize     = lame_get_framesize(gfp)
      ;

    if (totalframes < frameNum) {
        totalframes = frameNum;
    }
    if (global_encoder_progress.time_status_init == 0) {
        real_time->last_time = GetRealTime();
        proc_time->last_time = GetCPUTime();
        real_time->elapsed_time = 0;
        proc_time->elapsed_time = 0;
    }

    /* we need rollover protection for GetCPUTime, and maybe GetRealTime(): */
    tmx = GetRealTime();
    delta = tmx - real_time->last_time;
    if (delta < 0)
        delta = 0;      /* ignore, clock has rolled over */
    real_time->elapsed_time += delta;
    real_time->last_time = tmx;


    tmx = GetCPUTime();
    delta = tmx - proc_time->last_time;
    if (delta < 0)
        delta = 0;      /* ignore, clock has rolled over */
    proc_time->elapsed_time += delta;
    proc_time->last_time = tmx;

    if (global_encoder_progress.time_status_init == 0) {
        console_printf("\r"
                       "    Frame          |  CPU time/estim | REAL time/estim | play/CPU |    ETA \n"
                       "     0/       ( 0%%)|    0:00/     :  |    0:00/     :  |         "
                       SPEED_CHAR "|     :  \r"
                       /* , Console_IO.str_clreoln, Console_IO.str_clreoln */ );
        global_encoder_progress.time_status_init = 1;
        return;
    }

    ts_calc_times(real_time, samp_rate, frameNum, totalframes, framesize);
    ts_calc_times(proc_time, samp_rate, frameNum, totalframes, framesize);

    if (frameNum < totalframes) {
        percent = (int) (100. * frameNum / totalframes + 0.5);
    }
    else {
        percent = 100;
    }

    console_printf("\r%6i/%-6i", frameNum, totalframes);
    console_printf(percent < 100 ? " (%2d%%)|" : "(%3.3d%%)|", percent);
    ts_time_decompose(proc_time->elapsed_time, '/');
    ts_time_decompose(proc_time->estimated_time, '|');
    ts_time_decompose(real_time->elapsed_time, '/');
    ts_time_decompose(real_time->estimated_time, '|');
    console_printf(proc_time->speed_index <= 1. ?
                   "%9.4f" SPEED_CHAR "|" : "%#9.5g" SPEED_CHAR "|",
                   SPEED_MULT * proc_time->speed_index);
    ts_time_decompose((real_time->estimated_time - real_time->elapsed_time), ' ');
}
示例#3
0
文件: mpgplay.c 项目: mentat/tehDJ
int main(int argc, char **argv){

	char		*bufout;
	char		*bufin;
	path_id		path,devpath;
	error_code	error;
	u_int32		bufsize_out = OUT_BUF_SIZE;
	u_int32		bufsize_in = IN_BUF_SIZE;
	u_int32		count;
	int			inlen,outlen;
	char		*compbuf=NULL;
	int			compbuflen=0,compbufpos=0;
	int			status=MP3_OK;
	int			i;
	struct 		mpstr mp;
	int 		iflag=0;

	if (argc != 3)
	{
		printf("Play MP3 file\n");
		printf("Usage: mpgplay <filename><device>\n");
		exit(1);
	}
	/* set up signal handler */
	intercept (sighand);

	/* Initialize the MP3 decoder */
	InitMP3(&mp);
	
	if ((error = _os_open(argv[1], FAM_READ, &path)) != SUCCESS) {
		return error;
	}
    
    /* Prepare the Sound device */
    if ((error = _os_open(argv[2], FAM_WRITE, &devpath)) != SUCCESS) {
		return error;
    }

    if ((error = _os_srqmem (&bufsize_in, (void**)&bufin, 0)) != SUCCESS) {
		return error;
	}

    if ((error = _os_srqmem (&bufsize_out, (void**)&bufout, 0)) != SUCCESS) {
		return error;
	}


	sigval = SMAP_DONE_SIG; /* Sound is free */

	#if defined(SHOW_TIME_INFO)
	time (&initial_time);
	#endif

	while(status != MP3_ERR){
	
		count = IN_BUF_SIZE;

	    /* read the data */
    	if ((error = _os_read(path, bufin, &count)) != SUCCESS){
	      if (error == EOS_EOF) break; /* done */
    	  else return error;
		}

		inlen = count;

		/* Initialize buffer */

		outlen = compbufpos = compbuflen = 0;

		status = decodeMP3(&mp,bufin,inlen,bufout,OUT_BUF_SIZE,&outlen);

		if (!iflag){
			printf("Playing %s [%s - %dkbs]\n",
				argv[1],
					mp.fr.stereo?"Stereo":"Mono",
						frequencies[mp.fr.sampling_frequency]);


			#if defined(SHOW_FRAME)
				printf("FRAME: stereo %d jsbound %d single %d lsf %d\n",
			    mp.fr.stereo,
			    mp.fr.jsbound,
			    mp.fr.single,
			    mp.fr.lsf);
				printf("mpeg25 %d header_change %d lay %d error_protection %d\n",
			    mp.fr.mpeg25,
			    mp.fr.header_change,
			    mp.fr.lay,
			    mp.fr.error_protection);
				printf("bitrate_index %d sampling_frequency %d padding %d extension %d\n",
			    mp.fr.bitrate_index,
			    mp.fr.sampling_frequency,
			    mp.fr.padding,
			    mp.fr.extension);
				printf("mode %d mode_ext %d copyright %d original %d\n",
			    mp.fr.mode,
			    mp.fr.mode_ext,
			    mp.fr.copyright,
			    mp.fr.original);
				printf("emphasis %d framesize %d\n",
			    mp.fr.emphasis,
			    mp.fr.framesize);
			
			#endif



			iflag=1;

		}

		while(status == MP3_OK){


			/* Check buffer size */
			if ((compbufpos + outlen) > compbuflen || compbuf == NULL)
				{
				compbuflen = compbufpos+outlen;
				compbuf = (char *) realloc(compbuf,compbuflen); 
				}

			memcpy(compbuf+compbufpos,bufout,outlen);
			compbufpos+=outlen;

			status = decodeMP3(&mp,NULL,0,bufout,OUT_BUF_SIZE,&outlen);

		}


		if (compbufpos)
		{

			int blks =  compbufpos / SND_BLK_SIZE;
			int residual = compbufpos - (blks*SND_BLK_SIZE);


			#if defined(SHOW_TIME_INFO)
			{
				time (&current_time);
			    ts_time_decompose ( (unsigned long)difftime (current_time, initial_time));
				total_blks += (blks+1);
			}
			#endif


			/* Wait for buffer slot to empty */
		
			sigmask(1);
			if (sigval != SMAP_DONE_SIG){
  				tsleep(0);		
			} else 
				sigmask(-1);

			sigval = 0; 

		 	if (compbufpos > sound_buffer_size)
	 		{


				sound_buffer = (u_char *) realloc(sound_buffer,compbufpos); 

			}

				sound_buffer_size = compbufpos;

				memcpy(sound_buffer,compbuf,sound_buffer_size);

				/*
				 * Fill up the sound maps
				*/

				for(i=0;i<blks;i++)
				{

					smap[i].num_channels =  mp.fr.stereo;
					smap[i].sample_rate = frequencies[mp.fr.sampling_frequency]; 
					smap[i].coding_method = CODING_METHOD; 
					smap[i].sample_size = SAMPLE_SIZE; 
					smap[i].cur_offset = 0;
					smap[i].loop_start = 0;
					smap[i].loop_count = 1; 
					smap[i].loop_counter = 0; 
					smap[i].next = &smap[i+1];
					smap[i].trig_mask = 0;
					smap[i].trig_signal = 0;
					/* get the size of the data in this read */
					smap[i].buf_size = smap[i].loop_end = SND_BLK_SIZE; 
					smap[i].buf = &sound_buffer[i*SND_BLK_SIZE];


				}

				/* If we do not have residual then back up to last sound map 1st */

				if (residual==0)
					i--;

				/* Last block in chain */
				smap[i].num_channels =  mp.fr.stereo;
				smap[i].sample_rate = frequencies[mp.fr.sampling_frequency]; 
				smap[i].coding_method = CODING_METHOD; 
				smap[i].sample_size = SAMPLE_SIZE; 
				smap[i].cur_offset = 0;
				smap[i].loop_start = 0;
				smap[i].loop_count = 1; 
				smap[i].loop_counter = 0; 
				smap[i].next = NULL;
				smap[i].trig_mask = SND_TRIG_READY;
				smap[i].trig_signal = SMAP_DONE_SIG;
				/* get the size of the data in this read */
				smap[i].buf_size = smap[i].loop_end = residual?residual:SND_BLK_SIZE; 
				smap[i].buf = &sound_buffer[i*SND_BLK_SIZE];

				if ((error = _os_ss_snd_play(devpath, &smap[0], SND_NOBLOCK  )) != SUCCESS) {
					  return error;
				}

				compbufpos = 0;
		
		}

	}
	
	#if defined(SHOW_TIME_INFO)
	printf("\n");
	#endif

	
	/* Wait for buffer slot to empty */
		
	sigmask(1);
	if (sigval != SMAP_DONE_SIG){
			tsleep(0);		
	} else 
		sigmask(-1);


	/* Exit the MP3 decoder */
	ExitMP3(&mp);

	_os_srtmem(bufsize_in, (void *)bufin);
	_os_srtmem(bufsize_out, (void *)bufout);


}