Howdy All,

> -----Original Message-----
> From: Zia Mazhar [mailto:[EMAIL PROTECTED]]
> Sent: Monday, April 24, 2000 3:36 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [MP3 ENCODER] mpglib bugfix
> 
> Naoki Shibata wrote:
...
> >   I made a patch to fix some problems of mpglib. And, I updated
> > in_mpg123 plugin.
> >   Now, maximum differences of outputs of mpglib decoder and
> > l3dec 2.60 is 1 for each sample, as far as I tested.
...
> Really? That sounds great! I'll download it right away. By 
> the way, how do you
> measure the difference? Isn't there any way to be sure that 
> I'm getting the
> 100% accurate sound what has been encoded in an MP3 file?

If you have a C compiler, see my source for a utility called 'audiod' (audio
diff) below.  (It may need some tweaking for I/O, etc. on your particular
platform.)  It diffs two PCM audio files against one another and 1) tells
you their relative length, 2) tells you whether or not they differ, and 3)
outputs a histogram of the magnitudes of the differences (which may be quite
extensive if they are severely different).  In the above case, it should
tell you that there were a number of differences of magnitude 1.

As to your second question, there is no such thing as the 100% accurate
sound that was encoded in an mp3.  The precision of numerous internal
variables (not to mention the actual
audio I/O) is not specified in the MPEG spec, and rounding is not treated
consistently.  Similarly, math libraries (especially floating point
division) on different platforms may not be 100% identical in their
operation.  Thus 'conforming' decoders may disagree as to the precise output
PCM samples from a given input bitstream.  However, this rarely leads to
absolute differences of more than an LSB; thus the above standard of
measurement is pretty prevalent.

Alex

-----

#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

void main(int argc, char *argv[])
{
        int   i,diff_index,diff_total=0;
        int  *diffs;
        short sample1,sample2;
        int   samples=0;
        int   done1,done2,done=0;
        FILE *in1,*in2;

        if(argc!=3) {
                fprintf(stderr,"USAGE:  %s infile1 infile2\n",argv[0]);
                exit(1);
        }
        if((in1=fopen(argv[1],"rb"))==NULL) {
                fprintf(stderr,"ERROR:  Could not open file %s\n",argv[1]);
                exit(1);
        }
        if((in2=fopen(argv[2],"rb"))==NULL) {
                fprintf(stderr,"ERROR:  Could not open file %s\n",argv[2]);
                exit(1);
        }
        
        diffs = (int *)calloc(SHRT_MAX-SHRT_MIN+1,sizeof(int));

        // Prime the pipeline
        fread(&sample1,sizeof(short),1,in1);
        fread(&sample2,sizeof(short),1,in2);

        done1 = feof(in1);
        done2 = feof(in2);

        while(!done1 && !done2) {
                diff_index = abs(sample1-sample2);
                if(diff_index) diff_total++;
                diffs[diff_index]++;
                samples++;

                fread(&sample1,sizeof(short),1,in1);
                fread(&sample2,sizeof(short),1,in2);

                done1 = feof(in1);
                done2 = feof(in2);
        }

        if(!done1) {
                fseek(in1,0,SEEK_END);
                fprintf(stdout,"File %s is %d samples longer than file
%s...\n",
                            argv[1],(ftell(in1)>>1) - samples,argv[2]);
        }
        else if(!done2) {
                fseek(in2,0,SEEK_END);
                fprintf(stdout,"File %s is %d samples longer than file
%s...\n",
                            argv[2],(ftell(in2)>>1) - samples,argv[1]);
        }
        else
                done++;

        if(diff_total) {
                fprintf(stdout,"The files differ...\n");
                fprintf(stdout,"The differences were distributed as
follows:\n");
                for(i=1;i<SHRT_MAX-SHRT_MIN+1;i++) {
                        if(diffs[i]) {
                                fprintf(stdout,"\t%d differences of
magnitude %d\n",diffs[i],i);
                        }
                }

                if(done)
                        fprintf(stdout,"For a total of %d differences over
%d samples.\n",
                                diff_total,samples);
                else
                        fprintf(stdout,"For a total of %d differences over
the %d overlapping samples.\n",
                                diff_total,samples);
        }
        else {
                if(done)
                        fprintf(stdout,"The files are identical.\n");
                else
                        fprintf(stdout,"The overlapping portions of the
files are identical.\n");
        }

        free(diffs);
        fclose(in1);
        fclose(in2);
}
--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to