Changeset e414aa3236f4562b5796aca8098319a5d3020aeb

Show
Ignore:
Timestamp:
10/07/04 20:08:09 (4 years ago)
Author:
Gildas Bazin <gbazin@videolan.org>
git-committer:
Gildas Bazin <gbazin@videolan.org> 1089482889 +0000
git-parent:

[32f808e2b53be404078de7e50c64655c94f4240c]

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

* src/misc/mtime.c, include/mtime.h: new common "date" API for date incrementation without long-term rounding errors.

(is going to replace audio_date_t).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/mtime.h

    r6da0852 re414aa3  
    1010 ***************************************************************************** 
    1111 * Copyright (C) 1996, 1997, 1998, 1999, 2000 VideoLAN 
    12  * $Id: mtime.h,v 1.14 2003/12/02 01:54:30 rocky Exp
     12 * $Id
    1313 * 
    1414 * Authors: Vincent Seguin <seguin@via.ecp.fr> 
     
    6060VLC_EXPORT( char *,  secstotimestr, ( char *psz_buffer, int secs ) ); 
    6161 
     62/***************************************************************************** 
     63 * date_t: date incrementation without long-term rounding errors 
     64 *****************************************************************************/ 
     65struct date_t 
     66{ 
     67    mtime_t  date; 
     68    uint32_t i_divider_num; 
     69    uint32_t i_divider_den; 
     70    uint32_t i_remainder; 
     71}; 
     72 
     73VLC_EXPORT( void,    date_Init,      ( date_t *, uint32_t, uint32_t ) ); 
     74VLC_EXPORT( void,    date_Change,    ( date_t *, uint32_t, uint32_t ) ); 
     75VLC_EXPORT( void,    date_Set,       ( date_t *, mtime_t ) ); 
     76VLC_EXPORT( mtime_t, date_Get,       ( const date_t * ) ); 
     77VLC_EXPORT( void,    date_Move,      ( date_t *, mtime_t ) ); 
     78VLC_EXPORT( mtime_t, date_Increment, ( date_t *, uint32_t ) ); 
  • include/vlc_common.h

    r9ea870a re414aa3  
    184184typedef struct vlc_t vlc_t; 
    185185typedef struct variable_t variable_t; 
     186typedef struct date_t date_t; 
    186187 
    187188/* Messages */ 
  • src/misc/mtime.c

    r1e67ea6 re414aa3  
    44 ***************************************************************************** 
    55 * Copyright (C) 1998-2004 VideoLAN 
    6  * $Id: mtime.c,v 1.43 2004/01/25 17:16:06 zorglub Exp
     6 * $Id
    77 * 
    88 * Authors: Vincent Seguin <seguin@via.ecp.fr> 
     
    324324} 
    325325 
     326/* 
     327 * Date management (internal and external) 
     328 */ 
     329 
     330/** 
     331 * Initialize a date_t. 
     332 * 
     333 * \param date to initialize 
     334 * \param divider (sample rate) numerator 
     335 * \param divider (sample rate) denominator 
     336 */ 
     337 
     338void date_Init( date_t *p_date, uint32_t i_divider_n, uint32_t i_divider_d ) 
     339{ 
     340    p_date->date = 0; 
     341    p_date->i_divider_num = i_divider_n; 
     342    p_date->i_divider_den = i_divider_d; 
     343    p_date->i_remainder = 0; 
     344} 
     345 
     346/** 
     347 * Change a date_t. 
     348 * 
     349 * \param date to change 
     350 * \param divider (sample rate) numerator 
     351 * \param divider (sample rate) denominator 
     352 */ 
     353 
     354void date_Change( date_t *p_date, uint32_t i_divider_n, uint32_t i_divider_d ) 
     355{ 
     356    p_date->i_divider_num = i_divider_n; 
     357    p_date->i_divider_den = i_divider_d; 
     358} 
     359 
     360/** 
     361 * Set the date value of a date_t. 
     362 * 
     363 * \param date to set 
     364 * \param date value 
     365 */ 
     366void date_Set( date_t *p_date, mtime_t i_new_date ) 
     367{ 
     368    p_date->date = i_new_date; 
     369    p_date->i_remainder = 0; 
     370} 
     371 
     372/** 
     373 * Get the date of a date_t 
     374 * 
     375 * \param date to get 
     376 * \return date value 
     377 */ 
     378mtime_t date_Get( const date_t *p_date ) 
     379{ 
     380    return p_date->date; 
     381} 
     382 
     383/** 
     384 * Move forwards or backwards the date of a date_t. 
     385 * 
     386 * \param date to move 
     387 * \param difference value 
     388 */ 
     389void date_Move( date_t *p_date, mtime_t i_difference ) 
     390{ 
     391    p_date->date += i_difference; 
     392} 
     393 
     394/** 
     395 * Increment the date and return the result, taking into account 
     396 * rounding errors. 
     397 * 
     398 * \param date to increment 
     399 * \param incrementation in number of samples 
     400 * \return date value 
     401 */ 
     402mtime_t date_Increment( date_t *p_date, uint32_t i_nb_samples ) 
     403{ 
     404    mtime_t i_dividend = (mtime_t)i_nb_samples * 1000000; 
     405    p_date->date += i_dividend / p_date->i_divider_num * p_date->i_divider_den; 
     406    p_date->i_remainder += (int)(i_dividend % p_date->i_divider_num); 
     407 
     408    if( p_date->i_remainder >= p_date->i_divider_num ) 
     409    { 
     410        /* This is Bresenham algorithm. */ 
     411        p_date->date += p_date->i_divider_den; 
     412        p_date->i_remainder -= p_date->i_divider_num; 
     413    } 
     414 
     415    return p_date->date; 
     416}