forked from Mirrors/freeswitch
[mod_avmd] fix formatting to match coding standards
This commit is contained in:
parent
f2a7891f14
commit
c4bc0bfbb4
|
@ -2,7 +2,7 @@
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*
|
*
|
||||||
* Eric des Courtis <eric.des.courtis@benbria.com>
|
* Eric des Courtis <eric.des.courtis@benbria.com>
|
||||||
* Piotr Gregor <piotrgregor@rsyncme.org>
|
* Piotr Gregor <piotrgregor@rsyncme.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
|
|
||||||
double avmd_amplitude(circ_buffer_t *b, size_t i, double f) {
|
double avmd_amplitude(circ_buffer_t *b, size_t i, double f) {
|
||||||
double result;
|
double result;
|
||||||
result = sqrt(PSI(b, i) / sin(f * f));
|
result = sqrt(PSI(b, i) / sin(f * f));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*
|
*
|
||||||
* Eric des Courtis <eric.des.courtis@benbria.com>
|
* Eric des Courtis <eric.des.courtis@benbria.com>
|
||||||
* Piotr Gregor <piotrgregor@rsyncme.org>
|
* Piotr Gregor <piotrgregor@rsyncme.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,20 +11,20 @@
|
||||||
|
|
||||||
extern size_t next_power_of_2(size_t v)
|
extern size_t next_power_of_2(size_t v)
|
||||||
{
|
{
|
||||||
size_t prev;
|
size_t prev;
|
||||||
size_t tmp = 1;
|
size_t tmp = 1;
|
||||||
|
|
||||||
v++;
|
v++;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
prev = v;
|
prev = v;
|
||||||
v &= ~tmp;
|
v &= ~tmp;
|
||||||
tmp <<= 1;
|
tmp <<= 1;
|
||||||
} while (v != 0);
|
} while (v != 0);
|
||||||
|
|
||||||
prev <<= 1;
|
prev <<= 1;
|
||||||
|
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*
|
*
|
||||||
* Eric des Courtis <eric.des.courtis@benbria.com>
|
* Eric des Courtis <eric.des.courtis@benbria.com>
|
||||||
* Piotr Gregor <piotrgregor@rsyncme.org>
|
* Piotr Gregor <piotrgregor@rsyncme.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,89 +15,89 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef INT16_MIN
|
#ifndef INT16_MIN
|
||||||
#define INT16_MIN (-32767-1)
|
#define INT16_MIN (-32767-1)
|
||||||
#endif
|
#endif
|
||||||
#ifndef INT16_MAX
|
#ifndef INT16_MAX
|
||||||
#define INT16_MAX (32767)
|
#define INT16_MAX (32767)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BUFF_TYPE double
|
#define BUFF_TYPE double
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
size_t pos;
|
size_t pos;
|
||||||
size_t lpos;
|
size_t lpos;
|
||||||
BUFF_TYPE *buf;
|
BUFF_TYPE *buf;
|
||||||
size_t buf_len;
|
size_t buf_len;
|
||||||
size_t mask;
|
size_t mask;
|
||||||
size_t i;
|
size_t i;
|
||||||
size_t backlog;
|
size_t backlog;
|
||||||
} circ_buffer_t;
|
} circ_buffer_t;
|
||||||
|
|
||||||
extern size_t next_power_of_2(size_t v);
|
extern size_t next_power_of_2(size_t v);
|
||||||
|
|
||||||
#define INC_POS(b) \
|
#define INC_POS(b) \
|
||||||
{ \
|
{ \
|
||||||
(b)->pos++; \
|
(b)->pos++; \
|
||||||
(b)->pos &= (b)->mask; \
|
(b)->pos &= (b)->mask; \
|
||||||
(b)->lpos + 1 < 2 * (b)->buf_len ? (b)->lpos++ : (b)->lpos = (b)->buf_len; \
|
(b)->lpos + 1 < 2 * (b)->buf_len ? (b)->lpos++ : (b)->lpos = (b)->buf_len; \
|
||||||
if ((b)->backlog < (b)->buf_len) (b)->backlog++; \
|
if ((b)->backlog < (b)->buf_len) (b)->backlog++; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEC_POS(b) \
|
#define DEC_POS(b) \
|
||||||
{ \
|
{ \
|
||||||
(b)->pos--; \
|
(b)->pos--; \
|
||||||
(b)->pos &= (b)->mask; \
|
(b)->pos &= (b)->mask; \
|
||||||
(b)->lpos--; \
|
(b)->lpos--; \
|
||||||
if (((b)->backlog - 1) < (b)->backlog) (b)->backlog--; \
|
if (((b)->backlog - 1) < (b)->backlog) (b)->backlog--; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GET_SAMPLE(b, i) ((b)->buf[(i) & (b)->mask])
|
#define GET_SAMPLE(b, i) ((b)->buf[(i) & (b)->mask])
|
||||||
#define SET_SAMPLE(b, i, v) ((b)->buf[(i) & (b)->mask] = (v))
|
#define SET_SAMPLE(b, i, v) ((b)->buf[(i) & (b)->mask] = (v))
|
||||||
|
|
||||||
#define INSERT_FRAME(b, f, l) \
|
#define INSERT_FRAME(b, f, l) \
|
||||||
do { \
|
do { \
|
||||||
for ((b)->i = 0; (b)->i < (l); (b)->i++) { \
|
for ((b)->i = 0; (b)->i < (l); (b)->i++) { \
|
||||||
SET_SAMPLE((b), ((b)->i + (b)->pos), (f)[(b)->i]); \
|
SET_SAMPLE((b), ((b)->i + (b)->pos), (f)[(b)->i]); \
|
||||||
} \
|
} \
|
||||||
(b)->pos += (l); \
|
(b)->pos += (l); \
|
||||||
(b)->lpos += (l); \
|
(b)->lpos += (l); \
|
||||||
(b)->pos %= (b)->buf_len; \
|
(b)->pos %= (b)->buf_len; \
|
||||||
(b)->backlog += (l); \
|
(b)->backlog += (l); \
|
||||||
if ((b)->backlog > (b)->buf_len) (b)->backlog = (b)->buf_len; \
|
if ((b)->backlog > (b)->buf_len) (b)->backlog = (b)->buf_len; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
/* ((f)[(b)->i] >= 0) ? \
|
/* ((f)[(b)->i] >= 0) ? \
|
||||||
((BUFF_TYPE)(f)[(b)->i] / (BUFF_TYPE)INT16_MAX): \
|
((BUFF_TYPE)(f)[(b)->i] / (BUFF_TYPE)INT16_MAX): \
|
||||||
(0.0 - ((BUFF_TYPE)(f)[(b)->i] / (BUFF_TYPE)INT16_MIN)) \ */
|
(0.0 - ((BUFF_TYPE)(f)[(b)->i] / (BUFF_TYPE)INT16_MIN)) \ */
|
||||||
#define INSERT_INT16_FRAME(b, f, l) \
|
#define INSERT_INT16_FRAME(b, f, l) \
|
||||||
{ \
|
{ \
|
||||||
for ((b)->i = 0; (b)->i < (l); (b)->i++) { \
|
for ((b)->i = 0; (b)->i < (l); (b)->i++) { \
|
||||||
SET_SAMPLE( \
|
SET_SAMPLE( \
|
||||||
(b), \
|
(b), \
|
||||||
((b)->i + (b)->pos), \
|
((b)->i + (b)->pos), \
|
||||||
( \
|
( \
|
||||||
(BUFF_TYPE)(f)[(b)->i] \
|
(BUFF_TYPE)(f)[(b)->i] \
|
||||||
) \
|
) \
|
||||||
); \
|
); \
|
||||||
} \
|
} \
|
||||||
(b)->pos += (l); \
|
(b)->pos += (l); \
|
||||||
(b)->lpos += (l); \
|
(b)->lpos += (l); \
|
||||||
(b)->pos &= (b)->mask; \
|
(b)->pos &= (b)->mask; \
|
||||||
(b)->backlog += (l); \
|
(b)->backlog += (l); \
|
||||||
if ((b)->backlog > (b)->buf_len) (b)->backlog = (b)->buf_len; \
|
if ((b)->backlog > (b)->buf_len) (b)->backlog = (b)->buf_len; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define CALC_BUFF_LEN(fl, bl) (((fl) >= (bl))? next_power_of_2((fl) << 1): next_power_of_2((bl) << 1))
|
#define CALC_BUFF_LEN(fl, bl) (((fl) >= (bl))? next_power_of_2((fl) << 1): next_power_of_2((bl) << 1))
|
||||||
|
|
||||||
#define INIT_CIRC_BUFFER(bf, bl, fl, s) \
|
#define INIT_CIRC_BUFFER(bf, bl, fl, s) \
|
||||||
{ \
|
{ \
|
||||||
(bf)->buf_len = CALC_BUFF_LEN((fl), (bl)); \
|
(bf)->buf_len = CALC_BUFF_LEN((fl), (bl)); \
|
||||||
(bf)->mask = (bf)->buf_len - 1; \
|
(bf)->mask = (bf)->buf_len - 1; \
|
||||||
(bf)->buf = (BUFF_TYPE *) switch_core_session_alloc(s, (bf)->buf_len * sizeof(BUFF_TYPE)); \
|
(bf)->buf = (BUFF_TYPE *) switch_core_session_alloc(s, (bf)->buf_len * sizeof(BUFF_TYPE)); \
|
||||||
|
@ -105,7 +105,7 @@ extern size_t next_power_of_2(size_t v);
|
||||||
(bf)->lpos = 0; \
|
(bf)->lpos = 0; \
|
||||||
(bf)->backlog = 0; \
|
(bf)->backlog = 0; \
|
||||||
(bf)->i = 0; \
|
(bf)->i = 0; \
|
||||||
}
|
}
|
||||||
|
|
||||||
//#define DESTROY_CIRC_BUFFER(b) free((b)->buf)
|
//#define DESTROY_CIRC_BUFFER(b) free((b)->buf)
|
||||||
#define GET_BACKLOG_POS(b) ((b)->lpos - (b)->backlog)
|
#define GET_BACKLOG_POS(b) ((b)->lpos - (b)->backlog)
|
||||||
|
@ -114,9 +114,9 @@ extern size_t next_power_of_2(size_t v);
|
||||||
#define GET_CURRENT_SAMPLE(b) GET_SAMPLE((b), GET_CURRENT_LPOS((b)))
|
#define GET_CURRENT_SAMPLE(b) GET_SAMPLE((b), GET_CURRENT_LPOS((b)))
|
||||||
|
|
||||||
#define ADD_SAMPLE(b, s) \
|
#define ADD_SAMPLE(b, s) \
|
||||||
do { \
|
do { \
|
||||||
INC_POS((b)); \
|
INC_POS((b)); \
|
||||||
SET_SAMPLE((b), GET_CURRENT_LPOS((b)), (s)); \
|
SET_SAMPLE((b), GET_CURRENT_LPOS((b)), (s)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#endif /* __AVMD_BUFFER_H__ */
|
#endif /* __AVMD_BUFFER_H__ */
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*
|
*
|
||||||
* Eric des Courtis <eric.des.courtis@benbria.com>
|
* Eric des Courtis <eric.des.courtis@benbria.com>
|
||||||
* Piotr Gregor <piotrgregor@rsyncme.org>
|
* Piotr Gregor <piotrgregor@rsyncme.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#define ISNAN(x) (!!(_isnan(x)))
|
#define ISNAN(x) (!!(_isnan(x)))
|
||||||
#define ISINF(x) (isinf(x))
|
#define ISINF(x) (isinf(x))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "avmd_buffer.h"
|
#include "avmd_buffer.h"
|
||||||
|
@ -18,50 +18,50 @@
|
||||||
#include "avmd_options.h"
|
#include "avmd_options.h"
|
||||||
|
|
||||||
#ifdef AVMD_FAST_MATH
|
#ifdef AVMD_FAST_MATH
|
||||||
#include "avmd_fast_acosf.h"
|
#include "avmd_fast_acosf.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
double avmd_desa2(circ_buffer_t *b, size_t i, double *amplitude) {
|
double avmd_desa2(circ_buffer_t *b, size_t i, double *amplitude) {
|
||||||
double d;
|
double d;
|
||||||
double n;
|
double n;
|
||||||
double x0;
|
double x0;
|
||||||
double x1;
|
double x1;
|
||||||
double x2;
|
double x2;
|
||||||
double x3;
|
double x3;
|
||||||
double x4;
|
double x4;
|
||||||
double x2sq;
|
double x2sq;
|
||||||
double result;
|
double result;
|
||||||
double PSI_Xn, PSI_Yn, NEEDED;
|
double PSI_Xn, PSI_Yn, NEEDED;
|
||||||
|
|
||||||
x0 = GET_SAMPLE((b), (i));
|
x0 = GET_SAMPLE((b), (i));
|
||||||
x1 = GET_SAMPLE((b), ((i) + 1));
|
x1 = GET_SAMPLE((b), ((i) + 1));
|
||||||
x2 = GET_SAMPLE((b), ((i) + 2));
|
x2 = GET_SAMPLE((b), ((i) + 2));
|
||||||
x3 = GET_SAMPLE((b), ((i) + 3));
|
x3 = GET_SAMPLE((b), ((i) + 3));
|
||||||
x4 = GET_SAMPLE((b), ((i) + 4));
|
x4 = GET_SAMPLE((b), ((i) + 4));
|
||||||
|
|
||||||
x2sq = x2 * x2;
|
x2sq = x2 * x2;
|
||||||
d = 2.0 * ((x2sq) - (x1 * x3));
|
d = 2.0 * ((x2sq) - (x1 * x3));
|
||||||
if (d == 0.0) {
|
if (d == 0.0) {
|
||||||
*amplitude = 0.0;
|
*amplitude = 0.0;
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
PSI_Xn = ((x2sq) - (x0 * x4));
|
PSI_Xn = ((x2sq) - (x0 * x4));
|
||||||
NEEDED = ((x1 * x1) - (x0 * x2)) + ((x3 * x3) - (x2 * x4));
|
NEEDED = ((x1 * x1) - (x0 * x2)) + ((x3 * x3) - (x2 * x4));
|
||||||
n = ((x2sq) - (x0 * x4)) - NEEDED;
|
n = ((x2sq) - (x0 * x4)) - NEEDED;
|
||||||
PSI_Yn = NEEDED + PSI_Xn;
|
PSI_Yn = NEEDED + PSI_Xn;
|
||||||
|
|
||||||
#ifdef AVMD_FAST_MATH
|
#ifdef AVMD_FAST_MATH
|
||||||
result = 0.5 * (double)fast_acosf((float)n/d);
|
result = 0.5 * (double)fast_acosf((float)n/d);
|
||||||
#else
|
#else
|
||||||
result = 0.5 * acos(n/d);
|
result = 0.5 * acos(n/d);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ISNAN(result)) {
|
if (ISNAN(result)) {
|
||||||
result = 0.0;
|
result = 0.0;
|
||||||
}
|
}
|
||||||
*amplitude = 2.0 * PSI_Xn / sqrt(PSI_Yn);
|
*amplitude = 2.0 * PSI_Xn / sqrt(PSI_Yn);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*
|
*
|
||||||
* Eric des Courtis <eric.des.courtis@benbria.com>
|
* Eric des Courtis <eric.des.courtis@benbria.com>
|
||||||
* Piotr Gregor <piotrgregor@rsyncme.org>
|
* Piotr Gregor <piotrgregor@rsyncme.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,71 +1,71 @@
|
||||||
/*
|
/*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*
|
*
|
||||||
* Piotr Gregor <piotrgregor@rsyncme.org>
|
* Piotr Gregor <piotrgregor@rsyncme.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __AVMD_DESA2_TWEAKED_H__
|
#ifndef __AVMD_DESA2_TWEAKED_H__
|
||||||
#include "avmd_desa2_tweaked.h"
|
#include "avmd_desa2_tweaked.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#define ISNAN(x) (!!(_isnan(x)))
|
#define ISNAN(x) (!!(_isnan(x)))
|
||||||
#define ISINF(x) (isinf(x))
|
#define ISINF(x) (isinf(x))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "avmd_buffer.h"
|
#include "avmd_buffer.h"
|
||||||
#include "avmd_options.h"
|
#include "avmd_options.h"
|
||||||
|
|
||||||
#ifndef AVMD_FAST_MATH
|
#ifndef AVMD_FAST_MATH
|
||||||
#include "avmd_fast_acosf.h"
|
#include "avmd_fast_acosf.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
avmd_desa2_tweaked(circ_buffer_t *b, size_t i, double *amplitude) {
|
avmd_desa2_tweaked(circ_buffer_t *b, size_t i, double *amplitude) {
|
||||||
double n, d;
|
double n, d;
|
||||||
double x0;
|
double x0;
|
||||||
double x1;
|
double x1;
|
||||||
double x2;
|
double x2;
|
||||||
double x3;
|
double x3;
|
||||||
double x4;
|
double x4;
|
||||||
double x2sq;
|
double x2sq;
|
||||||
double result;
|
double result;
|
||||||
double PSI_Xn, PSI_Yn, NEEDED;
|
double PSI_Xn, PSI_Yn, NEEDED;
|
||||||
|
|
||||||
x0 = GET_SAMPLE((b), (i));
|
x0 = GET_SAMPLE((b), (i));
|
||||||
x1 = GET_SAMPLE((b), ((i) + 1));
|
x1 = GET_SAMPLE((b), ((i) + 1));
|
||||||
x2 = GET_SAMPLE((b), ((i) + 2));
|
x2 = GET_SAMPLE((b), ((i) + 2));
|
||||||
x3 = GET_SAMPLE((b), ((i) + 3));
|
x3 = GET_SAMPLE((b), ((i) + 3));
|
||||||
x4 = GET_SAMPLE((b), ((i) + 4));
|
x4 = GET_SAMPLE((b), ((i) + 4));
|
||||||
x2sq = x2 * x2;
|
x2sq = x2 * x2;
|
||||||
d = 2.0 * ((x2sq) - (x1 * x3));
|
d = 2.0 * ((x2sq) - (x1 * x3));
|
||||||
PSI_Xn = ((x2sq) - (x0 * x4));
|
PSI_Xn = ((x2sq) - (x0 * x4));
|
||||||
NEEDED = ((x1 * x1) - (x0 * x2)) + ((x3 * x3) - (x2 * x4));
|
NEEDED = ((x1 * x1) - (x0 * x2)) + ((x3 * x3) - (x2 * x4));
|
||||||
n = ((x2sq) - (x0 * x4)) - NEEDED;
|
n = ((x2sq) - (x0 * x4)) - NEEDED;
|
||||||
PSI_Yn = NEEDED + PSI_Xn;
|
PSI_Yn = NEEDED + PSI_Xn;
|
||||||
|
|
||||||
/* instead of
|
/* instead of
|
||||||
#ifdef FASTMATH
|
#ifdef FASTMATH
|
||||||
result = 0.5 * (double)fast_acosf((float)n/d);
|
result = 0.5 * (double)fast_acosf((float)n/d);
|
||||||
#else
|
#else
|
||||||
result = 0.5 * acos(n/d);
|
result = 0.5 * acos(n/d);
|
||||||
#endif
|
#endif
|
||||||
we do simplified, modified for speed version : */
|
we do simplified, modified for speed version : */
|
||||||
|
|
||||||
result = n/d;
|
result = n/d;
|
||||||
/* if (ISINF(result)) {
|
/* if (ISINF(result)) {
|
||||||
*amplitude = 0.0;
|
*amplitude = 0.0;
|
||||||
if (n < 0.0) {
|
if (n < 0.0) {
|
||||||
return -10.0;
|
return -10.0;
|
||||||
} else {
|
} else {
|
||||||
return 10.0;
|
return 10.0;
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
*amplitude = 2.0 * PSI_Xn / sqrt(PSI_Yn);
|
*amplitude = 2.0 * PSI_Xn / sqrt(PSI_Yn);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*
|
*
|
||||||
* Piotr Gregor <piotrgregor@rsyncme.org>
|
* Piotr Gregor <piotrgregor@rsyncme.org>
|
||||||
*
|
*
|
||||||
* @date 20 Mar 2016
|
* @date 20 Mar 2016
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*
|
*
|
||||||
* Eric des Courtis <eric.des.courtis@benbria.com>
|
* Eric des Courtis <eric.des.courtis@benbria.com>
|
||||||
* Piotr Gregor <piotrgregor@rsyncme.org>
|
* Piotr Gregor <piotrgregor@rsyncme.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "avmd_fast_acosf.h"
|
#include "avmd_fast_acosf.h"
|
||||||
|
@ -39,8 +39,8 @@
|
||||||
|
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
float f;
|
float f;
|
||||||
} float_conv_t;
|
} float_conv_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -58,14 +58,14 @@ typedef union {
|
||||||
#define ACOS_TABLE_CONST_EXPONENT_BITS (3)
|
#define ACOS_TABLE_CONST_EXPONENT_BITS (3)
|
||||||
#define ACOS_TABLE_DISCARDED_BITS (3)
|
#define ACOS_TABLE_DISCARDED_BITS (3)
|
||||||
/* rosolution:
|
/* rosolution:
|
||||||
3: 15 728 640 indices spreading range [0.0, 1.0], table size on disk 134 217 728 bytes (default)
|
3: 15 728 640 indices spreading range [0.0, 1.0], table size on disk 134 217 728 bytes (default)
|
||||||
4: 7 364 320 indices spreading range [0.0, 1.0], table size on disk 67 108 864 bytes
|
4: 7 364 320 indices spreading range [0.0, 1.0], table size on disk 67 108 864 bytes
|
||||||
5: 3 932 160 indices spreading range [0.0, 1.0], table size on disk 33 554 432 bytes
|
5: 3 932 160 indices spreading range [0.0, 1.0], table size on disk 33 554 432 bytes
|
||||||
12: 30 720 indices spreading range [0.0, 1.0], table size on disk 262 144 bytes
|
12: 30 720 indices spreading range [0.0, 1.0], table size on disk 262 144 bytes
|
||||||
16: 1 920 indices spreading range [0.0, 1.0], table size on disk 16 384 bytes
|
16: 1 920 indices spreading range [0.0, 1.0], table size on disk 16 384 bytes
|
||||||
20: 120 indices spreading range [0.0, 1.0], table size on disk 1 024 bytes
|
20: 120 indices spreading range [0.0, 1.0], table size on disk 1 024 bytes
|
||||||
24: 7 indices spreading range [0.0, 1.0], table size on disk 64 bytes
|
24: 7 indices spreading range [0.0, 1.0], table size on disk 64 bytes
|
||||||
26: 1 indices spreading range [0.0, 1.0], table size on disk 16 bytes
|
26: 1 indices spreading range [0.0, 1.0], table size on disk 16 bytes
|
||||||
*/
|
*/
|
||||||
#define ACOS_TABLE_FREE_EXPONENT_BITS (7 - ACOS_TABLE_CONST_EXPONENT_BITS)
|
#define ACOS_TABLE_FREE_EXPONENT_BITS (7 - ACOS_TABLE_CONST_EXPONENT_BITS)
|
||||||
#define ACOS_TABLE_DATA_BITS (31 - ACOS_TABLE_CONST_EXPONENT_BITS - ACOS_TABLE_DISCARDED_BITS)
|
#define ACOS_TABLE_DATA_BITS (31 - ACOS_TABLE_CONST_EXPONENT_BITS - ACOS_TABLE_DISCARDED_BITS)
|
||||||
|
@ -73,7 +73,7 @@ typedef union {
|
||||||
|
|
||||||
#define VARIA_DATA_MASK (0x87FFFFFF & ~((1 << ACOS_TABLE_DISCARDED_BITS) - 1))
|
#define VARIA_DATA_MASK (0x87FFFFFF & ~((1 << ACOS_TABLE_DISCARDED_BITS) - 1))
|
||||||
#define CONST_DATA_MASK (((1 << ACOS_TABLE_CONST_EXPONENT_BITS) - 1) \
|
#define CONST_DATA_MASK (((1 << ACOS_TABLE_CONST_EXPONENT_BITS) - 1) \
|
||||||
<< (ACOS_TABLE_DATA_BITS - 1 + ACOS_TABLE_DISCARDED_BITS))
|
<< (ACOS_TABLE_DATA_BITS - 1 + ACOS_TABLE_DISCARDED_BITS))
|
||||||
|
|
||||||
#define SIGN_UNPACK_MASK (1 << (ACOS_TABLE_DATA_BITS - 1))
|
#define SIGN_UNPACK_MASK (1 << (ACOS_TABLE_DATA_BITS - 1))
|
||||||
#define DATA_UNPACK_MASK ((1 << (ACOS_TABLE_DATA_BITS - 1)) - 1)
|
#define DATA_UNPACK_MASK ((1 << (ACOS_TABLE_DATA_BITS - 1)) - 1)
|
||||||
|
@ -105,107 +105,107 @@ dump_table_summary(void);
|
||||||
|
|
||||||
extern int compute_table(void)
|
extern int compute_table(void)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
float f;
|
float f;
|
||||||
FILE *acos_table_file;
|
FILE *acos_table_file;
|
||||||
size_t res;
|
size_t res;
|
||||||
|
|
||||||
acos_table_file = fopen(ACOS_TABLE_FILENAME, "w");
|
acos_table_file = fopen(ACOS_TABLE_FILENAME, "w");
|
||||||
|
|
||||||
for (i = 0; i < ACOS_TABLE_LENGTH; i++) {
|
for (i = 0; i < ACOS_TABLE_LENGTH; i++) {
|
||||||
f = acosf(float_from_index(i));
|
f = acosf(float_from_index(i));
|
||||||
res = fwrite(&f, sizeof(f), 1, acos_table_file);
|
res = fwrite(&f, sizeof(f), 1, acos_table_file);
|
||||||
if (res != 1) {
|
if (res != 1) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res = fclose(acos_table_file);
|
res = fclose(acos_table_file);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
fclose(acos_table_file);
|
fclose(acos_table_file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int init_fast_acosf(void)
|
extern int init_fast_acosf(void)
|
||||||
{
|
{
|
||||||
int ret, errsv;
|
int ret, errsv;
|
||||||
FILE *acos_fp;
|
FILE *acos_fp;
|
||||||
char err[150];
|
char err[150];
|
||||||
|
|
||||||
if (acos_table == NULL) {
|
if (acos_table == NULL) {
|
||||||
ret = access(ACOS_TABLE_FILENAME, F_OK);
|
ret = access(ACOS_TABLE_FILENAME, F_OK);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
/* file doesn't exist, bad permissions,
|
/* file doesn't exist, bad permissions,
|
||||||
* or some other error occured */
|
* or some other error occured */
|
||||||
errsv = errno;
|
errsv = errno;
|
||||||
strerror_r(errsv, err, 150);
|
strerror_r(errsv, err, 150);
|
||||||
if (errsv != ENOENT) return -1;
|
if (errsv != ENOENT) return -1;
|
||||||
else {
|
else {
|
||||||
switch_log_printf(
|
switch_log_printf(
|
||||||
SWITCH_CHANNEL_LOG,
|
SWITCH_CHANNEL_LOG,
|
||||||
SWITCH_LOG_NOTICE,
|
SWITCH_LOG_NOTICE,
|
||||||
"File [%s] doesn't exist. Creating file...\n", ACOS_TABLE_FILENAME
|
"File [%s] doesn't exist. Creating file...\n", ACOS_TABLE_FILENAME
|
||||||
);
|
);
|
||||||
ret = compute_table();
|
ret = compute_table();
|
||||||
if (ret != 0) return -2;
|
if (ret != 0) return -2;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch_log_printf(
|
switch_log_printf(
|
||||||
SWITCH_CHANNEL_LOG,
|
SWITCH_CHANNEL_LOG,
|
||||||
SWITCH_LOG_INFO,
|
SWITCH_LOG_INFO,
|
||||||
"Using previously created file [%s]\n", ACOS_TABLE_FILENAME
|
"Using previously created file [%s]\n", ACOS_TABLE_FILENAME
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
acos_fp = fopen(ACOS_TABLE_FILENAME, "r");
|
acos_fp = fopen(ACOS_TABLE_FILENAME, "r");
|
||||||
if (acos_fp == NULL) return -3;
|
if (acos_fp == NULL) return -3;
|
||||||
/* can't fail */
|
/* can't fail */
|
||||||
acos_fd = fileno(acos_fp);
|
acos_fd = fileno(acos_fp);
|
||||||
acos_table = (float *) mmap(
|
acos_table = (float *) mmap(
|
||||||
NULL, /* kernel chooses the address at which to create the mapping */
|
NULL, /* kernel chooses the address at which to create the mapping */
|
||||||
ACOS_TABLE_LENGTH * sizeof(float), PROT_READ, MAP_SHARED, acos_fd, 0);
|
ACOS_TABLE_LENGTH * sizeof(float), PROT_READ, MAP_SHARED, acos_fd, 0);
|
||||||
if (acos_table == MAP_FAILED) return -4;
|
if (acos_table == MAP_FAILED) return -4;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int destroy_fast_acosf(void)
|
extern int destroy_fast_acosf(void)
|
||||||
{
|
{
|
||||||
if (munmap(acos_table, ACOS_TABLE_LENGTH) == -1) return -1;
|
if (munmap(acos_table, ACOS_TABLE_LENGTH) == -1) return -1;
|
||||||
if (acos_fd != -1) {
|
if (acos_fd != -1) {
|
||||||
if (close(acos_fd) == -1) return -2;
|
if (close(acos_fd) == -1) return -2;
|
||||||
}
|
}
|
||||||
/* disable use of fast arc cosine file */
|
/* disable use of fast arc cosine file */
|
||||||
acos_table = NULL;
|
acos_table = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern float fast_acosf(float x)
|
extern float fast_acosf(float x)
|
||||||
{
|
{
|
||||||
return acos_table[index_from_float(x)];
|
return acos_table[index_from_float(x)];
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t index_from_float(float f)
|
static uint32_t index_from_float(float f)
|
||||||
{
|
{
|
||||||
float_conv_t d;
|
float_conv_t d;
|
||||||
d.f = f;
|
d.f = f;
|
||||||
return ((d.i & SIGN_MASK) >> (32 - ACOS_TABLE_DATA_BITS)) |
|
return ((d.i & SIGN_MASK) >> (32 - ACOS_TABLE_DATA_BITS)) |
|
||||||
((d.i & DATA_MASK) >> ACOS_TABLE_DISCARDED_BITS);
|
((d.i & DATA_MASK) >> ACOS_TABLE_DISCARDED_BITS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float float_from_index(uint32_t d)
|
static float float_from_index(uint32_t d)
|
||||||
{
|
{
|
||||||
float_conv_t f;
|
float_conv_t f;
|
||||||
f.i = ((d & SIGN_UNPACK_MASK) << (32 - ACOS_TABLE_DATA_BITS)) |
|
f.i = ((d & SIGN_UNPACK_MASK) << (32 - ACOS_TABLE_DATA_BITS)) |
|
||||||
((d & DATA_UNPACK_MASK) << ACOS_TABLE_DISCARDED_BITS) | CONST_DATA_MASK;
|
((d & DATA_UNPACK_MASK) << ACOS_TABLE_DISCARDED_BITS) | CONST_DATA_MASK;
|
||||||
return f.f;
|
return f.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FAST_ACOSF_TESTING
|
#ifdef FAST_ACOSF_TESTING
|
||||||
|
@ -216,111 +216,111 @@ static float float_from_index(uint32_t d)
|
||||||
static void
|
static void
|
||||||
debug_print(void)
|
debug_print(void)
|
||||||
{
|
{
|
||||||
INF(ACOS_TABLE_CONST_EXPONENT);
|
INF(ACOS_TABLE_CONST_EXPONENT);
|
||||||
INF(ACOS_TABLE_CONST_EXPONENT_BITS);
|
INF(ACOS_TABLE_CONST_EXPONENT_BITS);
|
||||||
INF(ACOS_TABLE_FREE_EXPONENT_BITS);
|
INF(ACOS_TABLE_FREE_EXPONENT_BITS);
|
||||||
INF(ACOS_TABLE_DISCARDED_BITS);
|
INF(ACOS_TABLE_DISCARDED_BITS);
|
||||||
INF(ACOS_TABLE_DATA_BITS);
|
INF(ACOS_TABLE_DATA_BITS);
|
||||||
INF(ACOS_TABLE_LENGTH);
|
INF(ACOS_TABLE_LENGTH);
|
||||||
INFX(VARIA_DATA_MASK);
|
INFX(VARIA_DATA_MASK);
|
||||||
INFX(CONST_DATA_MASK);
|
INFX(CONST_DATA_MASK);
|
||||||
INFX(SIGN_UNPACK_MASK);
|
INFX(SIGN_UNPACK_MASK);
|
||||||
INFX(DATA_UNPACK_MASK);
|
INFX(DATA_UNPACK_MASK);
|
||||||
INFX(SIGN_MASK);
|
INFX(SIGN_MASK);
|
||||||
INFX(DATA_MASK);
|
INFX(DATA_MASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dump_table_summary(void)
|
dump_table_summary(void)
|
||||||
{
|
{
|
||||||
uint32_t i, i_0, i_1, di;
|
uint32_t i, i_0, i_1, di;
|
||||||
float f;
|
float f;
|
||||||
|
|
||||||
i = 1;
|
i = 1;
|
||||||
i_0 = index_from_float(0.0);
|
i_0 = index_from_float(0.0);
|
||||||
i_1 = index_from_float(1.0);
|
i_1 = index_from_float(1.0);
|
||||||
di = (i_1 - i_0)/100;
|
di = (i_1 - i_0)/100;
|
||||||
if (di == 0) di = 1;
|
if (di == 0) di = 1;
|
||||||
|
|
||||||
for (; i < ACOS_TABLE_LENGTH; i += di )
|
for (; i < ACOS_TABLE_LENGTH; i += di )
|
||||||
{
|
{
|
||||||
f = float_from_index(i);
|
f = float_from_index(i);
|
||||||
printf("-01i[%.10u] : ffi[%f] fa[%f] acos[%f]\n",
|
printf("-01i[%.10u] : ffi[%f] fa[%f] acos[%f]\n",
|
||||||
i, f, fast_acosf(f), acos(f));
|
i, f, fast_acosf(f), acos(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 1;
|
i = 1;
|
||||||
for (; i < ACOS_TABLE_LENGTH; i = (i << 1))
|
for (; i < ACOS_TABLE_LENGTH; i = (i << 1))
|
||||||
{
|
{
|
||||||
f = fast_acosf(float_from_index(i));
|
f = fast_acosf(float_from_index(i));
|
||||||
printf("--i[%.10u] : fa[%f] ffi[%f]\n",
|
printf("--i[%.10u] : fa[%f] ffi[%f]\n",
|
||||||
i, f, float_from_index(i));
|
i, f, float_from_index(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
f = 0.0;
|
f = 0.0;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 0.1;
|
f = 0.1;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 0.2;
|
f = 0.2;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 0.3;
|
f = 0.3;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 0.4;
|
f = 0.4;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 0.5;
|
f = 0.5;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 0.6;
|
f = 0.6;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 0.7;
|
f = 0.7;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 7.5;
|
f = 7.5;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 0.8;
|
f = 0.8;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 0.9;
|
f = 0.9;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 0.95;
|
f = 0.95;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 0.99;
|
f = 0.99;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 1.0;
|
f = 1.0;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 1.1;
|
f = 1.1;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 1.2;
|
f = 1.2;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = 0.0;
|
f = 0.0;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -0.1;
|
f = -0.1;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -0.2;
|
f = -0.2;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -0.3;
|
f = -0.3;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -0.4;
|
f = -0.4;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -0.5;
|
f = -0.5;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -0.6;
|
f = -0.6;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -0.7;
|
f = -0.7;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -7.5;
|
f = -7.5;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -0.8;
|
f = -0.8;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -0.9;
|
f = -0.9;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -0.95;
|
f = -0.95;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -0.99;
|
f = -0.99;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -1.0;
|
f = -1.0;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -1.1;
|
f = -1.1;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
f = -1.2;
|
f = -1.2;
|
||||||
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
printf("i [%d] from float [%f]\n", index_from_float(f), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* FAST_ACOSF_TESTING */
|
#endif /* FAST_ACOSF_TESTING */
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*
|
*
|
||||||
* Eric des Courtis <eric.des.courtis@benbria.com>
|
* Eric des Courtis <eric.des.courtis@benbria.com>
|
||||||
* Piotr Gregor <piotrgregor@rsyncme.org>
|
* Piotr Gregor <piotrgregor@rsyncme.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*
|
*
|
||||||
* Piotr Gregor <piotrgregor@rsyncme.org>
|
* Piotr Gregor <piotrgregor@rsyncme.org>
|
||||||
*
|
*
|
||||||
* @date 23 Mar 2016
|
* @date 23 Mar 2016
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define AVMD_MAX(a, b) (a) > (b) ? (a) : (b)
|
#define AVMD_MAX(a, b) (a) > (b) ? (a) : (b)
|
||||||
#define AVMD_MEDIAN_FILTER(a, b, c) (a) > (b) ? ((a) > (c) ? \
|
#define AVMD_MEDIAN_FILTER(a, b, c) (a) > (b) ? ((a) > (c) ? \
|
||||||
AVMD_MAX((b), (c)) : a) : ((b) > (c) ? AVMD_MAX((a), (c)) : (b))
|
AVMD_MAX((b), (c)) : a) : ((b) > (c) ? AVMD_MAX((a), (c)) : (b))
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,30 +8,30 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#ifndef __AVMD_GOERTZEL_H__
|
#ifndef __AVMD_GOERTZEL_H__
|
||||||
#include "avmd_goertzel.h"
|
#include "avmd_goertzel.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __AVMD_BUFFER_H__
|
#ifndef __AVMD_BUFFER_H__
|
||||||
#include "avmd_buffer.h"
|
#include "avmd_buffer.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
extern double avmd_goertzel(circ_buffer_t *b, size_t pos, double f, size_t num)
|
extern double avmd_goertzel(circ_buffer_t *b, size_t pos, double f, size_t num)
|
||||||
{
|
{
|
||||||
double s = 0.0;
|
double s = 0.0;
|
||||||
double p = 0.0;
|
double p = 0.0;
|
||||||
double p2 = 0.0;
|
double p2 = 0.0;
|
||||||
double coeff;
|
double coeff;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
coeff = 2.0 * cos(2.0 * M_PI * f);
|
coeff = 2.0 * cos(2.0 * M_PI * f);
|
||||||
|
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
/* TODO: optimize to avoid GET_SAMPLE when possible */
|
/* TODO: optimize to avoid GET_SAMPLE when possible */
|
||||||
s = GET_SAMPLE(b, i + pos) + (coeff * p) - p2;
|
s = GET_SAMPLE(b, i + pos) + (coeff * p) - p2;
|
||||||
p2 = p;
|
p2 = p;
|
||||||
p = s;
|
p = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (p2 * p2) + (p * p) - (coeff * p2 * p);
|
return (p2 * p2) + (p * p) - (coeff * p2 * p);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,14 @@
|
||||||
|
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "avmd_buffer.h"
|
#include "avmd_buffer.h"
|
||||||
|
|
||||||
#if !defined(M_PI)
|
#if !defined(M_PI)
|
||||||
/* C99 systems may not define M_PI */
|
/* C99 systems may not define M_PI */
|
||||||
#define M_PI 3.14159265358979323846264338327
|
#define M_PI 3.14159265358979323846264338327
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*
|
*
|
||||||
* Piotr Gregor <piotrgregor@rsyncme.org>
|
* Piotr Gregor <piotrgregor@rsyncme.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*
|
*
|
||||||
* Eric des Courtis <eric.des.courtis@benbria.com>
|
* Eric des Courtis <eric.des.courtis@benbria.com>
|
||||||
* Piotr Gregor <piotrgregor@rsyncme.org>
|
* Piotr Gregor <piotrgregor@rsyncme.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*
|
*
|
||||||
* Eric des Courtis <eric.des.courtis@benbria.com>
|
* Eric des Courtis <eric.des.courtis@benbria.com>
|
||||||
* Piotr Gregor <piotrgregor@rsyncme.org>
|
* Piotr Gregor <piotrgregor@rsyncme.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,22 +22,22 @@
|
||||||
#include "avmd_buffer.h"
|
#include "avmd_buffer.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
size_t len;
|
size_t len;
|
||||||
BUFF_TYPE *data;
|
BUFF_TYPE *data;
|
||||||
BUFF_TYPE sma;
|
BUFF_TYPE sma;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
size_t lpos;
|
size_t lpos;
|
||||||
} sma_buffer_t;
|
} sma_buffer_t;
|
||||||
|
|
||||||
#define INIT_SMA_BUFFER(b, l, s) \
|
#define INIT_SMA_BUFFER(b, l, s) \
|
||||||
{ \
|
{ \
|
||||||
(void)memset((b), 0, sizeof(sma_buffer_t)); \
|
(void)memset((b), 0, sizeof(sma_buffer_t)); \
|
||||||
(b)->len = (l); \
|
(b)->len = (l); \
|
||||||
(b)->data = (BUFF_TYPE *)switch_core_session_alloc((s), sizeof(BUFF_TYPE) * (l)); \
|
(b)->data = (BUFF_TYPE *)switch_core_session_alloc((s), sizeof(BUFF_TYPE) * (l)); \
|
||||||
(b)->sma = 0.0; \
|
(b)->sma = 0.0; \
|
||||||
(b)->pos = 0; \
|
(b)->pos = 0; \
|
||||||
(b)->lpos = 0; \
|
(b)->lpos = 0; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GET_SMA_SAMPLE(b, p) ((b)->data[(p) % (b)->len])
|
#define GET_SMA_SAMPLE(b, p) ((b)->data[(p) % (b)->len])
|
||||||
#define SET_SMA_SAMPLE(b, p, v) ((b)->data[(p) % (b)->len] = (v))
|
#define SET_SMA_SAMPLE(b, p, v) ((b)->data[(p) % (b)->len] = (v))
|
||||||
|
@ -45,33 +45,33 @@ typedef struct {
|
||||||
#define GET_CURRENT_SMA_LPOS(b) ((b)->lpos)
|
#define GET_CURRENT_SMA_LPOS(b) ((b)->lpos)
|
||||||
|
|
||||||
#define INC_SMA_POS(b) \
|
#define INC_SMA_POS(b) \
|
||||||
{ \
|
{ \
|
||||||
((b)->lpos + 1 < 2 * (b)->len) ? ((b)->lpos++) : ((b)->lpos = (b)->len); \
|
((b)->lpos + 1 < 2 * (b)->len) ? ((b)->lpos++) : ((b)->lpos = (b)->len); \
|
||||||
(b)->pos = (b)->lpos % (b)->len; \
|
(b)->pos = (b)->lpos % (b)->len; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define APPEND_SMA_VAL(b, v) \
|
#define APPEND_SMA_VAL(b, v) \
|
||||||
{ \
|
{ \
|
||||||
(b)->sma -= ((b)->data[(b)->pos] / (BUFF_TYPE)(b)->len); \
|
(b)->sma -= ((b)->data[(b)->pos] / (BUFF_TYPE)(b)->len); \
|
||||||
(b)->data[(b)->pos] = (v); \
|
(b)->data[(b)->pos] = (v); \
|
||||||
(((b)->lpos) >= ((b)->len)) ? ((b)->sma += ((b)->data[(b)->pos] / (BUFF_TYPE)(b)->len)) : \
|
(((b)->lpos) >= ((b)->len)) ? ((b)->sma += ((b)->data[(b)->pos] / (BUFF_TYPE)(b)->len)) : \
|
||||||
((b)->sma = ((((b)->sma)*((b)->pos)) + ((b)->data[(b)->pos])) / ((BUFF_TYPE)(((b)->pos) + 1))) ; \
|
((b)->sma = ((((b)->sma)*((b)->pos)) + ((b)->data[(b)->pos])) / ((BUFF_TYPE)(((b)->pos) + 1))) ; \
|
||||||
INC_SMA_POS(b); \
|
INC_SMA_POS(b); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RESET_SMA_BUFFER(b) \
|
#define RESET_SMA_BUFFER(b) \
|
||||||
{ \
|
{ \
|
||||||
(b)->sma = 0.0; \
|
(b)->sma = 0.0; \
|
||||||
(void)memset((b)->data, 0, sizeof(BUFF_TYPE) * (b)->len); \
|
(void)memset((b)->data, 0, sizeof(BUFF_TYPE) * (b)->len); \
|
||||||
(b)->pos = 0; \
|
(b)->pos = 0; \
|
||||||
(b)->lpos = 0; \
|
(b)->lpos = 0; \
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#define DESTROY_SMA_BUFFER(b) \
|
#define DESTROY_SMA_BUFFER(b) \
|
||||||
do{ \
|
do{ \
|
||||||
free((b)->data); \
|
free((b)->data); \
|
||||||
}while(0);
|
}while(0);
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -83,19 +83,19 @@ typedef struct {
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
sma_buffer_t b;
|
sma_buffer_t b;
|
||||||
|
|
||||||
INIT_SMA_BUFFER(&b, 100);
|
INIT_SMA_BUFFER(&b, 100);
|
||||||
|
|
||||||
for(i = 0; i < 20; i++){
|
for(i = 0; i < 20; i++){
|
||||||
APPEND_SMA_VAL(&b, 100.0);
|
APPEND_SMA_VAL(&b, 100.0);
|
||||||
printf("SMA = %lf\n", b.sma);
|
printf("SMA = %lf\n", b.sma);
|
||||||
}
|
}
|
||||||
|
|
||||||
DESTROY_SMA_BUFFER(&b);
|
DESTROY_SMA_BUFFER(&b);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,74 +1,74 @@
|
||||||
<configuration name="avmd.conf" description="AVMD config">
|
<configuration name="avmd.conf" description="AVMD config">
|
||||||
<settings>
|
<settings>
|
||||||
|
|
||||||
<!-- Edit these settings to change default behaviour
|
<!-- Edit these settings to change default behaviour
|
||||||
of each avmd session. Settings can be overwritten
|
of each avmd session. Settings can be overwritten
|
||||||
by values passed dynamically per each session -->
|
by values passed dynamically per each session -->
|
||||||
|
|
||||||
|
|
||||||
<!-- Global settings -->
|
<!-- Global settings -->
|
||||||
|
|
||||||
<!-- define/undefine this to enable/disable logging of avmd
|
<!-- define/undefine this to enable/disable logging of avmd
|
||||||
intermediate computations to log -->
|
intermediate computations to log -->
|
||||||
<param name="debug" value="0"/>
|
<param name="debug" value="0"/>
|
||||||
|
|
||||||
<!-- define/undef this to enable/disable verbose logging (and reporting to the console)
|
<!-- define/undef this to enable/disable verbose logging (and reporting to the console)
|
||||||
of detection status and other diagnostics like parameters avmd session has been started with,
|
of detection status and other diagnostics like parameters avmd session has been started with,
|
||||||
change of configuration parameters, beep detection status after session ended
|
change of configuration parameters, beep detection status after session ended
|
||||||
(stop event is fired independently of this setting and beep status included there) -->
|
(stop event is fired independently of this setting and beep status included there) -->
|
||||||
<param name="report_status" value="1"/>
|
<param name="report_status" value="1"/>
|
||||||
|
|
||||||
<!-- define/undefine this to enable/disable faster computation
|
<!-- define/undefine this to enable/disable faster computation
|
||||||
of arcus cosine - table will be created mapping floats
|
of arcus cosine - table will be created mapping floats
|
||||||
to integers and returning arc cos values given these integer
|
to integers and returning arc cos values given these integer
|
||||||
indices into table -->
|
indices into table -->
|
||||||
<param name="fast_math" value="0"/>
|
<param name="fast_math" value="0"/>
|
||||||
<!-- Global settings end -->
|
<!-- Global settings end -->
|
||||||
|
|
||||||
|
|
||||||
<!-- Per call (session) settings. These settings can be overwritten
|
<!-- Per call (session) settings. These settings can be overwritten
|
||||||
with custom/different values per each avmd session -->
|
with custom/different values per each avmd session -->
|
||||||
|
|
||||||
<!-- define/undefine this to classify avmd beep detection as valid
|
<!-- define/undefine this to classify avmd beep detection as valid
|
||||||
only when there is required number of consecutive elements
|
only when there is required number of consecutive elements
|
||||||
in the SMA buffer without reset -->
|
in the SMA buffer without reset -->
|
||||||
<param name="require_continuous_streak" value="1"/>
|
<param name="require_continuous_streak" value="1"/>
|
||||||
|
|
||||||
<!-- required number of consecutive elements in the SMA buffer
|
<!-- required number of consecutive elements in the SMA buffer
|
||||||
without reset. This parameter helps to avoid false beeps, bigger this value is
|
without reset. This parameter helps to avoid false beeps, bigger this value is
|
||||||
smaller the probability of getting false detection -->
|
smaller the probability of getting false detection -->
|
||||||
<param name="sample_n_continuous_streak" value="3"/>
|
<param name="sample_n_continuous_streak" value="3"/>
|
||||||
|
|
||||||
<!-- define number of samples to skip starting from the beginning
|
<!-- define number of samples to skip starting from the beginning
|
||||||
of the frame and/or after reset has happened. This serves the purpose of skipping first few
|
of the frame and/or after reset has happened. This serves the purpose of skipping first few
|
||||||
estimations on each frame, as these estimations may be inaccurate. This parameter also helps
|
estimations on each frame, as these estimations may be inaccurate. This parameter also helps
|
||||||
to give more robust detections when it's value is increased (up to scertain limit of about 60). -->
|
to give more robust detections when it's value is increased (up to scertain limit of about 60). -->
|
||||||
<param name="sample_n_to_skip" value="0"/>
|
<param name="sample_n_to_skip" value="0"/>
|
||||||
|
|
||||||
<param name="require_continuous_streak_amp" value="1"/>
|
<param name="require_continuous_streak_amp" value="1"/>
|
||||||
<param name="sample_n_continuous_streak_amp" value="3"/>
|
<param name="sample_n_continuous_streak_amp" value="3"/>
|
||||||
|
|
||||||
<!-- define/undefine this to enable/disable simplified estimation
|
<!-- define/undefine this to enable/disable simplified estimation
|
||||||
of frequency based on approximation of sin(x) with (x)
|
of frequency based on approximation of sin(x) with (x)
|
||||||
in the range x=[0,PI/2] -->
|
in the range x=[0,PI/2] -->
|
||||||
<param name="simplified_estimation" value="1"/>
|
<param name="simplified_estimation" value="1"/>
|
||||||
|
|
||||||
<!-- define/undefine to enable/disable avmd on internal channel -->
|
<!-- define/undefine to enable/disable avmd on internal channel -->
|
||||||
<param name="inbound_channel" value="0"/>
|
<param name="inbound_channel" value="0"/>
|
||||||
|
|
||||||
<!-- define/undefine to enable/disable avmd on external channel -->
|
<!-- define/undefine to enable/disable avmd on external channel -->
|
||||||
<param name="outbound_channel" value="1"/>
|
<param name="outbound_channel" value="1"/>
|
||||||
|
|
||||||
<!-- determines the mode of detection, default is both amplitude and frequency -->
|
<!-- determines the mode of detection, default is both amplitude and frequency -->
|
||||||
<param name="detection_mode" value="2"/>
|
<param name="detection_mode" value="2"/>
|
||||||
|
|
||||||
<!-- number of detection threads running per each avmd session -->
|
<!-- number of detection threads running per each avmd session -->
|
||||||
<param name="detectors_n" value="36"/>
|
<param name="detectors_n" value="36"/>
|
||||||
|
|
||||||
<!-- number of lagged detection threads running per each avmd session -->
|
<!-- number of lagged detection threads running per each avmd session -->
|
||||||
<param name="detectors_lagged_n" value="1"/>
|
<param name="detectors_lagged_n" value="1"/>
|
||||||
|
|
||||||
<!-- Per call settings end -->
|
<!-- Per call settings end -->
|
||||||
</settings>
|
</settings>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -19,18 +19,18 @@ my $pass = "ClueCon";
|
||||||
my $format = "plain";
|
my $format = "plain";
|
||||||
|
|
||||||
if ($#ARGV + 1 eq 1) {
|
if ($#ARGV + 1 eq 1) {
|
||||||
$format = $ARGV[0];
|
$format = $ARGV[0];
|
||||||
print "Using format: [" .$format ."]\n";
|
print "Using format: [" .$format ."]\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $con = new ESL::ESLconnection($host, $port, $pass);
|
my $con = new ESL::ESLconnection($host, $port, $pass);
|
||||||
if (!$con) {
|
if (!$con) {
|
||||||
die "Unable to establish connection to $host:$port\n";
|
die "Unable to establish connection to $host:$port\n";
|
||||||
}
|
}
|
||||||
if ($con->connected()) {
|
if ($con->connected()) {
|
||||||
print "OK, Connected.\n";
|
print "OK, Connected.\n";
|
||||||
} else {
|
} else {
|
||||||
die "Conenction failure.\n";
|
die "Conenction failure.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Subscribing to avmd events...\n";
|
print "Subscribing to avmd events...\n";
|
||||||
|
@ -40,17 +40,17 @@ $con->events("plain", "CUSTOM avmd::beep");
|
||||||
|
|
||||||
print "Waiting for the events...\n";
|
print "Waiting for the events...\n";
|
||||||
while($con->connected()) {
|
while($con->connected()) {
|
||||||
my $e = $con->recvEvent();
|
my $e = $con->recvEvent();
|
||||||
my $avmd_event_type = "";
|
my $avmd_event_type = "";
|
||||||
$avmd_event_type = $e->getHeader("Event-Subclass");
|
$avmd_event_type = $e->getHeader("Event-Subclass");
|
||||||
if ($avmd_event_type eq 'avmd::start') { # mark nicely the start of new session and event streak - most likely there will be other events from this session coming after this one
|
if ($avmd_event_type eq 'avmd::start') { # mark nicely the start of new session and event streak - most likely there will be other events from this session coming after this one
|
||||||
print "\n--------------------\n\n";
|
print "\n--------------------\n\n";
|
||||||
}
|
}
|
||||||
if ($e) {
|
if ($e) {
|
||||||
my $body = $e->serialize($format);
|
my $body = $e->serialize($format);
|
||||||
print $body;
|
print $body;
|
||||||
print "\n\n";
|
print "\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Disconnected.\n\n";
|
print "Disconnected.\n\n";
|
||||||
|
|
|
@ -25,21 +25,21 @@ my $callerid;
|
||||||
|
|
||||||
|
|
||||||
if ($#ARGV + 1 eq 2) {
|
if ($#ARGV + 1 eq 2) {
|
||||||
$dest = $ARGV[0];
|
$dest = $ARGV[0];
|
||||||
$callerid = $ARGV[1];
|
$callerid = $ARGV[1];
|
||||||
print "Dialing [" .$dest ."] as " .$callerid ."]\n";
|
print "Dialing [" .$dest ."] as " .$callerid ."]\n";
|
||||||
} else {
|
} else {
|
||||||
die "Please specify destination number and caller id\n";
|
die "Please specify destination number and caller id\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $con = new ESL::ESLconnection($host, $port, $pass);
|
my $con = new ESL::ESLconnection($host, $port, $pass);
|
||||||
if (!$con) {
|
if (!$con) {
|
||||||
die "Unable to establish connection to $host:$port\n";
|
die "Unable to establish connection to $host:$port\n";
|
||||||
}
|
}
|
||||||
if ($con->connected()) {
|
if ($con->connected()) {
|
||||||
print "OK, Connected.\n";
|
print "OK, Connected.\n";
|
||||||
} else {
|
} else {
|
||||||
die "Connection failure.\n";
|
die "Connection failure.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Subscribing to avmd events...\n";
|
print "Subscribing to avmd events...\n";
|
||||||
|
@ -48,42 +48,42 @@ $con->events("plain", "CUSTOM avmd::stop");
|
||||||
$con->events("plain", "CUSTOM avmd::beep");
|
$con->events("plain", "CUSTOM avmd::beep");
|
||||||
|
|
||||||
while($con->connected()) {
|
while($con->connected()) {
|
||||||
test_once($dest, $callerid);
|
test_once($dest, $callerid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Disconnected.\n\n";
|
print "Disconnected.\n\n";
|
||||||
|
|
||||||
sub test_once {
|
sub test_once {
|
||||||
my ($dest, $callerid) = @_;
|
my ($dest, $callerid) = @_;
|
||||||
my $originate_string =
|
my $originate_string =
|
||||||
'originate ' .
|
'originate ' .
|
||||||
'{ignore_early_media=true,' .
|
'{ignore_early_media=true,' .
|
||||||
'origination_uuid=%s,' .
|
'origination_uuid=%s,' .
|
||||||
'originate_timeout=60,' .
|
'originate_timeout=60,' .
|
||||||
'origination_caller_id_number=' . $callerid . ',' .
|
'origination_caller_id_number=' . $callerid . ',' .
|
||||||
'origination_caller_id_name=' . $callerid . '}';
|
'origination_caller_id_name=' . $callerid . '}';
|
||||||
|
|
||||||
if(defined($endpoint)) {
|
if(defined($endpoint)) {
|
||||||
$originate_string .= $endpoint;
|
$originate_string .= $endpoint;
|
||||||
} else {
|
} else {
|
||||||
$originate_string .= 'loopback/' . $dest . '/' . $context;
|
$originate_string .= 'loopback/' . $dest . '/' . $context;
|
||||||
}
|
}
|
||||||
$originate_string .= ' ' . '&playback(' . $playback . ')';
|
$originate_string .= ' ' . '&playback(' . $playback . ')';
|
||||||
|
|
||||||
my $uuid = $con->api('create_uuid')->getBody();
|
my $uuid = $con->api('create_uuid')->getBody();
|
||||||
my ($time_epoch, $time_hires) = Time::HiRes::gettimeofday();
|
my ($time_epoch, $time_hires) = Time::HiRes::gettimeofday();
|
||||||
printf("Calling with uuid [%s] [%s]... [%s]\n", $uuid, POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($time_epoch)), $originate_string);
|
printf("Calling with uuid [%s] [%s]... [%s]\n", $uuid, POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($time_epoch)), $originate_string);
|
||||||
|
|
||||||
$con->bgapi(sprintf($originate_string, $uuid));
|
$con->bgapi(sprintf($originate_string, $uuid));
|
||||||
|
|
||||||
print "Waiting for the events...\n\n";
|
print "Waiting for the events...\n\n";
|
||||||
while($con->connected()) {
|
while($con->connected()) {
|
||||||
my $e = $con->recvEvent();
|
my $e = $con->recvEvent();
|
||||||
if ($e) {
|
if ($e) {
|
||||||
my $body = $e->serialize('plain');
|
my $body = $e->serialize('plain');
|
||||||
print $body;
|
print $body;
|
||||||
print "\n\n";
|
print "\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,55 +32,55 @@ my $idx = 0;
|
||||||
|
|
||||||
|
|
||||||
if ($#ARGV + 1 eq 3) {
|
if ($#ARGV + 1 eq 3) {
|
||||||
$dest = $ARGV[0];
|
$dest = $ARGV[0];
|
||||||
$callerid = $ARGV[1];
|
$callerid = $ARGV[1];
|
||||||
$thread_n = $ARGV[2];
|
$thread_n = $ARGV[2];
|
||||||
print "Dialing [" .$thread_n ."] calls simultaneously to[" .$dest ."] as [" .$callerid ."]\n";
|
print "Dialing [" .$thread_n ."] calls simultaneously to[" .$dest ."] as [" .$callerid ."]\n";
|
||||||
} else {
|
} else {
|
||||||
die "Please specify destination number, caller id and number of calls to make\n\nExample:\n./avmd_originate_multiple.pl EXTENSION CALLER NUMBER_OF_CALLS";
|
die "Please specify destination number, caller id and number of calls to make\n\nExample:\n./avmd_originate_multiple.pl EXTENSION CALLER NUMBER_OF_CALLS";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $con = new ESL::ESLconnection($host, $port, $pass);
|
my $con = new ESL::ESLconnection($host, $port, $pass);
|
||||||
if (!$con) {
|
if (!$con) {
|
||||||
die "Unable to establish connection to $host:$port\n";
|
die "Unable to establish connection to $host:$port\n";
|
||||||
}
|
}
|
||||||
if ($con->connected()) {
|
if ($con->connected()) {
|
||||||
print "OK, Connected.\n";
|
print "OK, Connected.\n";
|
||||||
} else {
|
} else {
|
||||||
die "Connection failure.\n";
|
die "Connection failure.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
while($con->connected() && ($idx < $thread_n)) {
|
while($con->connected() && ($idx < $thread_n)) {
|
||||||
call_once($dest, $callerid, $idx);
|
call_once($dest, $callerid, $idx);
|
||||||
$idx++;
|
$idx++;
|
||||||
Time::HiRes::sleep(0.11); # avoid switch_core_session.c:2265 Throttle Error! 33, switch_time.c:1227 Over Session Rate of 30!
|
Time::HiRes::sleep(0.11); # avoid switch_core_session.c:2265 Throttle Error! 33, switch_time.c:1227 Over Session Rate of 30!
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Disconnected.\n\n";
|
print "Disconnected.\n\n";
|
||||||
|
|
||||||
sub call_once {
|
sub call_once {
|
||||||
my ($dest, $callerid, $idx) = @_;
|
my ($dest, $callerid, $idx) = @_;
|
||||||
my $originate_string =
|
my $originate_string =
|
||||||
'originate ' .
|
'originate ' .
|
||||||
'{ignore_early_media=true,' .
|
'{ignore_early_media=true,' .
|
||||||
'originator_codec=PCMA,' .
|
'originator_codec=PCMA,' .
|
||||||
'origination_uuid=%s,' .
|
'origination_uuid=%s,' .
|
||||||
'originate_timeout=60,' .
|
'originate_timeout=60,' .
|
||||||
'origination_caller_id_number=' . $callerid . ',' .
|
'origination_caller_id_number=' . $callerid . ',' .
|
||||||
'origination_caller_id_name=' . $callerid . '}';
|
'origination_caller_id_name=' . $callerid . '}';
|
||||||
|
|
||||||
if(defined($endpoint)) {
|
if(defined($endpoint)) {
|
||||||
$originate_string = '';
|
$originate_string = '';
|
||||||
$originate_string .= $endpoint;
|
$originate_string .= $endpoint;
|
||||||
} else {
|
} else {
|
||||||
$originate_string .= 'loopback/' . $dest . '/' . $context;
|
$originate_string .= 'loopback/' . $dest . '/' . $context;
|
||||||
$originate_string .= ' ' . '&playback(' . $playback . ')';
|
$originate_string .= ' ' . '&playback(' . $playback . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
my $uuid = $con->api('create_uuid')->getBody();
|
my $uuid = $con->api('create_uuid')->getBody();
|
||||||
my ($time_epoch, $time_hires) = Time::HiRes::gettimeofday();
|
my ($time_epoch, $time_hires) = Time::HiRes::gettimeofday();
|
||||||
printf("[%s]\tCalling with uuid [%s] [%s]... [%s]\n", $idx + 1, $uuid, POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($time_epoch)), $originate_string);
|
printf("[%s]\tCalling with uuid [%s] [%s]... [%s]\n", $idx + 1, $uuid, POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($time_epoch)), $originate_string);
|
||||||
|
|
||||||
$con->bgapi(sprintf($originate_string, $uuid));
|
$con->bgapi(sprintf($originate_string, $uuid));
|
||||||
$con->api('uuid_setvar ' . $uuid .' execute_on_answer avmd_start');
|
$con->api('uuid_setvar ' . $uuid .' execute_on_answer avmd_start');
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,51 +27,51 @@ my $idx = 0;
|
||||||
|
|
||||||
|
|
||||||
if ($#ARGV + 1 eq 3) {
|
if ($#ARGV + 1 eq 3) {
|
||||||
$dest = $ARGV[0];
|
$dest = $ARGV[0];
|
||||||
$callerid = $ARGV[1];
|
$callerid = $ARGV[1];
|
||||||
$thread_n = $ARGV[2];
|
$thread_n = $ARGV[2];
|
||||||
print "Dialing [" .$thread_n ."] calls simultaneously to [loopback][" .$dest ."] as [" .$callerid ."]\n";
|
print "Dialing [" .$thread_n ."] calls simultaneously to [loopback][" .$dest ."] as [" .$callerid ."]\n";
|
||||||
} else {
|
} else {
|
||||||
die "Please specify destination number, caller id and number of calls to make\n";
|
die "Please specify destination number, caller id and number of calls to make\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $con = new ESL::ESLconnection($host, $port, $pass);
|
my $con = new ESL::ESLconnection($host, $port, $pass);
|
||||||
if (!$con) {
|
if (!$con) {
|
||||||
die "Unable to establish connection to $host:$port\n";
|
die "Unable to establish connection to $host:$port\n";
|
||||||
}
|
}
|
||||||
if ($con->connected()) {
|
if ($con->connected()) {
|
||||||
print "OK, Connected.\n";
|
print "OK, Connected.\n";
|
||||||
} else {
|
} else {
|
||||||
die "Connection failure.\n";
|
die "Connection failure.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
while($con->connected() && ($idx < $thread_n)) {
|
while($con->connected() && ($idx < $thread_n)) {
|
||||||
call_once($dest, $callerid, $idx);
|
call_once($dest, $callerid, $idx);
|
||||||
$idx++;
|
$idx++;
|
||||||
Time::HiRes::sleep(0.11); # avoid switch_core_session.c:2265 Throttle Error! 33, switch_time.c:1227 Over Session Rate of 30!
|
Time::HiRes::sleep(0.11); # avoid switch_core_session.c:2265 Throttle Error! 33, switch_time.c:1227 Over Session Rate of 30!
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Disconnected.\n\n";
|
print "Disconnected.\n\n";
|
||||||
|
|
||||||
sub call_once {
|
sub call_once {
|
||||||
my ($dest, $callerid, $idx) = @_;
|
my ($dest, $callerid, $idx) = @_;
|
||||||
my $uuid =
|
my $uuid =
|
||||||
my $originate_string =
|
my $originate_string =
|
||||||
'originate ' .
|
'originate ' .
|
||||||
'{ignore_early_media=true,' .
|
'{ignore_early_media=true,' .
|
||||||
'originator_codec=PCMA,' .
|
'originator_codec=PCMA,' .
|
||||||
'origination_uuid=%s,' .
|
'origination_uuid=%s,' .
|
||||||
'originate_timeout=60,' .
|
'originate_timeout=60,' .
|
||||||
'origination_caller_id_number=' . $callerid . ',' .
|
'origination_caller_id_number=' . $callerid . ',' .
|
||||||
'origination_caller_id_name=' . $callerid . '}';
|
'origination_caller_id_name=' . $callerid . '}';
|
||||||
|
|
||||||
$originate_string .= 'loopback/' . $dest . '/' . $context;
|
$originate_string .= 'loopback/' . $dest . '/' . $context;
|
||||||
$originate_string .= ' ' . '&playback(' . $playback . ')';
|
$originate_string .= ' ' . '&playback(' . $playback . ')';
|
||||||
|
|
||||||
my $uuid = $con->api('create_uuid')->getBody();
|
my $uuid = $con->api('create_uuid')->getBody();
|
||||||
my ($time_epoch, $time_hires) = Time::HiRes::gettimeofday();
|
my ($time_epoch, $time_hires) = Time::HiRes::gettimeofday();
|
||||||
printf("[%s]\tCalling with uuid [%s] [%s]... [%s]\n", $idx + 1, $uuid, POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($time_epoch)), $originate_string);
|
printf("[%s]\tCalling with uuid [%s] [%s]... [%s]\n", $idx + 1, $uuid, POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($time_epoch)), $originate_string);
|
||||||
|
|
||||||
$con->bgapi(sprintf($originate_string, $uuid));
|
$con->bgapi(sprintf($originate_string, $uuid));
|
||||||
$con->api('uuid_setvar ' . $uuid .' execute_on_answer avmd_start');
|
$con->api('uuid_setvar ' . $uuid .' execute_on_answer avmd_start');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
||||||
|
|
||||||
|
|
||||||
#brief Test module avmd by calling voicemails from avmd test suite
|
#brief Test module avmd by calling voicemails from avmd test suite
|
||||||
# and print detection results to the console.
|
# and print detection results to the console.
|
||||||
#author Piotr Gregor <piotr@dataandsignal.com>
|
#author Piotr Gregor <piotr@dataandsignal.com>
|
||||||
#details If you are testing serving voicemails from dialplan then avmd
|
#details If you are testing serving voicemails from dialplan then avmd
|
||||||
# must be set to inbound mode, either globally (by avmd set inbound
|
# must be set to inbound mode, either globally (by avmd set inbound
|
||||||
# in fs_cli) or in dialplan settings (<action application="avmd_start"
|
# in fs_cli) or in dialplan settings (<action application="avmd_start"
|
||||||
# data="inbound_channel=1,outbound_channel=0") or dynamically per call.
|
# data="inbound_channel=1,outbound_channel=0") or dynamically per call.
|
||||||
#date 15 Sept 2016 03:00 PM
|
#date 15 Sept 2016 03:00 PM
|
||||||
|
|
||||||
|
|
||||||
$|++; # turn on autoflush
|
$|++; # turn on autoflush
|
||||||
|
@ -21,106 +21,106 @@ use Time::HiRes;
|
||||||
|
|
||||||
# Hashtable of <destination number : test result expectation> pairs
|
# Hashtable of <destination number : test result expectation> pairs
|
||||||
my %numbers = (
|
my %numbers = (
|
||||||
503 => "NOTDETECTED", # dual frequency (similar to single freq with varying amplitude), mode [0] AVMD_DETECT_AMP
|
503 => "NOTDETECTED", # dual frequency (similar to single freq with varying amplitude), mode [0] AVMD_DETECT_AMP
|
||||||
504 => "NOTDETECTED",
|
504 => "NOTDETECTED",
|
||||||
505 => "NOTDETECTED",
|
505 => "NOTDETECTED",
|
||||||
506 => "NOTDETECTED",
|
506 => "NOTDETECTED",
|
||||||
507 => "NOTDETECTED",
|
507 => "NOTDETECTED",
|
||||||
508 => "NOTDETECTED",
|
508 => "NOTDETECTED",
|
||||||
509 => "NOTDETECTED",
|
509 => "NOTDETECTED",
|
||||||
510 => "NOTDETECTED",
|
510 => "NOTDETECTED",
|
||||||
511 => "NOTDETECTED",
|
511 => "NOTDETECTED",
|
||||||
512 => "NOTDETECTED",
|
512 => "NOTDETECTED",
|
||||||
513 => "NOTDETECTED",
|
513 => "NOTDETECTED",
|
||||||
514 => "NOTDETECTED",
|
514 => "NOTDETECTED",
|
||||||
515 => "NOTDETECTED",
|
515 => "NOTDETECTED",
|
||||||
516 => "NOTDETECTED",
|
516 => "NOTDETECTED",
|
||||||
517 => "NOTDETECTED",
|
517 => "NOTDETECTED",
|
||||||
518 => "NOTDETECTED",
|
518 => "NOTDETECTED",
|
||||||
519 => "NOTDETECTED",
|
519 => "NOTDETECTED",
|
||||||
520 => "NOTDETECTED",
|
520 => "NOTDETECTED",
|
||||||
521 => "NOTDETECTED",
|
521 => "NOTDETECTED",
|
||||||
522 => "NOTDETECTED",
|
522 => "NOTDETECTED",
|
||||||
523 => "NOTDETECTED",
|
523 => "NOTDETECTED",
|
||||||
603 => "DETECTED", # dual frequency (similar to single freq with varying amplitude), mode [1] AVMD_DETECT_FREQ
|
603 => "DETECTED", # dual frequency (similar to single freq with varying amplitude), mode [1] AVMD_DETECT_FREQ
|
||||||
604 => "DETECTED",
|
604 => "DETECTED",
|
||||||
605 => "DETECTED",
|
605 => "DETECTED",
|
||||||
606 => "DETECTED",
|
606 => "DETECTED",
|
||||||
607 => "DETECTED",
|
607 => "DETECTED",
|
||||||
608 => "DETECTED",
|
608 => "DETECTED",
|
||||||
609 => "DETECTED",
|
609 => "DETECTED",
|
||||||
610 => "DETECTED",
|
610 => "DETECTED",
|
||||||
611 => "DETECTED",
|
611 => "DETECTED",
|
||||||
612 => "DETECTED",
|
612 => "DETECTED",
|
||||||
613 => "DETECTED",
|
613 => "DETECTED",
|
||||||
614 => "DETECTED",
|
614 => "DETECTED",
|
||||||
615 => "DETECTED",
|
615 => "DETECTED",
|
||||||
616 => "DETECTED",
|
616 => "DETECTED",
|
||||||
617 => "DETECTED",
|
617 => "DETECTED",
|
||||||
618 => "DETECTED",
|
618 => "DETECTED",
|
||||||
619 => "DETECTED",
|
619 => "DETECTED",
|
||||||
620 => "DETECTED",
|
620 => "DETECTED",
|
||||||
621 => "DETECTED",
|
621 => "DETECTED",
|
||||||
622 => "DETECTED",
|
622 => "DETECTED",
|
||||||
623 => "DETECTED",
|
623 => "DETECTED",
|
||||||
703 => "NOTDETECTED", # dual frequency (similar to single freq with varying amplitude), mode [2] AVMD_DETECT_BOTH
|
703 => "NOTDETECTED", # dual frequency (similar to single freq with varying amplitude), mode [2] AVMD_DETECT_BOTH
|
||||||
704 => "NOTDETECTED",
|
704 => "NOTDETECTED",
|
||||||
705 => "NOTDETECTED",
|
705 => "NOTDETECTED",
|
||||||
706 => "NOTDETECTED",
|
706 => "NOTDETECTED",
|
||||||
707 => "NOTDETECTED",
|
707 => "NOTDETECTED",
|
||||||
708 => "NOTDETECTED",
|
708 => "NOTDETECTED",
|
||||||
709 => "NOTDETECTED",
|
709 => "NOTDETECTED",
|
||||||
710 => "NOTDETECTED",
|
710 => "NOTDETECTED",
|
||||||
711 => "NOTDETECTED",
|
711 => "NOTDETECTED",
|
||||||
712 => "NOTDETECTED",
|
712 => "NOTDETECTED",
|
||||||
713 => "NOTDETECTED",
|
713 => "NOTDETECTED",
|
||||||
714 => "NOTDETECTED",
|
714 => "NOTDETECTED",
|
||||||
715 => "NOTDETECTED",
|
715 => "NOTDETECTED",
|
||||||
716 => "NOTDETECTED",
|
716 => "NOTDETECTED",
|
||||||
717 => "NOTDETECTED",
|
717 => "NOTDETECTED",
|
||||||
718 => "NOTDETECTED",
|
718 => "NOTDETECTED",
|
||||||
719 => "NOTDETECTED",
|
719 => "NOTDETECTED",
|
||||||
720 => "NOTDETECTED",
|
720 => "NOTDETECTED",
|
||||||
721 => "NOTDETECTED",
|
721 => "NOTDETECTED",
|
||||||
722 => "NOTDETECTED",
|
722 => "NOTDETECTED",
|
||||||
723 => "NOTDETECTED",
|
723 => "NOTDETECTED",
|
||||||
840531000 => "DETECTED", # obscure voicemails, mode AVMD_DETECT_BOTH
|
840531000 => "DETECTED", # obscure voicemails, mode AVMD_DETECT_BOTH
|
||||||
840531001 => "DETECTED",
|
840531001 => "DETECTED",
|
||||||
840531002 => "DETECTED",
|
840531002 => "DETECTED",
|
||||||
840531003 => "DETECTED",
|
840531003 => "DETECTED",
|
||||||
840531004 => "DETECTED",
|
840531004 => "DETECTED",
|
||||||
840531005 => "DETECTED",
|
840531005 => "DETECTED",
|
||||||
840531006 => "DETECTED",
|
840531006 => "DETECTED",
|
||||||
840531007 => "DETECTED",
|
840531007 => "DETECTED",
|
||||||
840531008 => "DETECTED",
|
840531008 => "DETECTED",
|
||||||
840531009 => "DETECTED",
|
840531009 => "DETECTED",
|
||||||
840531010 => "DETECTED",
|
840531010 => "DETECTED",
|
||||||
840531011 => "DETECTED",
|
840531011 => "DETECTED",
|
||||||
840531012 => "DETECTED",
|
840531012 => "DETECTED",
|
||||||
840531013 => "DETECTED",
|
840531013 => "DETECTED",
|
||||||
840531014 => "DETECTED",
|
840531014 => "DETECTED",
|
||||||
840531200 => "DETECTED", # obscure voicemails, mode AVMD_DETECT_FREQ
|
840531200 => "DETECTED", # obscure voicemails, mode AVMD_DETECT_FREQ
|
||||||
840531201 => "DETECTED",
|
840531201 => "DETECTED",
|
||||||
840531202 => "DETECTED",
|
840531202 => "DETECTED",
|
||||||
840531203 => "DETECTED",
|
840531203 => "DETECTED",
|
||||||
840531204 => "DETECTED",
|
840531204 => "DETECTED",
|
||||||
840531205 => "DETECTED",
|
840531205 => "DETECTED",
|
||||||
840531206 => "DETECTED",
|
840531206 => "DETECTED",
|
||||||
840531207 => "DETECTED",
|
840531207 => "DETECTED",
|
||||||
840531208 => "DETECTED",
|
840531208 => "DETECTED",
|
||||||
840531209 => "DETECTED",
|
840531209 => "DETECTED",
|
||||||
840531210 => "DETECTED",
|
840531210 => "DETECTED",
|
||||||
840531211 => "DETECTED",
|
840531211 => "DETECTED",
|
||||||
840531212 => "DETECTED",
|
840531212 => "DETECTED",
|
||||||
840531213 => "DETECTED",
|
840531213 => "DETECTED",
|
||||||
840531214 => "DETECTED",
|
840531214 => "DETECTED",
|
||||||
840531400 => "DETECTED", # obscure voicemails ATT pack
|
840531400 => "DETECTED", # obscure voicemails ATT pack
|
||||||
840531401 => "DETECTED",
|
840531401 => "DETECTED",
|
||||||
840531402 => "DETECTED",
|
840531402 => "DETECTED",
|
||||||
840531403 => "DETECTED",
|
840531403 => "DETECTED",
|
||||||
840531404 => "DETECTED",
|
840531404 => "DETECTED",
|
||||||
840531405 => "DETECTED",
|
840531405 => "DETECTED",
|
||||||
840531051 => "NOTDETECTED", # fragment of "Save tonight" by Eagle-Eye Cherry covered by D-Lete-Funk-K
|
840531051 => "NOTDETECTED", # fragment of "Save tonight" by Eagle-Eye Cherry covered by D-Lete-Funk-K
|
||||||
);
|
);
|
||||||
|
|
||||||
my $host = "127.0.0.1";
|
my $host = "127.0.0.1";
|
||||||
|
@ -140,24 +140,24 @@ my $hanguped = 0;
|
||||||
|
|
||||||
|
|
||||||
if ($#ARGV + 1 eq 1) {
|
if ($#ARGV + 1 eq 1) {
|
||||||
$callerid = $ARGV[0];
|
$callerid = $ARGV[0];
|
||||||
print "\nDialing as [" .$callerid ."]\n";
|
print "\nDialing as [" .$callerid ."]\n";
|
||||||
} elsif ($#ARGV + 1 > 1) {
|
} elsif ($#ARGV + 1 > 1) {
|
||||||
die "Please specify single caller id.\n";
|
die "Please specify single caller id.\n";
|
||||||
} else {
|
} else {
|
||||||
die "Please specify caller id.\n";
|
die "Please specify caller id.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
print "Connecting...\t";
|
print "Connecting...\t";
|
||||||
my $con = new ESL::ESLconnection($host, $port, $pass);
|
my $con = new ESL::ESLconnection($host, $port, $pass);
|
||||||
if (!$con) {
|
if (!$con) {
|
||||||
die "Unable to establish connection to $host:$port\n";
|
die "Unable to establish connection to $host:$port\n";
|
||||||
}
|
}
|
||||||
if ($con->connected()) {
|
if ($con->connected()) {
|
||||||
print "OK.\n";
|
print "OK.\n";
|
||||||
} else {
|
} else {
|
||||||
die "Connection failure.\n";
|
die "Connection failure.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Subscribing to avmd events...\t";
|
print "Subscribing to avmd events...\t";
|
||||||
|
@ -171,95 +171,95 @@ printf("\nRunning [" .keys(%numbers) ."] tests.\n\n");
|
||||||
|
|
||||||
printf("outbound uuid | destination number | timestamp | expectation | test result | freq | f-variance | amplitude | a-variance | resolution | offset | idx\n\n");
|
printf("outbound uuid | destination number | timestamp | expectation | test result | freq | f-variance | amplitude | a-variance | resolution | offset | idx\n\n");
|
||||||
foreach $dest (sort keys %numbers) {
|
foreach $dest (sort keys %numbers) {
|
||||||
if (!$con->connected()) {
|
if (!$con->connected()) {
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
$expectation = $numbers{$dest};
|
$expectation = $numbers{$dest};
|
||||||
test_once($dest, $callerid, $expectation);
|
test_once($dest, $callerid, $expectation);
|
||||||
}
|
}
|
||||||
print "Disconnected.\n\n";
|
print "Disconnected.\n\n";
|
||||||
if (($failed == 0) && ($hanguped == 0)) {
|
if (($failed == 0) && ($hanguped == 0)) {
|
||||||
printf("\n\nOK. All PASS [%s]\n\n", $passed);
|
printf("\n\nOK. All PASS [%s]\n\n", $passed);
|
||||||
} else {
|
} else {
|
||||||
printf("PASS [%s], FAIL [%s], HANGUP [%s]\n\n", $passed, $failed, $hanguped);
|
printf("PASS [%s], FAIL [%s], HANGUP [%s]\n\n", $passed, $failed, $hanguped);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub test_once {
|
sub test_once {
|
||||||
my ($dest, $callerid, $expectation) = @_;
|
my ($dest, $callerid, $expectation) = @_;
|
||||||
my $originate_string =
|
my $originate_string =
|
||||||
'originate ' .
|
'originate ' .
|
||||||
'{ignore_early_media=true,' .
|
'{ignore_early_media=true,' .
|
||||||
'origination_uuid=%s,' .
|
'origination_uuid=%s,' .
|
||||||
'originate_timeout=60,' .
|
'originate_timeout=60,' .
|
||||||
'origination_caller_id_number=' . $callerid . ',' .
|
'origination_caller_id_number=' . $callerid . ',' .
|
||||||
'origination_caller_id_name=' . $callerid . '}';
|
'origination_caller_id_name=' . $callerid . '}';
|
||||||
my $outcome = "";
|
my $outcome = "";
|
||||||
my $result = "";
|
my $result = "";
|
||||||
my $event_uuid = "N/A";
|
my $event_uuid = "N/A";
|
||||||
my $uuid_in = "";
|
my $uuid_in = "";
|
||||||
my $freq = "N/A";
|
my $freq = "N/A";
|
||||||
my $freq_var = "N/A";
|
my $freq_var = "N/A";
|
||||||
my $amp = "N/A";
|
my $amp = "N/A";
|
||||||
my $amp_var = "N/A";
|
my $amp_var = "N/A";
|
||||||
my $resolution = "N/A";
|
my $resolution = "N/A";
|
||||||
my $offset = "N/A";
|
my $offset = "N/A";
|
||||||
my $idx = "N/A";
|
my $idx = "N/A";
|
||||||
|
|
||||||
if(defined($endpoint)) {
|
if(defined($endpoint)) {
|
||||||
$originate_string .= $endpoint;
|
$originate_string .= $endpoint;
|
||||||
} else {
|
} else {
|
||||||
$originate_string .= 'loopback/' . $dest . '/' . $context;
|
$originate_string .= 'loopback/' . $dest . '/' . $context;
|
||||||
}
|
}
|
||||||
$originate_string .= ' ' . '&playback(' . $playback . ')';
|
$originate_string .= ' ' . '&playback(' . $playback . ')';
|
||||||
|
|
||||||
my $uuid_out = $con->api('create_uuid')->getBody();
|
my $uuid_out = $con->api('create_uuid')->getBody();
|
||||||
my ($time_epoch, $time_hires) = Time::HiRes::gettimeofday();
|
my ($time_epoch, $time_hires) = Time::HiRes::gettimeofday();
|
||||||
|
|
||||||
printf("[%s] [%s]", $uuid_out, $dest);
|
printf("[%s] [%s]", $uuid_out, $dest);
|
||||||
$con->bgapi(sprintf($originate_string, $uuid_out));
|
$con->bgapi(sprintf($originate_string, $uuid_out));
|
||||||
|
|
||||||
while($con->connected()) {
|
while($con->connected()) {
|
||||||
my $e = $con->recvEvent();
|
my $e = $con->recvEvent();
|
||||||
if ($e) {
|
if ($e) {
|
||||||
my $event_name = $e->getHeader("Event-Name");
|
my $event_name = $e->getHeader("Event-Name");
|
||||||
if ($event_name eq 'CUSTOM') {
|
if ($event_name eq 'CUSTOM') {
|
||||||
my $avmd_event_type = $e->getHeader("Event-Subclass");
|
my $avmd_event_type = $e->getHeader("Event-Subclass");
|
||||||
if ($avmd_event_type eq 'avmd::start') {
|
if ($avmd_event_type eq 'avmd::start') {
|
||||||
$uuid_in = $e->getHeader("Unique-ID");
|
$uuid_in = $e->getHeader("Unique-ID");
|
||||||
} elsif (!($uuid_in eq "") && (($avmd_event_type eq 'avmd::beep') || ($avmd_event_type eq 'avmd::stop'))) {
|
} elsif (!($uuid_in eq "") && (($avmd_event_type eq 'avmd::beep') || ($avmd_event_type eq 'avmd::stop'))) {
|
||||||
$event_uuid = $e->getHeader("Unique-ID");
|
$event_uuid = $e->getHeader("Unique-ID");
|
||||||
if ($event_uuid eq $uuid_in) {
|
if ($event_uuid eq $uuid_in) {
|
||||||
if ($avmd_event_type eq 'avmd::beep') {
|
if ($avmd_event_type eq 'avmd::beep') {
|
||||||
$freq = $e->getHeader("Frequency");
|
$freq = $e->getHeader("Frequency");
|
||||||
$freq_var = $e->getHeader("Frequency-variance");
|
$freq_var = $e->getHeader("Frequency-variance");
|
||||||
$amp = $e->getHeader("Amplitude");
|
$amp = $e->getHeader("Amplitude");
|
||||||
$amp_var = $e->getHeader("Amplitude-variance");
|
$amp_var = $e->getHeader("Amplitude-variance");
|
||||||
$resolution = $e->getHeader("Detector-resolution");
|
$resolution = $e->getHeader("Detector-resolution");
|
||||||
$offset = $e->getHeader("Detector-offset");
|
$offset = $e->getHeader("Detector-offset");
|
||||||
$idx = $e->getHeader("Detector-index");
|
$idx = $e->getHeader("Detector-index");
|
||||||
}
|
}
|
||||||
$outcome = $e->getHeader("Beep-Status");
|
$outcome = $e->getHeader("Beep-Status");
|
||||||
if ($outcome eq $expectation) {
|
if ($outcome eq $expectation) {
|
||||||
$result = "PASS";
|
$result = "PASS";
|
||||||
$passed++;
|
$passed++;
|
||||||
} else {
|
} else {
|
||||||
$result = "FAIL";
|
$result = "FAIL";
|
||||||
$failed++;
|
$failed++;
|
||||||
}
|
}
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elsif ($event_name eq 'CHANNEL_HANGUP') {
|
} elsif ($event_name eq 'CHANNEL_HANGUP') {
|
||||||
$event_uuid = $e->getHeader("variable_origination_uuid");
|
$event_uuid = $e->getHeader("variable_origination_uuid");
|
||||||
if ((defined $event_uuid) && ($event_uuid eq $uuid_out)) {
|
if ((defined $event_uuid) && ($event_uuid eq $uuid_out)) {
|
||||||
$outcome = "HANGUP";
|
$outcome = "HANGUP";
|
||||||
$result = "HANGUP";
|
$result = "HANGUP";
|
||||||
$hanguped++;
|
$hanguped++;
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("\t[%s]\t[%s]\t\t[%s]\t[%s]HZ\t[%s]\t[%s]\t[%s]\t[%s][%s][%s]\n", POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($time_epoch)), $expectation, $result, $freq, $freq_var, $amp, $amp_var, $resolution, $offset, $idx);
|
printf("\t[%s]\t[%s]\t\t[%s]\t[%s]HZ\t[%s]\t[%s]\t[%s]\t[%s][%s][%s]\n", POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($time_epoch)), $expectation, $result, $freq, $freq_var, $amp, $amp_var, $resolution, $offset, $idx);
|
||||||
Time::HiRes::sleep(0.5); # avoid switch_core_session.c:2265 Throttle Error! 33, switch_time.c:1227 Over Session Rate of 30!
|
Time::HiRes::sleep(0.5); # avoid switch_core_session.c:2265 Throttle Error! 33, switch_time.c:1227 Over Session Rate of 30!
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue