1st problem
~~~~~~~~~~~

I have a set of WAV files without silence gaps. After converting to MP3 and 
reconverting to
WAV there are gaps (20...40 ms) between the files. How can I prevent this?


2nd problem
~~~~~~~~~~~
Some of my CDs have a lot of DC offset. Other are well DC free. Examples:

 x[AC]     y[AC]     r         type        x[DC]     y[DC]     File
 26.110%   30.231%   37.382%   MS-Stereo   -8.418%   -6.779%   Giora 
Feidman/track01.cdda.wav
 24.437%   26.815%   62.902%   MS-Stereo   -7.890%   -6.384%   Giora 
Feidman/track02.cdda.wav
 28.233%   17.670%   88.636%   MS-Stereo   -7.832%   -5.380%   Giora 
Feidman/track03.cdda.wav
 44.400%   42.320%   77.321%   MS-Stereo  -10.005%   -7.835%   Giora 
Feidman/track04.cdda.wav
 27.438%   29.094%   74.308%   MS-Stereo   -7.997%   -6.360%   Giora 
Feidman/track05.cdda.wav
 38.190%   38.762%   73.798%   MS-Stereo   -8.416%   -6.575%   Giora 
Feidman/track06.cdda.wav
 33.937%   35.373%   52.249%   MS-Stereo   -9.008%   -7.106%   Giora 
Feidman/track07.cdda.wav
 25.220%   24.489%   83.892%   MS-Stereo   -7.981%   -6.185%   Giora 
Feidman/track08.cdda.wav
 23.899%   26.594%   76.254%   MS-Stereo   -8.135%   -6.559%   Giora 
Feidman/track09.cdda.wav
 27.257%   29.149%   73.527%   MS-Stereo   -8.739%   -7.057%   Giora 
Feidman/track10.cdda.wav
 44.419%   36.258%   79.641%   MS-Stereo   -9.816%   -7.550%   Giora 
Feidman/track11.cdda.wav
 22.294%   31.883%   89.198%   MS-Stereo   -8.411%   -7.360%   Giora 
Feidman/track12.cdda.wav
 37.214%   35.780%   81.549%   MS-Stereo   -9.638%   -7.372%   Giora 
Feidman/track13.cdda.wav
 33.170%   41.641%   87.566%   MS-Stereo   -9.481%   -7.850%   Giora 
Feidman/track14.cdda.wav
 33.711%   42.198%   88.124%   MS-Stereo   -9.345%   -7.669%   Giora 
Feidman/track15.cdda.wav
 43.713%   45.161%   73.291%   MS-Stereo   -9.884%   -7.836%   Giora 
Feidman/track16.cdda.wav
 36.152%   34.970%   73.292%   MS-Stereo   -9.071%   -7.062%   Giora 
Feidman/track17.cdda.wav
 37.865%   34.517%   71.336%   MS-Stereo   -9.279%   -7.062%   Giora 
Feidman/track18.cdda.wav
 34.980%   39.203%   49.169%   MS-Stereo   -8.949%   -7.188%   Giora 
Feidman/track19.cdda.wav
 29.621%   32.464%   81.196%   MS-Stereo   -8.881%   -7.007%   Giora 
Feidman/track20.cdda.wav
 70.782%   68.893%   53.126%   MS-Stereo   -0.006%   -0.008%   Jazz Lyrik 
Prosa/track01.cdda.wav
 39.614%   45.291%   81.413%   MS-Stereo   -0.006%   -0.007%   Jazz Lyrik 
Prosa/track02.cdda.wav
 71.708%   73.715%   99.879%   Mono        -0.010%   -0.010%   Jazz Lyrik 
Prosa/track03.cdda.wav
 31.473%   32.412%   99.844%   Mono        -0.007%   -0.007%   Jazz Lyrik 
Prosa/track04.cdda.wav
 71.731%   73.783%   99.925%   Mono        -0.005%   -0.005%   Jazz Lyrik 
Prosa/track05.cdda.wav
 36.925%   37.863%   99.791%   Mono        -0.007%   -0.007%   Jazz Lyrik 
Prosa/track06.cdda.wav
 28.091%   28.811%   99.835%   Mono        -0.006%   -0.006%   Jazz Lyrik 
Prosa/track07.cdda.wav
 51.676%   52.912%   99.507%   Mono        -0.008%   -0.008%   Jazz Lyrik 
Prosa/track08.cdda.wav
 48.875%   49.597%   81.123%   MS-Stereo   -0.007%   -0.007%   Jazz Lyrik 
Prosa/track09.cdda.wav
 55.150%   56.083%   99.873%   Mono        -0.001%   -0.001%   Jazz Lyrik 
Prosa/track10.cdda.wav
 47.875%   49.324%   99.749%   Mono        -0.007%   -0.007%   Jazz Lyrik 
Prosa/track11.cdda.wav
 85.609%   91.884%   60.015%   MS-Stereo   -0.005%   -0.004%   Jazz Lyrik 
Prosa/track12.cdda.wav
 31.389%   38.746%   86.307%   MS-Stereo   -0.007%   -0.007%   Jazz Lyrik 
Prosa/track13.cdda.wav
 76.018%   74.017%   80.323%   MS-Stereo   -0.008%   -0.008%   Jazz Lyrik 
Prosa/track14.cdda.wav
 41.697%   52.852%   75.873%   MS-Stereo   -0.006%   -0.006%   Jazz Lyrik 
Prosa/track15.cdda.wav
 68.815%   71.073%   99.863%   Mono        -0.009%   -0.009%   Jazz Lyrik 
Prosa/track16.cdda.wav
 42.912%   43.491%   98.428%   Mono        -0.006%   -0.007%   Jazz Lyrik 
Prosa/track17.cdda.wav
101.106%   99.551%   63.043%   MS-Stereo   -0.014%   -0.020%   Jazz Lyrik 
Prosa/track18.cdda.wav
 57.308%   60.230%   90.311%   MS-Stereo   -0.007%   -0.007%   Jazz Lyrik 
Prosa/track19.cdda.wav
 87.427%   82.443%   40.229%   MS-Stereo   -0.007%   -0.009%   Jazz Lyrik 
Prosa/track20.cdda.wav
 46.851%   47.622%   87.358%   MS-Stereo   -0.007%   -0.007%   Jazz Lyrik 
Prosa/track21.cdda.wav
 69.743%   77.524%   71.732%   MS-Stereo   -0.007%   -0.007%   Jazz Lyrik 
Prosa/track22.cdda.wav

Problem No.1 is that it creaks Kr#[&\/§$%&!°^z! terrible on the start and
the end of such a file. 
Problem No.2 is that at the same bitrate DC decreases sound quality (is this
a feature of MP3 or a bug in Lame?)

I don't like high pass filtering in the frequency domain (don't reduces DC
at the beginning of the file, may be removes wanted frequencies), I often do
high pass filtering in the polynom domain (Legendre). 

0nd order polynom filtering is DC canceling, 1st order is an additional
trend elimination, ...

A huge disadvantage is that you must read the whole file before processing,
so I use a preprocessor generating a 32-bit float AIFF file (more accuracy
without intermediante roundings, larger range needed, because of value
shifting).

-- 
Mit freundlichen Grüßen
Frank Klemm
 
eMail | [EMAIL PROTECTED]       home: [EMAIL PROTECTED]
phone | +49 (3641) 64-2721    home: +49 (3641) 390545
sMail | R.-Breitscheid-Str. 43, 07747 Jena, Germany

------------ korr.c --------------------
// nasm -f elf korr_asm.asm; gcc -O2 -s -o korr korr.c korr_asm.o
//   or
// gcc -O2 -s -DNONASM -o korr korr.c

#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <memory.h>

typedef signed short stereo [2];
typedef struct {
    unsigned long long  n;
    long double         x;
    long double         x2;
    long double         y;
    long double         y2;
    long double         xy;
} korr_t;

korr_t k;

#ifdef NONASM

void analyze ( const stereo* p, size_t len )
{
    long double  _x = 0, _x2 = 0, _y = 0, _y2 = 0, _xy = 0;
    long double  t1;
    long double  t2;
    
    k.n  += len;
    
    for ( ; len--; p++ ) {
#if 1
        _x  += (t1 = (double)(*p)[0]);
        _x2 += t1*t1;
        _y  += (t2 = (double)(*p)[1]);
        _y2 += t2*t2;
        _xy += t1*t2;
#else
        _x  += (*p)[0];
        _x2 += (*p)[0] * (*p)[0];
        _y  += (*p)[1];
        _y2 += (*p)[1] * (*p)[1];
        _xy += (*p)[0] * (*p)[1];
#endif        
    }
    
    k.x  += _x ;
    k.x2 += _x2;
    k.y  += _y ;
    k.y2 += _y2;
    k.xy += _xy;
}

#else

extern void __analyze ( const stereo* p, size_t len, korr_t* dst );

#define analyze(ptr,len)  __analyze ( ptr, len, &k )

#endif

void init ( void )
{
    memset ( &k, 0, sizeof(k) );
}

const char* type ( double r )
{
    if ( r > +0.98 ) return "Mono";
    if ( r > +0.91 ) return "?";
    if ( r > +0.37 ) return "MS-Stereo";
    if ( r > -0.37 ) return "Stereo";
    return "???";
}

void report_init ( void )
{
    printf ( " x[AC]     y[AC]     r         type        x[DC]     y[DC]     File\n");
}

void report ( const char* name )
{
    long double  scale = sqrt ( 1.e5 / (1<<29) ); // Sine Full Scale is +10 dB, 7327 = 
100%
    long double  r;
    long double  sx;
    long double  sy;
    long double  x;
    long double  y;
    
    // printf ("n=%Lu (7036596)\nx=%Lf (-1136345)\ny=%Lf (-783749)\nxy=%Lf 
(103252784558988)\nx²=%Lf (182857029624921)\ny²=%Lf 
(201045032621475)\n\n",k.n,k.x,k.y,k.xy,k.x2,k.y2);
    
    r  = (k.x2*k.n - k.x*k.x) * (k.y2*k.n - k.y*k.y);
    r  = r > 0.   ?  (k.xy*k.n - k.x*k.y) / sqrt (r)  :  1.l;
    sx = k.n > 1  ?  sqrt ( (k.x2 - k.x*k.x/k.n) / (k.n - 1) )  :  0.l;
    sy = k.n > 1  ?  sqrt ( (k.y2 - k.y*k.y/k.n) / (k.n - 1) )  :  0.l;
    x  = k.n > 0  ?  k.x/k.n  :  0.l;
    y  = k.n > 0  ?  k.y/k.n  :  0.l;
    
    printf ( "%7.3Lf%%  %7.3Lf%%  %7.3Lf%%   %-9s  %+7.3Lf%%  %+7.3Lf%%   %s\n", 
             sx * scale, sy * scale, 100. * r, type (r), x * scale, y * scale, name );
    fflush ( stdout );
}

void readfile ( const char* name )
{
    stereo  s [2048];
    size_t  samples;
    int     fd;
    
    init ();
    if ( name ) {
        if ( (fd = open ( name, O_RDONLY )) < 0 )
            return;
        read ( fd, s, 44 );
        while  ( ( samples = read (fd, s, sizeof(s)) ) > 0 )
            analyze ( s, samples / sizeof (*s) );
        close ( fd );   
        report ( name );
    } else {
        read ( 0, s, 44 );
        while  ( ( samples = read ( 0, s, sizeof(s)) ) > 0 )
            analyze ( s, samples / sizeof (*s) );
        report ( "<stdin>" );
    }
}

int main ( int argc, char** argv )
{
    report_init ();
    
    if (argc < 2)
        readfile ( NULL );
    else        
        while ( *++argv )
            readfile ( *argv );
    
    return 0;
}
------------ korr_asm.asm ---------------------
        BITS 32

        SECTION .text
;
; void __analyze ( const stereo* p, size_t len, korr_t* result );
;
; esp+12        result
; esp+ 8        len
; esp+ 4        p
; esp+ 0        return address
;
        GLOBAL  __analyze:function
__analyze
        mov     eax,  [esp+12]
        mov     ecx,  [esp+ 8]
        mov     edx,  [esp+ 4]
        add     dword [eax+0],ecx
        adc     dword [eax+4],byte 0
        fldz
        fldz
        fldz
        fldz
        fldz                            ; Sxy Sy² Sy  Sx² Sx
lbl:
        fild    word [edx+0]            ; x   Sxy Sy² Sy  Sx² Sx
        fld     st0                     ; x   x   Sxy Sy² Sy  Sx² Sx
        fmul    st0,st0                 ; x²  x   Sxy Sy² Sy  Sx² Sx
        faddp   st5,st0                 ; x   Sxy Sy² Sy  Sx² Sx
        fadd    st5,st0
        fild    word [edx+2]            ; y   x   Sxy Sy² Sy  Sx² Sx
        fadd    st4,st0
        add     edx,byte 4
        fmul    st1,st0                 ; y   xy  Sxy Sy² Sy  Sx² Sx
        fmul    st0,st0                 ; y²  xy  Sxy Sy² Sy  Sx² Sx
        faddp   st3,st0                 ; xy  Sxy Sy² Sy  Sx² Sx
        faddp   st1,st0                 ; Sxy Sy² Sy  Sx² Sx
        dec     ecx
        jnz     lbl

        fld     tword [eax+56]
        faddp   st1,st0 
        fstp    tword [eax+56]          ; xy
        fld     tword [eax+44]
        faddp   st1,st0
        fstp    tword [eax+44]          ; y²
        fld     tword [eax+32]
        faddp   st1,st0
        fstp    tword [eax+32]          ; y
        fld     tword [eax+20]
        faddp   st1,st0
        fstp    tword [eax+20]          ; x²
        fld     tword [eax+ 8]
        faddp   st1,st0
        fstp    tword [eax+ 8]          ; x
        ret
;
-----------------------------------------------------

--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to