Commit eb8a2ee0 authored by Simon Morlat's avatar Simon Morlat

since G722 implementation is bit exact and uses 14 bit input, shift input...

since G722 implementation is bit exact and uses 14 bit input, shift input right and left to avoid saturation.
The bit shift should be 2, but for some reason (??) 1 seems enough.
parent b501ae52
......@@ -30,6 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#else
/*otherwise use built-in version, forked from spandsp a long time ago and that has a public license.*/
#include "g722.h"
#include <../intl/gettextP.h>
#endif
struct EncState {
......@@ -58,6 +59,18 @@ static void enc_uninit(MSFilter *f)
f->data = 0;
};
static void scale_down(int16_t *samples, int count){
int i;
for (i=0;i<count;++i)
samples[i]=samples[i]>>1;
}
static void scale_up(int16_t *samples, int count){
int i;
for (i=0;i<count;++i)
samples[i]=samples[i]<<1;
}
static void enc_process(MSFilter *f)
{
struct EncState *s=(struct EncState*)f->data;
......@@ -84,6 +97,7 @@ static void enc_process(MSFilter *f)
mblk_t *om=allocb(nbytes*frame_per_packet,0);//too large...
int k;
scale_down((int16_t *)buf,chunksize/2);
k = g722_encode(s->state, om->b_wptr, (int16_t *)buf, chunksize/2);
om->b_wptr += k;
mblk_set_timestamp_info(om,s->ts);
......@@ -201,6 +215,7 @@ static void dec_process(MSFilter *f)
ms_warning("g722_decode error!");
freemsg(om);
} else {
scale_up((int16_t *)om->b_wptr,declen);
om->b_wptr += declen*2;
ms_queue_put(f->outputs[0],om);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment