Changeset 2620


Ignore:
Timestamp:
Apr 20, 2009 2:19:11 PM (15 years ago)
Author:
bennylp
Message:

More ticket #774: added option to shift PCM input to encoder right by some value (default is 1) to make it compatible with some other app

Location:
pjproject/trunk
Files:
6 edited

Legend:

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

    r2563 r2620  
    238238 */ 
    239239#ifndef PJMEDIA_HAS_G7221_CODEC 
    240 #   define PJMEDIA_HAS_G7221_CODEC    0 
    241 #endif 
     240#   define PJMEDIA_HAS_G7221_CODEC              0 
     241#endif 
     242 
     243/** 
     244 * Default G.722.1 codec encoder and decoder level adjustment.  
     245 * If the value is non-zero, then PCM input samples to the encoder will  
     246 * be shifted right by this value, and similarly PCM output samples from 
     247 * the decoder will be shifted left by this value. 
     248 * 
     249 * This can be changed at run-time after initialization by calling 
     250 * #pjmedia_codec_g7221_set_pcm_shift(). 
     251 */ 
     252#ifndef PJMEDIA_G7221_DEFAULT_PCM_SHIFT 
     253#   define PJMEDIA_G7221_DEFAULT_PCM_SHIFT      1 
     254#endif 
     255 
    242256 
    243257 
  • pjproject/trunk/pjmedia/include/pjmedia-codec/g7221.h

    r2563 r2620  
    9494                                                  pj_bool_t enabled); 
    9595 
     96/** 
     97 * Set the G.722.1 codec encoder and decoder level adjustment.  
     98 * If the value is non-zero, then PCM input samples to the encoder will  
     99 * be shifted right by this value, and similarly PCM output samples from 
     100 * the decoder will be shifted left by this value. 
     101 * 
     102 * Default value is PJMEDIA_G7221_DEFAULT_PCM_SHIFT. 
     103 * 
     104 * @param val           The value 
     105 * 
     106 * @return              PJ_SUCCESS on success. 
     107 */ 
     108PJ_DECL(pj_status_t) pjmedia_codec_g7221_set_pcm_shift(int val); 
     109 
     110 
    96111 
    97112/** 
  • pjproject/trunk/pjmedia/src/pjmedia-codec/g7221.c

    r2616 r2620  
    138138    pj_mutex_t              *mutex;         /**< Codec factory mutex.       */ 
    139139 
     140    int                      pcm_shift;     /**< Level adjustment           */ 
    140141    unsigned                 mode_count;    /**< Number of G722.1 modes.    */ 
    141142    codec_mode               modes[MAX_CODEC_MODES]; /**< The G722.1 modes. */ 
     
    165166    pj_uint16_t          frame_size_bits;   /**< Coded frame size in bits.  */ 
    166167    pj_uint16_t          number_of_regions; /**< Number of regions.         */ 
     168    int                  pcm_shift;         /**< Adjustment for PCM in/out  */ 
    167169     
    168170    /* Encoder specific state */ 
     171    Word16              *enc_frame;         /**< 16bit to 14bit buffer      */ 
    169172    Word16              *enc_old_frame; 
    170173     
     
    252255    /* Initialize codec modes, by default all standard bitrates are enabled */ 
    253256    codec_factory.mode_count = 0; 
     257    codec_factory.pcm_shift = PJMEDIA_G7221_DEFAULT_PCM_SHIFT; 
    254258 
    255259    mode = &codec_factory.modes[codec_factory.mode_count++]; 
     
    409413 
    410414/* 
     415 * Set level adjustment. 
     416 */ 
     417PJ_DEF(pj_status_t)  pjmedia_codec_g7221_set_pcm_shift(int val) 
     418{ 
     419    codec_factory.pcm_shift = val; 
     420    return PJ_SUCCESS; 
     421} 
     422 
     423/* 
    411424 * Unregister G722.1 codec factory from pjmedia endpoint. 
    412425 */ 
     
    645658                                    (attr->info.clock_rate <= WB_SAMPLE_RATE? 
    646659                                     NUMBER_OF_REGIONS:MAX_NUMBER_OF_REGIONS); 
     660    codec_data->pcm_shift = codec_factory.pcm_shift; 
    647661 
    648662    /* Initialize encoder state */ 
    649663    tmp = codec_data->samples_per_frame << 1; 
    650664    codec_data->enc_old_frame = (Word16*)pj_pool_zalloc(pool, tmp); 
     665    codec_data->enc_frame = (Word16*)pj_pool_alloc(pool, tmp); 
    651666 
    652667    /* Initialize decoder state */ 
     
    734749{ 
    735750    codec_private_t *codec_data = (codec_private_t*) codec->codec_data; 
     751    const Word16 *pcm_input; 
    736752    Word16 mlt_coefs[MAX_SAMPLES_PER_FRAME]; 
    737753    Word16 mag_shift; 
     
    773789    } 
    774790 
     791    /* Encoder adjust the input signal level */ 
     792    if (codec_data->pcm_shift) { 
     793        unsigned i; 
     794        pcm_input = (const Word16*)input->buf; 
     795        for (i=0; i<codec_data->samples_per_frame; ++i) { 
     796            codec_data->enc_frame[i] =  
     797                (pj_int16_t)(pcm_input[i] >> codec_data->pcm_shift); 
     798        } 
     799        pcm_input = codec_data->enc_frame; 
     800    } else { 
     801        pcm_input = (const Word16*)input->buf; 
     802    } 
     803 
    775804    /* Convert input samples to rmlt coefs */ 
    776     mag_shift = samples_to_rmlt_coefs((Word16*)input->buf, 
     805    mag_shift = samples_to_rmlt_coefs(pcm_input, 
    777806                                      codec_data->enc_old_frame,  
    778807                                      mlt_coefs,  
     
    856885                          mag_shift); 
    857886 
     887    /* Decoder adjust PCM signal */ 
     888    if (codec_data->pcm_shift) { 
     889        unsigned i; 
     890        pj_int16_t *buf = (Word16*)output->buf; 
     891 
     892        for (i=0; i<codec_data->samples_per_frame; ++i) { 
     893            buf[i] <<= codec_data->pcm_shift; 
     894        } 
     895    } 
     896 
    858897    output->type = PJMEDIA_FRAME_TYPE_AUDIO; 
    859898    output->size = codec_data->samples_per_frame << 1; 
  • pjproject/trunk/pjmedia/src/test/codec_vectors.c

    r2615 r2620  
    573573        return -7; 
    574574    } 
     575 
     576    /* Set shift value to zero for the test vectors */ 
     577    pjmedia_codec_g7221_set_pcm_shift(0); 
    575578#endif 
    576579 
  • pjproject/trunk/third_party/g7221/common/defs.h

    r2563 r2620  
    141141                 Word16 frame_error_flag); 
    142142 
    143 Word16  samples_to_rmlt_coefs(Word16 *new_samples,Word16 *history,Word16 *coefs,Word16 dct_length); 
     143Word16  samples_to_rmlt_coefs(const Word16 *new_samples,Word16 *history,Word16 *coefs,Word16 dct_length); 
    144144void rmlt_coefs_to_samples(Word16 *coefs,      
    145145                           Word16 *old_samples,            
  • pjproject/trunk/third_party/g7221/encode/sam2coef.c

    r2616 r2620  
    6666***************************************************************************/ 
    6767 
    68 Word16 samples_to_rmlt_coefs(Word16 *new_samples,Word16 *old_samples,Word16 *coefs,Word16 dct_length) 
     68Word16 samples_to_rmlt_coefs(const Word16 *new_samples,Word16 *old_samples,Word16 *coefs,Word16 dct_length) 
    6969{ 
    7070 
    7171    Word16      index, vals_left,mag_shift,n; 
    7272    Word16      windowed_data[MAX_DCT_LENGTH]; 
    73     Word16      *new_ptr, *old_ptr, *sam_low, *sam_high; 
     73    Word16      *old_ptr; 
     74    const Word16 *new_ptr, *sam_low, *sam_high; 
    7475    Word16      *win_low, *win_high; 
    7576    Word16      *dst_ptr; 
Note: See TracChangeset for help on using the changeset viewer.