1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 07:12:39 +00:00

benchmarking code (#define TIMING)

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@3508 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
michael 2001-12-15 22:32:14 +00:00
parent 7a7eaccc0b
commit a415880927

View File

@ -4,6 +4,8 @@
// writes it to stdout. resulting stream playbackable with sox:
// play -c 2 -r 48000 out.sw
//#define TIMING //needs Pentium or newer
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
@ -17,6 +19,25 @@ static int buf_size=0;
static int16_t out_buf[6*256*6];
#ifdef TIMING
static inline long long rdtsc()
{
long long l;
asm volatile( "rdtsc\n\t"
: "=A" (l)
);
// printf("%d\n", int(l/1000));
return l;
}
#define STARTTIMING t=rdtsc();
#define ENDTIMING sum+=rdtsc()-t; t=rdtsc();
#else
#define STARTTIMING ;
#define ENDTIMING ;
#endif
static inline int16_t convert (int32_t i)
{
if (i > 0x43c07fff)
@ -126,6 +147,9 @@ int main(){
int accel=0;
int sample_rate=0;
int bit_rate=0;
#ifdef TIMING
long long t, sum=0;
#endif
samples = a52_init (accel);
if (samples == NULL) {
@ -144,7 +168,9 @@ while(1){
if(c<0) goto eof;
buf[buf_size++]=c;
}
STARTTIMING
length = a52_syncinfo (buf, &flags, &sample_rate, &bit_rate);
ENDTIMING
if(!length){
// bad file => resync
memcpy(buf,buf+1,6);
@ -161,8 +187,10 @@ while(1){
// decode:
flags=A52_STEREO; // A52_DOLBY // A52_2F2R // A52_3F2R | A52_LFE
flags |= A52_ADJUST_LEVEL;
STARTTIMING
if (a52_frame (&state, buf, &flags, &level, bias))
{ fprintf(stderr,"error at decoding\n"); continue; }
ENDTIMING
// a52_dynrng (&state, NULL, NULL); // disable dynamic range compensation
@ -170,8 +198,10 @@ while(1){
for (i = 0; i < 6; i++) {
int32_t * f = (int32_t *) samples;
int i;
STARTTIMING
if (a52_block (&state, samples))
{ fprintf(stderr,"error at sampling\n"); break; }
ENDTIMING
// resample to STEREO/DOLBY:
for (i = 0; i < 256; i++) {
s16[2*i] = convert (f[i]);
@ -185,4 +215,8 @@ while(1){
eof:
#ifdef TIMING
fprintf(stderr, "%4.4fm cycles\n",sum/1000000.0);
#endif
}