Changeset 2281


Ignore:
Timestamp:
Sep 16, 2008 2:33:16 PM (11 years ago)
Author:
bennylp
Message:

Ticket #619: added configuration to force floating point algorithm to be used in the tone generator, and added fade-in and fade out options

Location:
pjproject/trunk/pjmedia
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia/config.h

    r2215 r2281  
    542542 * more CPU load. This is only applied to floating point enabled machines. 
    543543 * 
    544  * By default it is enabled. 
     544 * By default it is enabled when PJ_HAS_FLOATING_POINT is set. 
     545 * 
     546 * @see PJMEDIA_TONEGEN_FORCE_FLOAT 
    545547 */ 
    546548#ifndef PJMEDIA_USE_HIGH_QUALITY_TONEGEN 
    547 #   define PJMEDIA_USE_HIGH_QUALITY_TONEGEN         1 
     549#   define PJMEDIA_USE_HIGH_QUALITY_TONEGEN         PJ_HAS_FLOATING_POINT 
     550#endif 
     551 
     552 
     553/** 
     554 * Force the tone generation to use floating point computation, even when 
     555 * PJ_HAS_FLOATING_POINT is disabled. This may be necessary if the tone 
     556 * generator is used to produce DTMF to be sent inband, since the fixed 
     557 * point algorithm may not have the correct frequency accuracy. 
     558 * 
     559 * This option, combined with PJ_HAS_FLOATING_POINT will produce the  
     560 * following selection of tone generator algorithm: 
     561 *  - if both PJ_HAS_FLOATING_POINT and PJMEDIA_USE_HIGH_QUALITY_TONEGEN  
     562 *    are set, the standard sin() function will be used. This will produce 
     563 *    the highest quality tones, at the expense of more processing power. 
     564 *  - if PJ_HAS_FLOATING_POINT is not set: 
     565 *      - if both PJMEDIA_USE_HIGH_QUALITY_TONEGEN and  
     566 *        PJMEDIA_TONEGEN_FORCE_FLOAT are set, sin() based algorithm will 
     567 *        be used (similar as above). 
     568 *      - if PJMEDIA_USE_HIGH_QUALITY_TONEGEN is not set but the 
     569 *        PJMEDIA_TONEGEN_FORCE_FLOAT is set, a floating point approximation 
     570 *        algorithm will be used. This should produce good enough tone 
     571 *        for most uses, and the performance is faster than using pure 
     572 *        sin() based algorithm. Note that linking to math library may 
     573 *        still be needed. 
     574 *      - if both are not set, the fixed point approximation algorithm 
     575 *        will be used. 
     576 * 
     577 * Default: 1 
     578 */ 
     579#ifndef PJMEDIA_TONEGEN_FORCE_FLOAT 
     580#   define PJMEDIA_TONEGEN_FORCE_FLOAT              1 
     581#endif 
     582 
     583 
     584/** 
     585 * Fade-in duration for the tone, in milliseconds. Set to zero to disable 
     586 * this feature. 
     587 * 
     588 * Default: 1 (msec) 
     589 */ 
     590#ifndef PJMEDIA_TONEGEN_FADE_IN_TIME 
     591#   define PJMEDIA_TONEGEN_FADE_IN_TIME             1 
     592#endif 
     593 
     594 
     595/** 
     596 * Fade-out duration for the tone, in milliseconds. Set to zero to disable 
     597 * this feature. 
     598 * 
     599 * Default: 2 (msec) 
     600 */ 
     601#ifndef PJMEDIA_TONEGEN_FADE_OUT_TIME 
     602#   define PJMEDIA_TONEGEN_FADE_OUT_TIME            2 
    548603#endif 
    549604 
  • pjproject/trunk/pjmedia/src/pjmedia/tonegen.c

    r2039 r2281  
    3939 
    4040 
    41 #if defined(PJ_HAS_FLOATING_POINT) && PJ_HAS_FLOATING_POINT!=0 
     41#if (defined(PJ_HAS_FLOATING_POINT) && PJ_HAS_FLOATING_POINT!=0) || \ 
     42    (defined(PJMEDIA_TONEGEN_FORCE_FLOAT) && PJMEDIA_TONEGEN_FORCE_FLOAT != 0) 
    4243#   include <math.h> 
    4344 
     
    250251    unsigned            options; 
    251252    unsigned            playback_options; 
     253    unsigned            fade_in_len;    /* fade in for this # of samples */ 
     254    unsigned            fade_out_len;   /* fade out for this # of samples*/ 
    252255 
    253256    /* lock */ 
     
    336339    tonegen->digit_map = &digit_map; 
    337340 
     341    tonegen->fade_in_len = PJMEDIA_TONEGEN_FADE_IN_TIME * clock_rate / 1000; 
     342    tonegen->fade_out_len = PJMEDIA_TONEGEN_FADE_OUT_TIME * clock_rate / 1000; 
     343 
    338344    /* Lock */ 
    339345    if (options & PJMEDIA_TONEGEN_NO_LOCK) { 
     
    534540            generate_tone(&tonegen->state, port->info.channel_count, 
    535541                          cnt, dst); 
     542 
    536543            dst += cnt; 
    537544            tonegen->dig_samples += cnt; 
    538545            required -= cnt; 
     546 
     547            if (tonegen->dig_samples == cnt) { 
     548                /* Fade in */ 
     549                short *samp = (dst - cnt); 
     550                short *end; 
     551 
     552                if (cnt > tonegen->fade_in_len) 
     553                    cnt = tonegen->fade_in_len; 
     554                end = samp + cnt; 
     555                if (cnt) { 
     556                    const unsigned step = 0xFFFF / cnt; 
     557                    unsigned scale = 0; 
     558 
     559                    for (; samp < end; ++samp) { 
     560                        (*samp) = (short)(((*samp) * scale) >> 16); 
     561                        scale += step; 
     562                    } 
     563                } 
     564            } else if (tonegen->dig_samples == on_samp) { 
     565                /* Fade out */ 
     566                if (cnt > tonegen->fade_out_len) 
     567                    cnt = tonegen->fade_out_len; 
     568                if (cnt) { 
     569                    short *samp = (dst - cnt); 
     570                    const unsigned step = 0xFFFF / cnt; 
     571                    unsigned scale = 0xFFFF - step; 
     572 
     573                    for (; samp < dst; ++samp) { 
     574                        (*samp) = (short)(((*samp) * scale) >> 16); 
     575                        scale -= step; 
     576                    } 
     577                } 
     578            } 
    539579 
    540580            if (dst == end) 
Note: See TracChangeset for help on using the changeset viewer.