Changeset 1206810b7e59fcec539825b4fb9e8794152222a2

Show
Ignore:
Timestamp:
04/03/03 20:28:39 (6 years ago)
Author:
Gildas Bazin <gbazin@videolan.org>
git-committer:
Gildas Bazin <gbazin@videolan.org> 1046806119 +0000
git-parent:

[eb1ba666bb488d9ed579789c3f4c9df802774c54]

git-author:
Gildas Bazin <gbazin@videolan.org> 1046806119 +0000
Message:

* modules/audio_filter/resampler/bandlimited.c: fix bug that was affecting

quality badly + some clean-up.
Changed the module priority so it is now the default resampler.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/audio_filter/resampler/bandlimited.c

    r75426e2 r1206810  
    33 ***************************************************************************** 
    44 * Copyright (C) 2002 VideoLAN 
    5  * $Id: bandlimited.c,v 1.1 2003/03/04 03:27:40 gbazin Exp $ 
     5 * $Id: bandlimited.c,v 1.2 2003/03/04 19:28:39 gbazin Exp $ 
    66 * 
    77 * Authors: Gildas Bazin <gbazin@netcourrier.com> 
     
    6868 
    6969    int i_old_rate; 
    70     int d_old_factor; 
     70    double d_old_factor; 
    7171    int i_old_wing; 
    7272 
     
    8181vlc_module_begin(); 
    8282    set_description( _("audio filter for bandlimited interpolation resampling") ); 
    83     set_capability( "audio filter", 4 ); 
     83    set_capability( "audio filter", 20 ); 
    8484    set_callbacks( Create, Close ); 
    8585vlc_module_end(); 
     
    159159    int i_in_nb = p_in_buf->i_nb_samples; 
    160160    int i_in, i_out = 0; 
    161  
    162     double d_factor = (double)p_aout->mixer.mixer.i_rate 
    163                         / p_filter->input.i_rate; 
    164     int i_filter_wing, i_left_over; 
     161    double d_factor, d_scale_factor, d_old_scale_factor; 
     162    int i_filter_wing; 
     163#if 0 
     164    int i; 
     165#endif 
    165166 
    166167    /* Check if we really need to run the resampler */ 
     
    214215 
    215216#if 0 
    216     msg_Err( p_filter, "old rate: %i, old factor: %i, old wing: %i, i_in: %i", 
     217    msg_Err( p_filter, "old rate: %i, old factor: %f, old wing: %i, i_in: %i", 
    217218             p_filter->p_sys->i_old_rate, p_filter->p_sys->d_old_factor, 
    218219             p_filter->p_sys->i_old_wing, i_in_nb ); 
    219220#endif 
    220  
    221     /* Calculate the length of the filter wing */ 
    222     d_factor = (double)p_aout->mixer.mixer.i_rate / p_filter->input.i_rate; 
    223     i_filter_wing = ((SMALL_FILTER_NMULT+1)/2.0) * __MAX(1.0,1.0/d_factor) + 1; 
    224  
    225     /* Check if we have enough buffered data to start with the new rate. */ 
    226     i_left_over = i_filter_wing - p_filter->p_sys->i_old_wing; 
    227221 
    228222    /* Prepare the source buffer */ 
     
    255249    memset( p_out, 0, p_out_buf->i_size ); 
    256250 
    257 #if 0 
     251    /* Calculate the new length of the filter wing */ 
     252    d_factor = (double)p_aout->mixer.mixer.i_rate / p_filter->input.i_rate; 
     253    i_filter_wing = ((SMALL_FILTER_NMULT+1)/2.0) * __MAX(1.0,1.0/d_factor) + 1; 
     254 
    258255    /* Account for increased filter gain when using factors less than 1 */ 
    259     if( d_factor < 1 ) 
    260     { 
    261         LpScl = SMALL_FILTER_SCALE * d_factor + 0.5; 
    262     } 
    263 #endif 
     256    d_old_scale_factor = SMALL_FILTER_SCALE * 
     257        p_filter->p_sys->d_old_factor + 0.5; 
     258    d_scale_factor = SMALL_FILTER_SCALE * d_factor + 0.5; 
    264259 
    265260    /* Apply the old rate until we have enough samples for the new one */ 
    266     for( i_in = p_filter->p_sys->i_old_wing; i_in < i_left_over; i_in++ ) 
     261    /* TODO: Check we have enough samples */ 
     262    i_in = p_filter->p_sys->i_old_wing; 
     263    p_in += p_filter->p_sys->i_old_wing * i_nb_channels; 
     264    for( ; i_in < i_filter_wing; i_in++ ) 
    267265    { 
    268266        if( p_filter->p_sys->d_old_factor == 1 ) 
     
    298296                               1, i_nb_channels ); 
    299297 
     298#if 0 
     299                /* Normalize for unity filter gain */ 
     300                for( i = 0; i < i_nb_channels; i++ ) 
     301                { 
     302                    *(p_out+i) *= d_old_scale_factor; 
     303                } 
     304#endif 
    300305            } 
    301306            else 
     
    316321            } 
    317322 
    318 #if 0 
    319             v *= LpScl;             /* Normalize for unity filter gain */ 
    320 #endif 
    321  
    322323            p_out += i_nb_channels; 
    323324            i_out++; 
     
    331332 
    332333    /* Apply the new rate for the rest of the samples */ 
     334    /* TODO: Check we have enough future samples for the new rate */ 
    333335    if( i_in < i_in_nb - i_filter_wing ) 
    334336    { 
     
    360362                               p_filter->output.i_rate, 
    361363                               1, i_nb_channels ); 
     364 
     365#if 0 
     366                /* Normalize for unity filter gain */ 
     367                for( i = 0; i < i_nb_channels; i++ ) 
     368                { 
     369                    *(p_out+i) *= d_old_scale_factor; 
     370                } 
     371#endif 
    362372            } 
    363373            else 
     
    378388            } 
    379389 
    380 #if 0 
    381             v *= LpScl;             /* Normalize for unity filter gain */ 
    382 #endif 
    383  
    384390            p_out += i_nb_channels; 
    385391            i_out++; 
     
    402408 
    403409#if 0 
    404     msg_Err( p_filter, "pout size: %i, nb_samples out: %i", p_out_buf->i_size, 
     410    msg_Err( p_filter, "p_out size: %i, nb bytes out: %i", p_out_buf->i_size, 
    405411             i_out * p_filter->input.i_bytes_per_frame ); 
    406412#endif 
     
    507513          ((ui_output_rate * ui_counter + ui_remainder)<< Nhc) / 
    508514          ui_input_rate * ui_input_rate; 
    509           //(ui_remainder<<Nhc)* ui_output_rate/ui_input_rate - 
    510           //(ui_remainder<<Nhc) / ui_input_rate * ui_output_rate; 
    511515        t += *Hdp * ui_linear_remainder / ui_input_rate / Npc; 
    512516        for( i = 0; i < i_nb_channels; i++ )