Index: /pjproject/trunk/pjmedia/include/pjmedia-codec/config.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia-codec/config.h	(revision 2619)
+++ /pjproject/trunk/pjmedia/include/pjmedia-codec/config.h	(revision 2620)
@@ -238,6 +238,20 @@
  */
 #ifndef PJMEDIA_HAS_G7221_CODEC
-#   define PJMEDIA_HAS_G7221_CODEC    0
-#endif
+#   define PJMEDIA_HAS_G7221_CODEC		0
+#endif
+
+/**
+ * Default G.722.1 codec encoder and decoder level adjustment. 
+ * If the value is non-zero, then PCM input samples to the encoder will 
+ * be shifted right by this value, and similarly PCM output samples from
+ * the decoder will be shifted left by this value.
+ *
+ * This can be changed at run-time after initialization by calling
+ * #pjmedia_codec_g7221_set_pcm_shift().
+ */
+#ifndef PJMEDIA_G7221_DEFAULT_PCM_SHIFT
+#   define PJMEDIA_G7221_DEFAULT_PCM_SHIFT	1
+#endif
+
 
 
Index: /pjproject/trunk/pjmedia/include/pjmedia-codec/g7221.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia-codec/g7221.h	(revision 2619)
+++ /pjproject/trunk/pjmedia/include/pjmedia-codec/g7221.h	(revision 2620)
@@ -94,4 +94,19 @@
 						  pj_bool_t enabled);
 
+/**
+ * Set the G.722.1 codec encoder and decoder level adjustment. 
+ * If the value is non-zero, then PCM input samples to the encoder will 
+ * be shifted right by this value, and similarly PCM output samples from
+ * the decoder will be shifted left by this value.
+ *
+ * Default value is PJMEDIA_G7221_DEFAULT_PCM_SHIFT.
+ *
+ * @param val		The value
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_codec_g7221_set_pcm_shift(int val);
+
+
 
 /**
Index: /pjproject/trunk/pjmedia/src/pjmedia-codec/g7221.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia-codec/g7221.c	(revision 2619)
+++ /pjproject/trunk/pjmedia/src/pjmedia-codec/g7221.c	(revision 2620)
@@ -138,4 +138,5 @@
     pj_mutex_t		    *mutex;	    /**< Codec factory mutex.	    */
 
+    int			     pcm_shift;	    /**< Level adjustment	    */
     unsigned		     mode_count;    /**< Number of G722.1 modes.    */
     codec_mode		     modes[MAX_CODEC_MODES]; /**< The G722.1 modes. */
@@ -165,6 +166,8 @@
     pj_uint16_t		 frame_size_bits;   /**< Coded frame size in bits.  */
     pj_uint16_t		 number_of_regions; /**< Number of regions.	    */
+    int			 pcm_shift;	    /**< Adjustment for PCM in/out  */
     
     /* Encoder specific state */
+    Word16		*enc_frame;	    /**< 16bit to 14bit buffer	    */
     Word16		*enc_old_frame;
     
@@ -252,4 +255,5 @@
     /* Initialize codec modes, by default all standard bitrates are enabled */
     codec_factory.mode_count = 0;
+    codec_factory.pcm_shift = PJMEDIA_G7221_DEFAULT_PCM_SHIFT;
 
     mode = &codec_factory.modes[codec_factory.mode_count++];
@@ -409,4 +413,13 @@
 
 /*
+ * Set level adjustment.
+ */
+PJ_DEF(pj_status_t)  pjmedia_codec_g7221_set_pcm_shift(int val)
+{
+    codec_factory.pcm_shift = val;
+    return PJ_SUCCESS;
+}
+
+/*
  * Unregister G722.1 codec factory from pjmedia endpoint.
  */
@@ -645,8 +658,10 @@
 				    (attr->info.clock_rate <= WB_SAMPLE_RATE?
 				     NUMBER_OF_REGIONS:MAX_NUMBER_OF_REGIONS);
+    codec_data->pcm_shift = codec_factory.pcm_shift;
 
     /* Initialize encoder state */
     tmp = codec_data->samples_per_frame << 1;
     codec_data->enc_old_frame = (Word16*)pj_pool_zalloc(pool, tmp);
+    codec_data->enc_frame = (Word16*)pj_pool_alloc(pool, tmp);
 
     /* Initialize decoder state */
@@ -734,4 +749,5 @@
 {
     codec_private_t *codec_data = (codec_private_t*) codec->codec_data;
+    const Word16 *pcm_input;
     Word16 mlt_coefs[MAX_SAMPLES_PER_FRAME];
     Word16 mag_shift;
@@ -773,6 +789,19 @@
     }
 
+    /* Encoder adjust the input signal level */
+    if (codec_data->pcm_shift) {
+	unsigned i;
+	pcm_input = (const Word16*)input->buf;
+	for (i=0; i<codec_data->samples_per_frame; ++i) {
+	    codec_data->enc_frame[i] = 
+		(pj_int16_t)(pcm_input[i] >> codec_data->pcm_shift);
+	}
+	pcm_input = codec_data->enc_frame;
+    } else {
+	pcm_input = (const Word16*)input->buf;
+    }
+
     /* Convert input samples to rmlt coefs */
-    mag_shift = samples_to_rmlt_coefs((Word16*)input->buf,
+    mag_shift = samples_to_rmlt_coefs(pcm_input,
 				      codec_data->enc_old_frame, 
 				      mlt_coefs, 
@@ -856,4 +885,14 @@
 			  mag_shift);
 
+    /* Decoder adjust PCM signal */
+    if (codec_data->pcm_shift) {
+	unsigned i;
+	pj_int16_t *buf = (Word16*)output->buf;
+
+	for (i=0; i<codec_data->samples_per_frame; ++i) {
+	    buf[i] <<= codec_data->pcm_shift;
+	}
+    }
+
     output->type = PJMEDIA_FRAME_TYPE_AUDIO;
     output->size = codec_data->samples_per_frame << 1;
Index: /pjproject/trunk/pjmedia/src/test/codec_vectors.c
===================================================================
--- /pjproject/trunk/pjmedia/src/test/codec_vectors.c	(revision 2619)
+++ /pjproject/trunk/pjmedia/src/test/codec_vectors.c	(revision 2620)
@@ -573,4 +573,7 @@
 	return -7;
     }
+
+    /* Set shift value to zero for the test vectors */
+    pjmedia_codec_g7221_set_pcm_shift(0);
 #endif
 
Index: /pjproject/trunk/third_party/g7221/common/defs.h
===================================================================
--- /pjproject/trunk/third_party/g7221/common/defs.h	(revision 2619)
+++ /pjproject/trunk/third_party/g7221/common/defs.h	(revision 2620)
@@ -141,5 +141,5 @@
 	         Word16 frame_error_flag);
 
-Word16  samples_to_rmlt_coefs(Word16 *new_samples,Word16 *history,Word16 *coefs,Word16 dct_length);
+Word16  samples_to_rmlt_coefs(const Word16 *new_samples,Word16 *history,Word16 *coefs,Word16 dct_length);
 void rmlt_coefs_to_samples(Word16 *coefs,     
                            Word16 *old_samples,           
Index: /pjproject/trunk/third_party/g7221/encode/sam2coef.c
===================================================================
--- /pjproject/trunk/third_party/g7221/encode/sam2coef.c	(revision 2619)
+++ /pjproject/trunk/third_party/g7221/encode/sam2coef.c	(revision 2620)
@@ -66,10 +66,11 @@
 ***************************************************************************/
 
-Word16 samples_to_rmlt_coefs(Word16 *new_samples,Word16 *old_samples,Word16 *coefs,Word16 dct_length)
+Word16 samples_to_rmlt_coefs(const Word16 *new_samples,Word16 *old_samples,Word16 *coefs,Word16 dct_length)
 {
 
     Word16	index, vals_left,mag_shift,n;
     Word16	windowed_data[MAX_DCT_LENGTH];
-    Word16	*new_ptr, *old_ptr, *sam_low, *sam_high;
+    Word16	*old_ptr;
+    const Word16 *new_ptr, *sam_low, *sam_high;
     Word16	*win_low, *win_high;
     Word16	*dst_ptr;
