|
|
|
@ -102,8 +102,7 @@ struct adpcm_state {
|
|
|
|
|
* Sets the index to the step size table for the next encode.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static inline short
|
|
|
|
|
decode(int encoded, struct adpcm_state* state)
|
|
|
|
|
static inline short decode(int encoded, struct adpcm_state *state)
|
|
|
|
|
{
|
|
|
|
|
int diff;
|
|
|
|
|
int step;
|
|
|
|
@ -117,9 +116,12 @@ decode(int encoded, struct adpcm_state* state)
|
|
|
|
|
diff = (((encoded << 1) + 1) * step) >> 3;
|
|
|
|
|
#else /* BLI code */
|
|
|
|
|
diff = step >> 3;
|
|
|
|
|
if (encoded & 4) diff += step;
|
|
|
|
|
if (encoded & 2) diff += step >> 1;
|
|
|
|
|
if (encoded & 1) diff += step >> 2;
|
|
|
|
|
if (encoded & 4)
|
|
|
|
|
diff += step;
|
|
|
|
|
if (encoded & 2)
|
|
|
|
|
diff += step >> 1;
|
|
|
|
|
if (encoded & 1)
|
|
|
|
|
diff += step >> 2;
|
|
|
|
|
if ((encoded >> 1) & step & 0x1)
|
|
|
|
|
diff++;
|
|
|
|
|
#endif
|
|
|
|
@ -143,8 +145,7 @@ decode(int encoded, struct adpcm_state* state)
|
|
|
|
|
#ifdef AUTO_RETURN
|
|
|
|
|
if (encoded)
|
|
|
|
|
state->zero_count = 0;
|
|
|
|
|
else if (++(state->zero_count) == 24)
|
|
|
|
|
{
|
|
|
|
|
else if (++(state->zero_count) == 24) {
|
|
|
|
|
state->zero_count = 0;
|
|
|
|
|
if (state->signal > 0)
|
|
|
|
|
state->next_flag = 0x1;
|
|
|
|
@ -174,8 +175,7 @@ decode(int encoded, struct adpcm_state* state)
|
|
|
|
|
* signal gets updated with each pass.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
adpcm(short csig, struct adpcm_state* state)
|
|
|
|
|
static inline int adpcm(short csig, struct adpcm_state *state)
|
|
|
|
|
{
|
|
|
|
|
int diff;
|
|
|
|
|
int step;
|
|
|
|
@ -190,35 +190,28 @@ adpcm(short csig, struct adpcm_state* state)
|
|
|
|
|
diff = csig - state->signal;
|
|
|
|
|
|
|
|
|
|
#ifdef NOT_BLI
|
|
|
|
|
if (diff < 0)
|
|
|
|
|
{
|
|
|
|
|
if (diff < 0) {
|
|
|
|
|
encoded = (-diff << 2) / step;
|
|
|
|
|
if (encoded > 7)
|
|
|
|
|
encoded = 7;
|
|
|
|
|
encoded |= 0x08;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
} else {
|
|
|
|
|
encoded = (diff << 2) / step;
|
|
|
|
|
if (encoded > 7)
|
|
|
|
|
encoded = 7;
|
|
|
|
|
}
|
|
|
|
|
#else /* BLI code */
|
|
|
|
|
if (diff < 0)
|
|
|
|
|
{
|
|
|
|
|
if (diff < 0) {
|
|
|
|
|
encoded = 8;
|
|
|
|
|
diff = -diff;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
} else
|
|
|
|
|
encoded = 0;
|
|
|
|
|
if (diff >= step)
|
|
|
|
|
{
|
|
|
|
|
if (diff >= step) {
|
|
|
|
|
encoded |= 4;
|
|
|
|
|
diff -= step;
|
|
|
|
|
}
|
|
|
|
|
step >>= 1;
|
|
|
|
|
if (diff >= step)
|
|
|
|
|
{
|
|
|
|
|
if (diff >= step) {
|
|
|
|
|
encoded |= 2;
|
|
|
|
|
diff -= step;
|
|
|
|
|
}
|
|
|
|
@ -272,20 +265,18 @@ struct adpcm_decoder_pvt
|
|
|
|
|
* None.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static struct ast_translator_pvt *
|
|
|
|
|
adpcmtolin_new (void)
|
|
|
|
|
static struct ast_translator_pvt *adpcmtolin_new(void)
|
|
|
|
|
{
|
|
|
|
|
struct adpcm_decoder_pvt *tmp;
|
|
|
|
|
tmp = malloc (sizeof (struct adpcm_decoder_pvt));
|
|
|
|
|
if (tmp)
|
|
|
|
|
{
|
|
|
|
|
tmp = malloc(sizeof(struct adpcm_decoder_pvt));
|
|
|
|
|
if (tmp) {
|
|
|
|
|
memset(tmp, 0, sizeof(*tmp));
|
|
|
|
|
tmp->tail = 0;
|
|
|
|
|
plc_init(&tmp->plc);
|
|
|
|
|
localusecnt++;
|
|
|
|
|
ast_update_use_count ();
|
|
|
|
|
ast_update_use_count();
|
|
|
|
|
}
|
|
|
|
|
return (struct ast_translator_pvt *) tmp;
|
|
|
|
|
return (struct ast_translator_pvt *)tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -299,19 +290,17 @@ adpcmtolin_new (void)
|
|
|
|
|
* None.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static struct ast_translator_pvt *
|
|
|
|
|
lintoadpcm_new (void)
|
|
|
|
|
static struct ast_translator_pvt *lintoadpcm_new(void)
|
|
|
|
|
{
|
|
|
|
|
struct adpcm_encoder_pvt *tmp;
|
|
|
|
|
tmp = malloc (sizeof (struct adpcm_encoder_pvt));
|
|
|
|
|
if (tmp)
|
|
|
|
|
{
|
|
|
|
|
tmp = malloc(sizeof(struct adpcm_encoder_pvt));
|
|
|
|
|
if (tmp) {
|
|
|
|
|
memset(tmp, 0, sizeof(*tmp));
|
|
|
|
|
localusecnt++;
|
|
|
|
|
ast_update_use_count ();
|
|
|
|
|
ast_update_use_count();
|
|
|
|
|
tmp->tail = 0;
|
|
|
|
|
}
|
|
|
|
|
return (struct ast_translator_pvt *) tmp;
|
|
|
|
|
return (struct ast_translator_pvt *)tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -326,10 +315,9 @@ lintoadpcm_new (void)
|
|
|
|
|
* tmp->tail is the number of packed values in the buffer.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
adpcmtolin_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
|
|
|
|
|
static int adpcmtolin_framein(struct ast_translator_pvt *pvt, struct ast_frame *f)
|
|
|
|
|
{
|
|
|
|
|
struct adpcm_decoder_pvt *tmp = (struct adpcm_decoder_pvt *) pvt;
|
|
|
|
|
struct adpcm_decoder_pvt *tmp = (struct adpcm_decoder_pvt *)pvt;
|
|
|
|
|
int x;
|
|
|
|
|
unsigned char *b;
|
|
|
|
|
|
|
|
|
@ -357,7 +345,8 @@ adpcmtolin_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
|
|
|
|
|
tmp->outbuf[tmp->tail++] = decode(b[x] & 0x0f, &tmp->state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(useplc) plc_rx(&tmp->plc, tmp->outbuf+tmp->tail-f->datalen*2, f->datalen*2);
|
|
|
|
|
if(useplc)
|
|
|
|
|
plc_rx(&tmp->plc, tmp->outbuf+tmp->tail-f->datalen*2, f->datalen*2);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -374,17 +363,16 @@ adpcmtolin_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
|
|
|
|
|
* None.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static struct ast_frame *
|
|
|
|
|
adpcmtolin_frameout (struct ast_translator_pvt *pvt)
|
|
|
|
|
static struct ast_frame *adpcmtolin_frameout(struct ast_translator_pvt *pvt)
|
|
|
|
|
{
|
|
|
|
|
struct adpcm_decoder_pvt *tmp = (struct adpcm_decoder_pvt *) pvt;
|
|
|
|
|
struct adpcm_decoder_pvt *tmp = (struct adpcm_decoder_pvt *)pvt;
|
|
|
|
|
|
|
|
|
|
if (!tmp->tail)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
tmp->f.frametype = AST_FRAME_VOICE;
|
|
|
|
|
tmp->f.subclass = AST_FORMAT_SLINEAR;
|
|
|
|
|
tmp->f.datalen = tmp->tail *2;
|
|
|
|
|
tmp->f.datalen = tmp->tail * 2;
|
|
|
|
|
tmp->f.samples = tmp->tail;
|
|
|
|
|
tmp->f.mallocd = 0;
|
|
|
|
|
tmp->f.offset = AST_FRIENDLY_OFFSET;
|
|
|
|
@ -405,19 +393,15 @@ adpcmtolin_frameout (struct ast_translator_pvt *pvt)
|
|
|
|
|
* tmp->tail is number of signal values in the input buffer.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
lintoadpcm_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
|
|
|
|
|
static int lintoadpcm_framein(struct ast_translator_pvt *pvt, struct ast_frame *f)
|
|
|
|
|
{
|
|
|
|
|
struct adpcm_encoder_pvt *tmp = (struct adpcm_encoder_pvt *) pvt;
|
|
|
|
|
struct adpcm_encoder_pvt *tmp = (struct adpcm_encoder_pvt *)pvt;
|
|
|
|
|
|
|
|
|
|
if ((tmp->tail + f->datalen / 2) < (sizeof (tmp->inbuf) / 2))
|
|
|
|
|
{
|
|
|
|
|
memcpy (&tmp->inbuf[tmp->tail], f->data, f->datalen);
|
|
|
|
|
if ((tmp->tail + f->datalen / 2) < (sizeof(tmp->inbuf) / 2)) {
|
|
|
|
|
memcpy(&tmp->inbuf[tmp->tail], f->data, f->datalen);
|
|
|
|
|
tmp->tail += f->datalen / 2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ast_log (LOG_WARNING, "Out of buffer space\n");
|
|
|
|
|
} else {
|
|
|
|
|
ast_log(LOG_WARNING, "Out of buffer space\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
@ -435,14 +419,13 @@ lintoadpcm_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
|
|
|
|
|
* Leftover inbuf data gets packed, tail gets updated.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static struct ast_frame *
|
|
|
|
|
lintoadpcm_frameout (struct ast_translator_pvt *pvt)
|
|
|
|
|
static struct ast_frame *lintoadpcm_frameout(struct ast_translator_pvt *pvt)
|
|
|
|
|
{
|
|
|
|
|
struct adpcm_encoder_pvt *tmp = (struct adpcm_encoder_pvt *) pvt;
|
|
|
|
|
struct adpcm_encoder_pvt *tmp = (struct adpcm_encoder_pvt *)pvt;
|
|
|
|
|
int i_max, i;
|
|
|
|
|
|
|
|
|
|
if (tmp->tail < 2) return NULL;
|
|
|
|
|
|
|
|
|
|
if (tmp->tail < 2)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
i_max = tmp->tail & ~1; /* atomic size is 2 samples */
|
|
|
|
|
|
|
|
|
@ -453,14 +436,12 @@ lintoadpcm_frameout (struct ast_translator_pvt *pvt)
|
|
|
|
|
tmp->outbuf[3] = tmp->zero_count;
|
|
|
|
|
tmp->outbuf[4] = tmp->next_flag;
|
|
|
|
|
*/
|
|
|
|
|
for (i = 0; i < i_max; i+=2)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < i_max; i+=2) {
|
|
|
|
|
tmp->outbuf[i/2] =
|
|
|
|
|
(adpcm(tmp->inbuf[i ], &tmp->state) << 4) |
|
|
|
|
|
(adpcm(tmp->inbuf[i+1], &tmp->state) );
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tmp->f.frametype = AST_FRAME_VOICE;
|
|
|
|
|
tmp->f.subclass = AST_FORMAT_ADPCM;
|
|
|
|
|
tmp->f.samples = i_max;
|
|
|
|
@ -477,8 +458,7 @@ lintoadpcm_frameout (struct ast_translator_pvt *pvt)
|
|
|
|
|
|
|
|
|
|
if (tmp->tail == i_max)
|
|
|
|
|
tmp->tail = 0;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
else {
|
|
|
|
|
tmp->inbuf[0] = tmp->inbuf[tmp->tail];
|
|
|
|
|
tmp->tail = 1;
|
|
|
|
|
}
|
|
|
|
@ -490,13 +470,12 @@ lintoadpcm_frameout (struct ast_translator_pvt *pvt)
|
|
|
|
|
* AdpcmToLin_Sample
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static struct ast_frame *
|
|
|
|
|
adpcmtolin_sample (void)
|
|
|
|
|
static struct ast_frame *adpcmtolin_sample(void)
|
|
|
|
|
{
|
|
|
|
|
static struct ast_frame f;
|
|
|
|
|
f.frametype = AST_FRAME_VOICE;
|
|
|
|
|
f.subclass = AST_FORMAT_ADPCM;
|
|
|
|
|
f.datalen = sizeof (adpcm_slin_ex);
|
|
|
|
|
f.datalen = sizeof(adpcm_slin_ex);
|
|
|
|
|
f.samples = sizeof(adpcm_slin_ex) * 2;
|
|
|
|
|
f.mallocd = 0;
|
|
|
|
|
f.offset = 0;
|
|
|
|
@ -509,15 +488,14 @@ adpcmtolin_sample (void)
|
|
|
|
|
* LinToAdpcm_Sample
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static struct ast_frame *
|
|
|
|
|
lintoadpcm_sample (void)
|
|
|
|
|
static struct ast_frame *lintoadpcm_sample(void)
|
|
|
|
|
{
|
|
|
|
|
static struct ast_frame f;
|
|
|
|
|
f.frametype = AST_FRAME_VOICE;
|
|
|
|
|
f.subclass = AST_FORMAT_SLINEAR;
|
|
|
|
|
f.datalen = sizeof (slin_adpcm_ex);
|
|
|
|
|
f.datalen = sizeof(slin_adpcm_ex);
|
|
|
|
|
/* Assume 8000 Hz */
|
|
|
|
|
f.samples = sizeof (slin_adpcm_ex) / 2;
|
|
|
|
|
f.samples = sizeof(slin_adpcm_ex) / 2;
|
|
|
|
|
f.mallocd = 0;
|
|
|
|
|
f.offset = 0;
|
|
|
|
|
f.src = __PRETTY_FUNCTION__;
|
|
|
|
@ -536,12 +514,11 @@ lintoadpcm_sample (void)
|
|
|
|
|
* None.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
adpcm_destroy (struct ast_translator_pvt *pvt)
|
|
|
|
|
static void adpcm_destroy(struct ast_translator_pvt *pvt)
|
|
|
|
|
{
|
|
|
|
|
free (pvt);
|
|
|
|
|
free(pvt);
|
|
|
|
|
localusecnt--;
|
|
|
|
|
ast_update_use_count ();
|
|
|
|
|
ast_update_use_count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -576,8 +553,7 @@ static struct ast_translator lintoadpcm = {
|
|
|
|
|
lintoadpcm_sample
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
parse_config(void)
|
|
|
|
|
static void parse_config(void)
|
|
|
|
|
{
|
|
|
|
|
struct ast_config *cfg;
|
|
|
|
|
struct ast_variable *var;
|
|
|
|
@ -596,37 +572,34 @@ parse_config(void)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
reload(void)
|
|
|
|
|
int reload(void)
|
|
|
|
|
{
|
|
|
|
|
parse_config();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
unload_module (void)
|
|
|
|
|
int unload_module(void)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
ast_mutex_lock (&localuser_lock);
|
|
|
|
|
res = ast_unregister_translator (&lintoadpcm);
|
|
|
|
|
ast_mutex_lock(&localuser_lock);
|
|
|
|
|
res = ast_unregister_translator(&lintoadpcm);
|
|
|
|
|
if (!res)
|
|
|
|
|
res = ast_unregister_translator (&adpcmtolin);
|
|
|
|
|
res = ast_unregister_translator(&adpcmtolin);
|
|
|
|
|
if (localusecnt)
|
|
|
|
|
res = -1;
|
|
|
|
|
ast_mutex_unlock (&localuser_lock);
|
|
|
|
|
ast_mutex_unlock(&localuser_lock);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
load_module (void)
|
|
|
|
|
int load_module(void)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
parse_config();
|
|
|
|
|
res = ast_register_translator (&adpcmtolin);
|
|
|
|
|
res = ast_register_translator(&adpcmtolin);
|
|
|
|
|
if (!res)
|
|
|
|
|
res = ast_register_translator (&lintoadpcm);
|
|
|
|
|
res = ast_register_translator(&lintoadpcm);
|
|
|
|
|
else
|
|
|
|
|
ast_unregister_translator (&adpcmtolin);
|
|
|
|
|
ast_unregister_translator(&adpcmtolin);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -634,22 +607,19 @@ load_module (void)
|
|
|
|
|
* Return a description of this module.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
description (void)
|
|
|
|
|
char *description(void)
|
|
|
|
|
{
|
|
|
|
|
return tdesc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
usecount (void)
|
|
|
|
|
int usecount(void)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
STANDARD_USECOUNT (res);
|
|
|
|
|
STANDARD_USECOUNT(res);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
key ()
|
|
|
|
|
char *key()
|
|
|
|
|
{
|
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
|
}
|
|
|
|
|