Changeset 3202
- Timestamp:
- Jun 11, 2010 1:38:42 PM (14 years ago)
- Location:
- pjproject/trunk/pjmedia
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia-codec/config.h
r2875 r3202 95 95 #ifndef PJMEDIA_HAS_G722_CODEC 96 96 # define PJMEDIA_HAS_G722_CODEC 1 97 #endif 98 99 100 /** 101 * Default G.722 codec encoder and decoder level adjustment. The G.722 102 * specifies that it uses 14 bit PCM for input and output, while PJMEDIA 103 * normally uses 16 bit PCM, so the conversion is done by applying 104 * level adjustment. If the value is non-zero, then PCM input samples to 105 * the encoder will be shifted right by this value, and similarly PCM 106 * output samples from the decoder will be shifted left by this value. 107 * 108 * This can be changed at run-time after initialization by calling 109 * #pjmedia_codec_g722_set_pcm_shift(). 110 * 111 * Default: 2. 112 */ 113 #ifndef PJMEDIA_G722_DEFAULT_PCM_SHIFT 114 # define PJMEDIA_G722_DEFAULT_PCM_SHIFT 2 115 #endif 116 117 118 /** 119 * Specifies whether G.722 PCM shifting should be stopped when clipping 120 * detected in the decoder. Enabling this feature can be useful when 121 * talking to G.722 implementation that uses 16 bit PCM for G.722 input/ 122 * output (for any reason it seems to work) and the PCM shifting causes 123 * audio clipping. 124 * 125 * See also #PJMEDIA_G722_DEFAULT_PCM_SHIFT. 126 * 127 * Default: enabled. 128 */ 129 #ifndef PJMEDIA_G722_STOP_PCM_SHIFT_ON_CLIPPING 130 # define PJMEDIA_G722_STOP_PCM_SHIFT_ON_CLIPPING 1 97 131 #endif 98 132 -
pjproject/trunk/pjmedia/include/pjmedia-codec/g722.h
r3083 r3202 79 79 80 80 81 /** 82 * Set the G.722 codec encoder and decoder level adjustment. 83 * If the value is non-zero, then PCM input samples to the encoder will 84 * be shifted right by this value, and similarly PCM output samples from 85 * the decoder will be shifted left by this value. 86 * 87 * Default value is PJMEDIA_G722_DEFAULT_PCM_SHIFT. 88 * 89 * @param val The value 90 * 91 * @return PJ_SUCCESS on success. 92 */ 93 PJ_DECL(pj_status_t) pjmedia_codec_g722_set_pcm_shift(unsigned val); 94 95 81 96 PJ_END_DECL 82 97 -
pjproject/trunk/pjmedia/src/pjmedia-codec/g722.c
r2760 r3202 134 134 pj_mutex_t *mutex; 135 135 pjmedia_codec codec_list; 136 unsigned pcm_shift; 136 137 } g722_codec_factory; 137 138 … … 142 143 g722_enc_t encoder; 143 144 g722_dec_t decoder; 145 unsigned pcm_shift; 146 pj_int16_t pcm_clip_mask; 144 147 pj_bool_t plc_enabled; 145 148 pj_bool_t vad_enabled; … … 168 171 g722_codec_factory.base.factory_data = NULL; 169 172 g722_codec_factory.endpt = endpt; 173 g722_codec_factory.pcm_shift = PJMEDIA_G722_DEFAULT_PCM_SHIFT; 170 174 171 175 g722_codec_factory.pool = pjmedia_endpt_create_pool(endpt, "g722", 1000, … … 240 244 return status; 241 245 } 246 247 248 /* 249 * Set level adjustment. 250 */ 251 PJ_DEF(pj_status_t) pjmedia_codec_g722_set_pcm_shift(unsigned val) 252 { 253 g722_codec_factory.pcm_shift = val; 254 return PJ_SUCCESS; 255 } 256 242 257 243 258 /* … … 447 462 g722_data->vad_enabled = (attr->setting.vad != 0); 448 463 g722_data->plc_enabled = (attr->setting.plc != 0); 464 g722_data->pcm_shift = g722_codec_factory.pcm_shift; 465 g722_data->pcm_clip_mask = (pj_int16_t)(1<<g722_codec_factory.pcm_shift)-1; 466 g722_data->pcm_clip_mask <<= (16-g722_codec_factory.pcm_shift); 449 467 450 468 TRACE_((THIS_FILE, "G722 codec opened: vad=%d, plc=%d", … … 566 584 } 567 585 586 /* Adjust input signal level from 16-bit to 14-bit */ 587 if (g722_data->pcm_shift) { 588 pj_int16_t *p, *end; 589 590 p = (pj_int16_t*)input->buf; 591 end = p + input->size; 592 while (p < end) { 593 *p++ >>= g722_data->pcm_shift; 594 } 595 } 596 568 597 /* Encode to temporary buffer */ 569 598 output->size = output_buf_len; … … 624 653 625 654 pj_assert(output->size == SAMPLES_PER_FRAME); 655 656 /* Adjust input signal level from 14-bit to 16-bit */ 657 if (g722_data->pcm_shift) { 658 pj_int16_t *p, *end; 659 660 p = (pj_int16_t*)output->buf; 661 end = p + output->size; 662 while (p < end) { 663 #if PJMEDIA_G722_STOP_PCM_SHIFT_ON_CLIPPING 664 /* If there is clipping, stop the PCM shifting */ 665 if (*p & g722_data->pcm_clip_mask) { 666 g722_data->pcm_shift = 0; 667 break; 668 } 669 #endif 670 *p++ <<= g722_data->pcm_shift; 671 } 672 } 673 626 674 output->size = SAMPLES_PER_FRAME * 2; 627 675 output->type = PJMEDIA_FRAME_TYPE_AUDIO; -
pjproject/trunk/pjmedia/src/pjmedia-codec/g722/g722_dec.c
r2394 r3202 505 505 int ilowr, ylow, rlow, dlowt; 506 506 int ihigh, rhigh, dhigh; 507 int pcm1, pcm2;508 507 pj_uint8_t *in_ = (pj_uint8_t*) in; 509 508 … … 530 529 /* rhigh <= output high band pcm */ 531 530 532 rx_qmf(dec, rlow, rhigh, &pcm1, &pcm2); 533 out[i*2] = (pj_int16_t)(pcm1 << 2); 534 out[i*2+1] = (pj_int16_t)(pcm2 << 2); 531 rx_qmf(dec, rlow, rhigh, &out[i*2], &out[i*2+1]); 535 532 } 536 533 -
pjproject/trunk/pjmedia/src/pjmedia-codec/g722/g722_enc.c
r2394 r3202 544 544 545 545 for(i = 0; i < nsamples; i += 2) { 546 tx_qmf(enc, in[i] >>2, in[i+1]>>2, &xlow, &xhigh);546 tx_qmf(enc, in[i], in[i+1], &xlow, &xhigh); 547 547 548 548 /* low band encoder */
Note: See TracChangeset
for help on using the changeset viewer.