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