]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_avmd] fix formatting to match coding standards 1432/head
authorChris Rienzo <chris@signalwire.com>
Sat, 6 Nov 2021 00:11:32 +0000 (00:11 +0000)
committerChris Rienzo <chris@signalwire.com>
Sat, 6 Nov 2021 00:11:32 +0000 (00:11 +0000)
24 files changed:
src/mod/applications/mod_avmd/avmd_amplitude.c
src/mod/applications/mod_avmd/avmd_amplitude.h
src/mod/applications/mod_avmd/avmd_buffer.c
src/mod/applications/mod_avmd/avmd_buffer.h
src/mod/applications/mod_avmd/avmd_desa2.c
src/mod/applications/mod_avmd/avmd_desa2.h
src/mod/applications/mod_avmd/avmd_desa2_tweaked.c
src/mod/applications/mod_avmd/avmd_desa2_tweaked.h
src/mod/applications/mod_avmd/avmd_fast_acosf.c
src/mod/applications/mod_avmd/avmd_fast_acosf.h
src/mod/applications/mod_avmd/avmd_fir.h
src/mod/applications/mod_avmd/avmd_goertzel.c
src/mod/applications/mod_avmd/avmd_goertzel.h
src/mod/applications/mod_avmd/avmd_options.h
src/mod/applications/mod_avmd/avmd_psi.h
src/mod/applications/mod_avmd/avmd_sma_buf.h
src/mod/applications/mod_avmd/conf/autoload_configs/avmd.conf.xml
src/mod/applications/mod_avmd/conf/avmd_test_dialplan.xml
src/mod/applications/mod_avmd/mod_avmd.c
src/mod/applications/mod_avmd/scripts/avmd_get_events.pl
src/mod/applications/mod_avmd/scripts/avmd_originate.pl
src/mod/applications/mod_avmd/scripts/avmd_originate_multiple.pl
src/mod/applications/mod_avmd/scripts/avmd_originate_multiple_loopback.pl
src/mod/applications/mod_avmd/scripts/avmd_test.pl

index 86523fad4b3d76793a4e09f6731e2267d201d6aa..e4cd3745e339ff0edb276a1afe4fa93233601292 100644 (file)
@@ -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;
 }
index da98d083e5861bf3cca8e08c7ad7cf3132b826c5..1ada7290112476d33613b771acee6145f0522808 100644 (file)
@@ -4,7 +4,7 @@
  * Contributor(s):
  *
  * Eric des Courtis <eric.des.courtis@benbria.com>
- * Piotr Gregor     <piotrgregor@rsyncme.org>
+ * Piotr Gregor <piotrgregor@rsyncme.org>
  */
 
 
index f05f0deb4c01b691063cbf02e2db3668899041c8..f673a8d31bd47cc06e8aa63b654cc32b62001067 100644 (file)
 
 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;
 }
 
 
index 11d874b5ddeaae2fde8fb91c0847333211bef608..416072caf9ca87e9c4312504645d6174b6db8a07 100644 (file)
@@ -4,7 +4,7 @@
  * Contributor(s):
  *
  * Eric des Courtis <eric.des.courtis@benbria.com>
- * Piotr Gregor     <piotrgregor@rsyncme.org>
+ * Piotr Gregor <piotrgregor@rsyncme.org>
  */
 
 
 #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__ */
index f6b62785d159373bdf4ce6f06153ec836844b591..72e347fffd398b1177e2259d2e8402d5017b2673 100644 (file)
@@ -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"
 #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;
 
 }
index 6e8f6e58a7f2106f67fd1d6c26087709034c2ab0..83541ed38d367fd016de29f9d3aa933343732c93 100644 (file)
@@ -4,7 +4,7 @@
  * Contributor(s):
  *
  * Eric des Courtis <eric.des.courtis@benbria.com>
- * Piotr Gregor     <piotrgregor@rsyncme.org>
+ * Piotr Gregor <piotrgregor@rsyncme.org>
  */
 
 
index a6dab2be287f352c04a9e1e651f1e8cc83fb0c9b..9aadbb9dac7c974a3b154364180431b0cd0ece5a 100644 (file)
@@ -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;
 }
index ac6d6fc4d886cdd01a2c10cca122b4608c339c2a..38d788cde4ca3c3f87e075f4c55eebcd41d58fac 100644 (file)
@@ -10,7 +10,7 @@
  *
  * Contributor(s):
  *
- * Piotr Gregor     <piotrgregor@rsyncme.org>
+ * Piotr Gregor <piotrgregor@rsyncme.org>
  *
  * @date    20 Mar 2016
  */
index b0d8655d6e4bc241f5bfdcfcc7eec98947085697..572c6a84f9136dfa020fac603990edab254d81b1 100644 (file)
@@ -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;
-
-    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;
-        }
-    }
-
-    res = fclose(acos_table_file);
-    if (res != 0) {
-        return -2;
-    }
-    return 0;
+       uint32_t i;
+       float f;
+       FILE *acos_table_file;
+       size_t res;
+
+       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;
+               }
+       }
+
+       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];
-
-    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;
-
-    return 0;
+       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
+                       );
+               }
+       }
+
+       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;
 }
 
 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;
-
-    return 0;
+       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;
 }
 
 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;
-
-    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));
-    }
-
-    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);
+       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;
+
+       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));
+       }
+
+       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 */
index 8de7954def8396a62c6c14dc8ffda93402593bb2..93e43ba4385f366f6fe77efc5ee00195526a308e 100644 (file)
@@ -5,7 +5,7 @@
  * Contributor(s):
  *
  * Eric des Courtis <eric.des.courtis@benbria.com>
- * Piotr Gregor     <piotrgregor@rsyncme.org>
+ * Piotr Gregor <piotrgregor@rsyncme.org>
  */
 
 
index 25a2c23bb32d4b0f5b846f3540b675299c74475c..12dd1019ae18ecb76c3454d85fd9f6d22218d5b7 100644 (file)
@@ -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
index 5f05c00b220a09e5909f9fcd60c2faf5e631d5b9..15650397bca16664837a1284ddccffad5434a527 100644 (file)
@@ -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;
-
-    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;
-    }
-
-    return (p2 * p2) + (p * p) - (coeff * p2 * p);
+       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);
+
+       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);
 }
index 21ba3f51541870573d40f9f38ff97e8d5c21a6e5..be7920c933ebfdf066acdfaa415bf08acfe6c95c 100644 (file)
 
 
 #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
 
 
index a580af811ef28e36a8d11a579917f4316849e906..f1c23dcc552e3e03c30b12a7577962a04b6bfdab 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Contributor(s):
  *
- * Piotr Gregor     <piotrgregor@rsyncme.org>
+ * Piotr Gregor <piotrgregor@rsyncme.org>
  */
 
 
index dbbf401282b63c63031e608d20d7fb0ef3845a33..49f22090a93e206d1d78f7711fb3c3abf5bd3512 100644 (file)
@@ -2,7 +2,7 @@
  * Contributor(s):
  *
  * Eric des Courtis <eric.des.courtis@benbria.com>
- * Piotr Gregor     <piotrgregor@rsyncme.org>
+ * Piotr Gregor <piotrgregor@rsyncme.org>
  */
 
 
index e3051c9731339c3cbc36871eed3deb1478074f5a..0ee1aa5a9ecdc827164eb70fd985b494d3844dba 100644 (file)
@@ -4,7 +4,7 @@
  * Contributor(s):
  *
  * Eric des Courtis <eric.des.courtis@benbria.com>
- * Piotr Gregor     <piotrgregor@rsyncme.org>
+ * Piotr Gregor <piotrgregor@rsyncme.org>
  */
 
 
 #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;
 }
 
 */
index 86b2500bad23f033ee563a0ddac35fbde89b7f8f..cfd710f530d84d1f1cc96c2d6e9bd484f3d94b20 100644 (file)
@@ -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>
 
index de567a8350bfdad43e02de574985e57945cd9661..2a85ec7a607d2e99f0a424ff53b119d9fde8eee8 100644 (file)
 
-    <extension name="1701">
-      <condition field="destination_number" expression="^1701$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="voicemail/sin1000hz.raw"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-    <extension name="1702">
-      <condition field="destination_number" expression="^1702$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="voicemail/sin1200hz.raw"/>
-          <action application="hangup"/>
-          <action application="avmd" data="stop"/>
-      </condition>
-  </extension>
-    <extension name="1703">
-      <condition field="destination_number" expression="^1703$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="voicemail/sin1400hz.raw"/>
-          <action application="hangup"/>
-          <action application="avmd_stop"/>
-      </condition>
-  </extension>
-    <extension name="1704">
-      <condition field="destination_number" expression="^1704$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="voicemail/8000/sin1600hz.raw"/>
-          <action application="avmd_stop"/>
-        <action application="hangup"/>
-      </condition>
-  </extension>
+       <extension name="1701">
+               <condition field="destination_number" expression="^1701$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="voicemail/sin1000hz.raw"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="1702">
+               <condition field="destination_number" expression="^1702$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="voicemail/sin1200hz.raw"/>
+                       <action application="hangup"/>
+                       <action application="avmd" data="stop"/>
+               </condition>
+       </extension>
+       <extension name="1703">
+               <condition field="destination_number" expression="^1703$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="voicemail/sin1400hz.raw"/>
+                       <action application="hangup"/>
+                       <action application="avmd_stop"/>
+               </condition>
+       </extension>
+       <extension name="1704">
+               <condition field="destination_number" expression="^1704$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="voicemail/8000/sin1600hz.raw"/>
+                       <action application="avmd_stop"/>
+               <action application="hangup"/>
+               </condition>
+       </extension>
 
-  <extension name="503"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(503)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,400,500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="504"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(504)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,500,600)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="505"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(505)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,600,700)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="506"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(506)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,700,800)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="507"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(507)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,800,900)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="508"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(508)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,900,1000)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="509"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(509)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1000,1100)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="510"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(510)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1100,1200)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="511"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(511)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1200,1300)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="512"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(512)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1300,1400)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="513"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(513)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1400,1500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="514"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(514)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1500,1600)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="515"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(515)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1600,1700)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="516"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(516)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1700,1800)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="517"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(517)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1800,1900)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="518"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(518)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1900,1950)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="519"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(519)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,200,500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="520"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(520)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,500,700)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="521"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(521)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,100,500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="522"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(522)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1000,1500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="523"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(523)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1500,2000)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
+       <extension name="503"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(503)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,400,500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="504"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(504)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,500,600)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="505"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(505)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,600,700)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="506"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(506)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,700,800)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="507"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(507)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,800,900)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="508"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(508)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,900,1000)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="509"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(509)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1000,1100)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="510"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(510)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1100,1200)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="511"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(511)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1200,1300)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="512"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(512)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1300,1400)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="513"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(513)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1400,1500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="514"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(514)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1500,1600)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="515"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(515)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1600,1700)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="516"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(516)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1700,1800)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="517"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(517)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1800,1900)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="518"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(518)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1900,1950)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="519"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(519)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,200,500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="520"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(520)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,500,700)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="521"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(521)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,100,500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="522"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(522)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1000,1500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="523"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(523)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=0"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1500,2000)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
 
-  <extension name="603"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(603)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,400,500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="604"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(604)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,500,600)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="605"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(605)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,600,700)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="606"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(606)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,700,800)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="607"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(607)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,800,900)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="608"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(608)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,900,1000)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="609"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(609)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1000,1100)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="610"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(610)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1100,1200)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="611"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(611)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1200,1300)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="612"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(612)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1300,1400)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="613"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(613)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1400,1500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="614"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(614)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1500,1600)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="615"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(615)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1600,1700)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="616"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(616)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1700,1800)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="617"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(617)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1800,1900)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="618"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(618)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1900,1950)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="619"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(619)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,200,500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="620"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(620)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,500,700)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="621"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(621)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,100,500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="622"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(622)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1000,1500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="623"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(623)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1500,2000)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
+       <extension name="603"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(603)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,400,500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="604"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(604)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,500,600)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="605"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(605)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,600,700)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="606"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(606)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,700,800)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="607"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(607)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,800,900)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="608"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(608)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,900,1000)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="609"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(609)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1000,1100)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="610"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(610)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1100,1200)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="611"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(611)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1200,1300)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="612"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(612)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1300,1400)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="613"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(613)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1400,1500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="614"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(614)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1500,1600)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="615"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(615)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1600,1700)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="616"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(616)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1700,1800)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="617"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(617)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1800,1900)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="618"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(618)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1900,1950)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="619"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(619)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,200,500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="620"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(620)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,500,700)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="621"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(621)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,100,500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="622"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(622)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1000,1500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="623"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(623)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=1"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1500,2000)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
 
-  <extension name="703"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(703)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,400,500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="704"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(704)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,500,600)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="705"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(705)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,600,700)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="706"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(706)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,700,800)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="707"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(707)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,800,900)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="708"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(708)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,900,1000)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="709"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(709)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1000,1100)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="710"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(710)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1100,1200)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="711"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(711)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1200,1300)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="712"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(712)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1300,1400)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="713"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(713)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1400,1500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="714"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(714)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1500,1600)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="715"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(715)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1600,1700)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="716"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(716)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1700,1800)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="717"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(717)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1800,1900)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="718"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(718)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1900,1950)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="719"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(719)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,200,500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="720"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(720)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,500,700)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="721"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(721)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,100,500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="722"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(722)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1000,1500)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="723"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
-      <condition field="destination_number" expression="^(723)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
-          <action application="playback" data="tone_stream://L=1;%(1850,1000,1500,2000)" />
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
+       <extension name="703"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(703)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,400,500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="704"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(704)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,500,600)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="705"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(705)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,600,700)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="706"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(706)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,700,800)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="707"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(707)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,800,900)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="708"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(708)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,900,1000)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="709"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(709)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1000,1100)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="710"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(710)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1100,1200)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="711"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(711)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1200,1300)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="712"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(712)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1300,1400)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="713"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(713)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1400,1500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="714"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(714)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1500,1600)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="715"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(715)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1600,1700)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="716"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(716)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1700,1800)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="717"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(717)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1800,1900)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="718"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(718)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1900,1950)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="719"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(719)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,200,500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="720"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(720)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,500,700)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="721"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(721)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,100,500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="722"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(722)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1000,1500)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="723"><!-- this BEEP must be DETECETD in detection_mode 1 (FREQ), NOTDETECTED in detection_mode 0 (AMP) and 2 (BOTH) -->
+               <condition field="destination_number" expression="^(723)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,debug=0,detection_mode=2"/>
+                       <action application="playback" data="tone_stream://L=1;%(1850,1000,1500,2000)" />
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
 
-  <extension name="840531000"><!-- obscure voicemail  -->
-      <condition field="destination_number" expression="^(840531000)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/2086613157-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531001"><!-- obscure voicemail  -->
-      <condition field="destination_number" expression="^(840531001)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/2179185111-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531002"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531002)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/2539488697-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531003"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531003)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/2565910163-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531004"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531004)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/2679091031-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531005"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531005)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/2815939138-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531006"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531006)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/2819127763-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531007"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531007)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/3157668346-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531008"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531008)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/4064659099-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531009"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531009)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/6062255782-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531010"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531010)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/8477910425-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531011"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531011)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2"/>
-          <action application="playback" data="voicemail/8000/8508497121-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531012"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531012)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/8635280270-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531013"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531013)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2"/>
-          <action application="playback" data="voicemail/8000/9106390422-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531014"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531014)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2"/>
-          <action application="playback" data="voicemail/8000/9156332150-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
+       <extension name="840531000"><!-- obscure voicemail      -->
+               <condition field="destination_number" expression="^(840531000)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2086613157-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531001"><!-- obscure voicemail      -->
+               <condition field="destination_number" expression="^(840531001)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2179185111-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531002"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531002)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2539488697-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531003"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531003)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2565910163-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531004"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531004)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2679091031-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531005"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531005)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2815939138-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531006"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531006)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2819127763-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531007"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531007)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/3157668346-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531008"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531008)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/4064659099-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531009"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531009)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/6062255782-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531010"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531010)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/8477910425-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531011"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531011)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2"/>
+                       <action application="playback" data="voicemail/8000/8508497121-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531012"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531012)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/8635280270-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531013"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531013)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2"/>
+                       <action application="playback" data="voicemail/8000/9106390422-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531014"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531014)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2"/>
+                       <action application="playback" data="voicemail/8000/9156332150-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
 
-  <extension name="840531200"><!-- obscure voicemail  -->
-      <condition field="destination_number" expression="^(840531200)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/2086613157-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531201"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531201)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/2179185111-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531202"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531202)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/2539488697-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531203"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531203)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/2565910163-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531204"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531204)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/2679091031-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531205"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531205)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/2815939138-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531206"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531206)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/2819127763-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531207"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531207)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/3157668346-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531208"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531208)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/4064659099-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531209"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531209)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/6062255782-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531210"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531210)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/8477910425-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531211"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531211)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/8508497121-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531212"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531212)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/8635280270-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531213"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531213)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/9106390422-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531214"><!-- obscure voicemail -->
-      <condition field="destination_number" expression="^(840531214)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
-          <action application="playback" data="voicemail/8000/9156332150-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
+       <extension name="840531200"><!-- obscure voicemail      -->
+               <condition field="destination_number" expression="^(840531200)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2086613157-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531201"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531201)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2179185111-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531202"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531202)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2539488697-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531203"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531203)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2565910163-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531204"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531204)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2679091031-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531205"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531205)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2815939138-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531206"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531206)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2819127763-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531207"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531207)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/3157668346-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531208"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531208)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/4064659099-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531209"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531209)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/6062255782-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531210"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531210)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/8477910425-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531211"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531211)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/8508497121-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531212"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531212)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/8635280270-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531213"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531213)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/9106390422-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531214"><!-- obscure voicemail -->
+               <condition field="destination_number" expression="^(840531214)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=1,debug=0"/>
+                       <action application="playback" data="voicemail/8000/9156332150-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
 
-  <extension name="840531400"><!-- obscure voicemail pack 2 -->
-      <condition field="destination_number" expression="^(840531400)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/2764944714-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531401"><!-- obscure voicemail pack 2 -->
-      <condition field="destination_number" expression="^(840531401)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/3054957758-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531402"><!-- obscure voicemail pack 2 -->
-      <condition field="destination_number" expression="^(840531402)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/5044810548-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531403"><!-- obscure voicemail pack 2 -->
-      <condition field="destination_number" expression="^(840531403)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/5852842171-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531404"><!-- obscure voicemail pack 2 -->
-      <condition field="destination_number" expression="^(840531404)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/5857330628-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
-  <extension name="840531405"><!-- obscure voicemail pack 2 -->
-      <condition field="destination_number" expression="^(840531405)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/8702463704-18-15-bad.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
+       <extension name="840531400"><!-- obscure voicemail pack 2 -->
+               <condition field="destination_number" expression="^(840531400)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/2764944714-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531401"><!-- obscure voicemail pack 2 -->
+               <condition field="destination_number" expression="^(840531401)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/3054957758-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531402"><!-- obscure voicemail pack 2 -->
+               <condition field="destination_number" expression="^(840531402)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/5044810548-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531403"><!-- obscure voicemail pack 2 -->
+               <condition field="destination_number" expression="^(840531403)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/5852842171-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531404"><!-- obscure voicemail pack 2 -->
+               <condition field="destination_number" expression="^(840531404)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/5857330628-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
+       <extension name="840531405"><!-- obscure voicemail pack 2 -->
+               <condition field="destination_number" expression="^(840531405)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/8702463704-18-15-bad.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
 
-  <extension name="840531051"><!-- fragment of "Save tonight" by Eagle-Eye Cherry covered by D-Lete-Funk-K -->
-      <condition field="destination_number" expression="^(840531051)$">
-          <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
-          <action application="playback" data="voicemail/8000/save_tonight_8000.wav"/>
-          <action application="avmd_stop"/>
-          <action application="hangup"/>
-      </condition>
-  </extension>
+       <extension name="840531051"><!-- fragment of "Save tonight" by Eagle-Eye Cherry covered by D-Lete-Funk-K -->
+               <condition field="destination_number" expression="^(840531051)$">
+                       <action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2,debug=0"/>
+                       <action application="playback" data="voicemail/8000/save_tonight_8000.wav"/>
+                       <action application="avmd_stop"/>
+                       <action application="hangup"/>
+               </condition>
+       </extension>
index ea1c5f483aee449f6af2cd8637eff406a99197e3..dde3dfbf9309278cca472e5578ed0aa7a924da7c 100644 (file)
@@ -20,7 +20,7 @@
  * Contributor(s):
  *
  * Eric des Courtis <eric.des.courtis@benbria.com>
- * Piotr Gregor     <piotrgregor@rsyncme.org>
+ * Piotr Gregor <piotrgregor@rsyncme.org>
  *
  * mod_avmd.c -- Advanced Voicemail Detection Module
  *
 #include <float.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))
 #else
-    int __isnan(double);
+       int __isnan(double);
        int __isinf(double);
-    #define ISNAN(x) (__isnan(x))
-    #define ISINF(x) (__isinf(x))
+       #define ISNAN(x) (__isnan(x))
+       #define ISINF(x) (__isinf(x))
 #endif
 
 #include "avmd_buffer.h"
 /* don't forget to update avmd_events_str table if you modify this */
 enum avmd_event
 {
-    AVMD_EVENT_BEEP = 0,
-    AVMD_EVENT_SESSION_START = 1,
-    AVMD_EVENT_SESSION_STOP = 2
+       AVMD_EVENT_BEEP = 0,
+       AVMD_EVENT_SESSION_START = 1,
+       AVMD_EVENT_SESSION_STOP = 2
 };
 /* This array MUST be NULL terminated! */
 const char* avmd_events_str[] = {
-    [AVMD_EVENT_BEEP] =             "avmd::beep",
-    [AVMD_EVENT_SESSION_START] =    "avmd::start",
-    [AVMD_EVENT_SESSION_STOP] =     "avmd::stop",
-    NULL                                            /* MUST be last and always here */
+       [AVMD_EVENT_BEEP] = "avmd::beep",
+       [AVMD_EVENT_SESSION_START] = "avmd::start",
+       [AVMD_EVENT_SESSION_STOP] = "avmd::stop",
+       NULL /* MUST be last and always here */
 };
 
 #define AVMD_CHAR_BUF_LEN 20u
@@ -136,17 +136,17 @@ const char* avmd_events_str[] = {
 
 enum avmd_app
 {
-    AVMD_APP_START_APP = 0,
-    AVMD_APP_STOP_APP = 1,
-    AVMD_APP_START_FUNCTION = 2     /* deprecated since version 1.6.8 */
+       AVMD_APP_START_APP = 0,
+       AVMD_APP_STOP_APP = 1,
+       AVMD_APP_START_FUNCTION = 2 /* deprecated since version 1.6.8 */
 };
 
 enum avmd_detection_mode
 {
-    AVMD_DETECT_AMP = 0,
-    AVMD_DETECT_FREQ = 1,
-    AVMD_DETECT_BOTH = 2,
-    AVMD_DETECT_NONE = 3
+       AVMD_DETECT_AMP = 0,
+       AVMD_DETECT_FREQ = 1,
+       AVMD_DETECT_BOTH = 2,
+       AVMD_DETECT_NONE = 3
 };
 
 /* Prototypes */
@@ -159,92 +159,92 @@ SWITCH_STANDARD_APP(avmd_stop_app);
 SWITCH_STANDARD_APP(avmd_start_function);
 
 struct avmd_settings {
-    uint8_t     debug;
-    uint8_t     report_status;
-    uint8_t     fast_math;
-    uint8_t     require_continuous_streak;
-    uint16_t    sample_n_continuous_streak;
-    uint16_t    sample_n_to_skip;
-    uint8_t     require_continuous_streak_amp;
-    uint16_t    sample_n_continuous_streak_amp;
-    uint8_t     simplified_estimation;
-    uint8_t     inbound_channnel;
-    uint8_t     outbound_channnel;
-    enum avmd_detection_mode mode;
-    uint8_t     detectors_n;
-    uint8_t     detectors_lagged_n;
+       uint8_t debug;
+       uint8_t report_status;
+       uint8_t fast_math;
+       uint8_t require_continuous_streak;
+       uint16_t sample_n_continuous_streak;
+       uint16_t sample_n_to_skip;
+       uint8_t require_continuous_streak_amp;
+       uint16_t sample_n_continuous_streak_amp;
+       uint8_t simplified_estimation;
+       uint8_t inbound_channnel;
+       uint8_t outbound_channnel;
+       enum avmd_detection_mode mode;
+       uint8_t detectors_n;
+       uint8_t detectors_lagged_n;
 };
 
 /*! Status of the beep detection */
 typedef enum {
-    BEEP_DETECTED,
-    BEEP_NOTDETECTED
+       BEEP_DETECTED,
+       BEEP_NOTDETECTED
 } avmd_beep_state_t;
 
 /*! Data related to the current status of the beep */
 typedef struct {
-    avmd_beep_state_t beep_state;
-    size_t last_beep;
+       avmd_beep_state_t beep_state;
+       size_t last_beep;
 } avmd_state_t;
 
 struct avmd_session;
 typedef struct avmd_session avmd_session_t;
 
 struct avmd_buffer {
-    sma_buffer_t    sma_b;
-    sma_buffer_t    sqa_b;
+       sma_buffer_t sma_b;
+       sma_buffer_t sqa_b;
 
-    sma_buffer_t    sma_b_fir;
-    sma_buffer_t    sqa_b_fir;
+       sma_buffer_t sma_b_fir;
+       sma_buffer_t sqa_b_fir;
 
-    sma_buffer_t    sma_amp_b;
-    sma_buffer_t    sqa_amp_b;
+       sma_buffer_t sma_amp_b;
+       sma_buffer_t sqa_amp_b;
 
-    uint8_t         resolution;
-    uint8_t         offset;
-    double          amplitude_max;
-    size_t samples_streak, samples_streak_amp; /* number of DESA samples in single streak without reset needed to validate SMA estimator */
+       uint8_t resolution;
+       uint8_t offset;
+       double amplitude_max;
+       size_t samples_streak, samples_streak_amp; /* number of DESA samples in single streak without reset needed to validate SMA estimator */
 };
 
 struct avmd_detector {
-    switch_thread_t *thread;
-    switch_mutex_t  *mutex;
-    uint8_t                     flag_processing_done;
-    uint8_t                     flag_should_exit;
-    enum avmd_detection_mode    result;
-    switch_thread_cond_t        *cond_start_processing;
-    struct avmd_buffer          buffer;
-    avmd_session_t              *s;
-    size_t                      samples;
-    uint8_t                     idx;
-    uint8_t                     lagged, lag;
+       switch_thread_t *thread;
+       switch_mutex_t *mutex;
+       uint8_t flag_processing_done;
+       uint8_t flag_should_exit;
+       enum avmd_detection_mode result;
+       switch_thread_cond_t *cond_start_processing;
+       struct avmd_buffer buffer;
+       avmd_session_t *s;
+       size_t samples;
+       uint8_t idx;
+       uint8_t lagged, lag;
 };
 
 /*! Type that holds avmd detection session information. */
 struct avmd_session {
-    switch_core_session_t   *session;
-    switch_mutex_t          *mutex;
-    struct avmd_settings    settings;
-    uint32_t        rate;
-    circ_buffer_t   b;
-    size_t          pos;
-    double          f;
-    avmd_state_t    state;
-    switch_time_t   start_time, stop_time, detection_start_time, detection_stop_time;
-    size_t          frame_n;
-    uint8_t         frame_n_to_skip;
-
-    switch_mutex_t          *mutex_detectors_done;
-    switch_thread_cond_t    *cond_detectors_done;
-    struct avmd_detector    *detectors;
+       switch_core_session_t *session;
+       switch_mutex_t *mutex;
+       struct avmd_settings settings;
+       uint32_t rate;
+       circ_buffer_t b;
+       size_t pos;
+       double f;
+       avmd_state_t state;
+       switch_time_t start_time, stop_time, detection_start_time, detection_stop_time;
+       size_t frame_n;
+       uint8_t frame_n_to_skip;
+
+       switch_mutex_t *mutex_detectors_done;
+       switch_thread_cond_t *cond_detectors_done;
+       struct avmd_detector *detectors;
 };
 
 static struct avmd_globals
 {
-    switch_mutex_t          *mutex;
-    struct avmd_settings    settings;
-    switch_memory_pool_t    *pool;
-    size_t                  session_n;
+       switch_mutex_t *mutex;
+       struct avmd_settings settings;
+       switch_memory_pool_t *pool;
+       size_t session_n;
 } avmd_globals;
 
 static void avmd_process(avmd_session_t *session, switch_frame_t *frame, uint8_t direction);
@@ -255,7 +255,7 @@ static switch_status_t avmd_register_all_events(void);
 static void avmd_unregister_all_events(void);
 
 static void avmd_fire_event(enum avmd_event type, switch_core_session_t *fs_s, double freq, double v_freq, double amp, double v_amp, avmd_beep_state_t beep_status, uint8_t info,
-        switch_time_t detection_start_time, switch_time_t detection_stop_time, switch_time_t start_time, switch_time_t stop_time, uint8_t resolution, uint8_t offset, uint8_t idx);
+               switch_time_t detection_start_time, switch_time_t detection_stop_time, switch_time_t start_time, switch_time_t stop_time, uint8_t resolution, uint8_t offset, uint8_t idx);
 
 static enum avmd_detection_mode avmd_process_sample(avmd_session_t *s, circ_buffer_t *b, size_t sample_n, size_t pos, struct avmd_detector *d);
 
@@ -286,9 +286,9 @@ static uint8_t
 avmd_detection_in_progress(avmd_session_t *s);
 
 static switch_status_t avmd_launch_threads(avmd_session_t *s) {
-       uint8_t                 idx;
-       struct avmd_detector    *d;
-       switch_threadattr_t     *thd_attr = NULL;
+       uint8_t idx;
+       struct avmd_detector *d;
+       switch_threadattr_t *thd_attr = NULL;
 
        idx = 0;
        while (idx < s->settings.detectors_n) {
@@ -336,226 +336,226 @@ static switch_status_t avmd_launch_threads(avmd_session_t *s) {
 }
 
 static void avmd_join_threads(avmd_session_t *s) {
-    uint8_t                 idx;
-    struct avmd_detector    *d;
-    switch_status_t         status;
-
-    idx = 0;
-    while (idx < s->settings.detectors_n) {
-        d = &s->detectors[idx];
-        switch_mutex_lock(d->mutex);
-        if (d->thread != NULL) {
-            d->flag_should_exit = 1;
-            d->samples = 0;
-            switch_thread_cond_signal(d->cond_start_processing);
-            switch_mutex_unlock(d->mutex);
-            switch_thread_join(&status, d->thread);
-            d->thread = NULL;
-            switch_mutex_destroy(d->mutex);
-            switch_thread_cond_destroy(d->cond_start_processing);
-        } else {
-            switch_mutex_unlock(d->mutex);
-        }
-        ++idx;
-    }
-    idx = 0;
-    while (idx < s->settings.detectors_lagged_n) {
-        d = &s->detectors[s->settings.detectors_n + idx];
-        switch_mutex_lock(d->mutex);
-        if (d->thread != NULL) {
-            d->flag_should_exit = 1;
-            d->samples = 0;
-            switch_thread_cond_signal(d->cond_start_processing);
-            switch_mutex_unlock(d->mutex);
-            switch_thread_join(&status, d->thread);
-            d->thread = NULL;
-            switch_mutex_destroy(d->mutex);
-            switch_thread_cond_destroy(d->cond_start_processing);
-        } else {
-            switch_mutex_unlock(d->mutex);
-        }
-        ++idx;
-    }
+       uint8_t idx;
+       struct avmd_detector *d;
+       switch_status_t status;
+
+       idx = 0;
+       while (idx < s->settings.detectors_n) {
+               d = &s->detectors[idx];
+               switch_mutex_lock(d->mutex);
+               if (d->thread != NULL) {
+                       d->flag_should_exit = 1;
+                       d->samples = 0;
+                       switch_thread_cond_signal(d->cond_start_processing);
+                       switch_mutex_unlock(d->mutex);
+                       switch_thread_join(&status, d->thread);
+                       d->thread = NULL;
+                       switch_mutex_destroy(d->mutex);
+                       switch_thread_cond_destroy(d->cond_start_processing);
+               } else {
+                       switch_mutex_unlock(d->mutex);
+               }
+               ++idx;
+       }
+       idx = 0;
+       while (idx < s->settings.detectors_lagged_n) {
+               d = &s->detectors[s->settings.detectors_n + idx];
+               switch_mutex_lock(d->mutex);
+               if (d->thread != NULL) {
+                       d->flag_should_exit = 1;
+                       d->samples = 0;
+                       switch_thread_cond_signal(d->cond_start_processing);
+                       switch_mutex_unlock(d->mutex);
+                       switch_thread_join(&status, d->thread);
+                       d->thread = NULL;
+                       switch_mutex_destroy(d->mutex);
+                       switch_thread_cond_destroy(d->cond_start_processing);
+               } else {
+                       switch_mutex_unlock(d->mutex);
+               }
+               ++idx;
+       }
 }
 
 static switch_status_t avmd_init_buffer(struct avmd_buffer *b, size_t buf_sz, uint8_t resolution, uint8_t offset, switch_core_session_t *fs_session) {
-    INIT_SMA_BUFFER(&b->sma_b, buf_sz, fs_session);
-    if (b->sma_b.data == NULL) {
-        return SWITCH_STATUS_FALSE;
-    }
-    memset(b->sma_b.data, 0, sizeof(BUFF_TYPE) * buf_sz);
-
-    INIT_SMA_BUFFER(&b->sqa_b, buf_sz, fs_session);
-    if (b->sqa_b.data == NULL) {
-        return SWITCH_STATUS_FALSE;
-    }
-    memset(b->sqa_b.data, 0, sizeof(BUFF_TYPE) * buf_sz);
-
-    INIT_SMA_BUFFER(&b->sma_b_fir, buf_sz, fs_session);
-    if (b->sma_b_fir.data == NULL) {
-        return SWITCH_STATUS_FALSE;
-    }
-    memset(b->sma_b_fir.data, 0, sizeof(BUFF_TYPE) * buf_sz);
-
-    INIT_SMA_BUFFER(&b->sqa_b_fir, buf_sz, fs_session);
-    if (b->sqa_b_fir.data == NULL) {
-        return SWITCH_STATUS_FALSE;
-    }
-    memset(b->sqa_b_fir.data, 0, sizeof(BUFF_TYPE) * buf_sz);
-
-    INIT_SMA_BUFFER(&b->sma_amp_b, buf_sz, fs_session);
-    if (b->sma_amp_b.data == NULL) {
-        return SWITCH_STATUS_FALSE;
-    }
-    memset(b->sma_amp_b.data, 0, sizeof(BUFF_TYPE) * buf_sz);
-
-    INIT_SMA_BUFFER(&b->sqa_amp_b, buf_sz, fs_session);
-    if (b->sqa_amp_b.data == NULL) {
-        return SWITCH_STATUS_FALSE;
-    }
-    memset(b->sqa_amp_b.data, 0, sizeof(BUFF_TYPE) * buf_sz);
-
-    b->amplitude_max = 0.0;
-    b->samples_streak = 0;
-    b->samples_streak_amp = 0;
-    b->resolution = resolution;
-    b->offset = offset;
-
-    return SWITCH_STATUS_SUCCESS;
+       INIT_SMA_BUFFER(&b->sma_b, buf_sz, fs_session);
+       if (b->sma_b.data == NULL) {
+               return SWITCH_STATUS_FALSE;
+       }
+       memset(b->sma_b.data, 0, sizeof(BUFF_TYPE) * buf_sz);
+
+       INIT_SMA_BUFFER(&b->sqa_b, buf_sz, fs_session);
+       if (b->sqa_b.data == NULL) {
+               return SWITCH_STATUS_FALSE;
+       }
+       memset(b->sqa_b.data, 0, sizeof(BUFF_TYPE) * buf_sz);
+
+       INIT_SMA_BUFFER(&b->sma_b_fir, buf_sz, fs_session);
+       if (b->sma_b_fir.data == NULL) {
+               return SWITCH_STATUS_FALSE;
+       }
+       memset(b->sma_b_fir.data, 0, sizeof(BUFF_TYPE) * buf_sz);
+
+       INIT_SMA_BUFFER(&b->sqa_b_fir, buf_sz, fs_session);
+       if (b->sqa_b_fir.data == NULL) {
+               return SWITCH_STATUS_FALSE;
+       }
+       memset(b->sqa_b_fir.data, 0, sizeof(BUFF_TYPE) * buf_sz);
+
+       INIT_SMA_BUFFER(&b->sma_amp_b, buf_sz, fs_session);
+       if (b->sma_amp_b.data == NULL) {
+               return SWITCH_STATUS_FALSE;
+       }
+       memset(b->sma_amp_b.data, 0, sizeof(BUFF_TYPE) * buf_sz);
+
+       INIT_SMA_BUFFER(&b->sqa_amp_b, buf_sz, fs_session);
+       if (b->sqa_amp_b.data == NULL) {
+               return SWITCH_STATUS_FALSE;
+       }
+       memset(b->sqa_amp_b.data, 0, sizeof(BUFF_TYPE) * buf_sz);
+
+       b->amplitude_max = 0.0;
+       b->samples_streak = 0;
+       b->samples_streak_amp = 0;
+       b->resolution = resolution;
+       b->offset = offset;
+
+       return SWITCH_STATUS_SUCCESS;
 }
 
-/*! \brief  The avmd session data initialization function.
- * @param   avmd_session A reference to a avmd session.
- * @param   fs_session A reference to a FreeSWITCH session.
+/*! \brief The avmd session data initialization function.
+ * @param avmd_session A reference to a avmd session.
+ * @param fs_session A reference to a FreeSWITCH session.
  * @details Avmd globals mutex must be locked.
  */
 static switch_status_t init_avmd_session_data(avmd_session_t *avmd_session, switch_core_session_t *fs_session, switch_mutex_t *mutex)
 {
-    uint8_t         idx, resolution, offset;
-    size_t          buf_sz;
-    struct avmd_detector *d;
-    switch_status_t status = SWITCH_STATUS_SUCCESS;
-
-    if (mutex != NULL)
-    {
-        switch_mutex_lock(mutex);
-    }
-
-    /*! This is a worst case sample rate estimate */
-    avmd_session->rate = 48000;
-    INIT_CIRC_BUFFER(&avmd_session->b, (size_t) AVMD_BEEP_LEN(avmd_session->rate), (size_t) AVMD_FRAME_LEN(avmd_session->rate), fs_session);
-    if (avmd_session->b.buf == NULL) {
-        status =  SWITCH_STATUS_MEMERR;
-        goto end;
-    }
-    avmd_session->session = fs_session;
-    avmd_session->pos = 0;
-    avmd_session->f = 0.0;
-    avmd_session->state.last_beep = 0;
-    avmd_session->state.beep_state = BEEP_NOTDETECTED;
-    switch_mutex_init(&avmd_session->mutex, SWITCH_MUTEX_DEFAULT, switch_core_session_get_pool(fs_session));
-    avmd_session->frame_n = 0;
-    avmd_session->detection_start_time = 0;
-    avmd_session->detection_stop_time = 0;
-    avmd_session->frame_n_to_skip = 0;
-
-    buf_sz = AVMD_BEEP_LEN((uint32_t)avmd_session->rate) / (uint32_t) AVMD_SINE_LEN(avmd_session->rate);
-    if (buf_sz < 1) {
-        status = SWITCH_STATUS_MORE_DATA;
-        goto end;
-    }
-    avmd_session->detectors = (struct avmd_detector*) switch_core_session_alloc(fs_session, (avmd_session->settings.detectors_n + avmd_session->settings.detectors_lagged_n) * sizeof(struct avmd_detector));
-    if (avmd_session->detectors == NULL) {
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Can't allocate memory for avmd detectors!\n");
-        status = SWITCH_STATUS_NOT_INITALIZED;
-        goto end;
-    }
-    idx = 0;
-    resolution = 0;
-    while (idx < avmd_session->settings.detectors_n) {
-        ++resolution;
-        offset = 0;
-        while ((offset < resolution) && (idx < avmd_session->settings.detectors_n)) {
-            d = &avmd_session->detectors[idx];
-            if (avmd_init_buffer(&d->buffer, buf_sz, resolution, offset, fs_session) != SWITCH_STATUS_SUCCESS) {
-                status = SWITCH_STATUS_FALSE;
-                goto end;
-            }
-            d->s = avmd_session;
-            d->flag_processing_done = 1;
-            d->flag_should_exit = 1;
-            d->idx = idx;
-            d->thread = NULL;
-            switch_mutex_init(&d->mutex, SWITCH_MUTEX_DEFAULT, switch_core_session_get_pool(fs_session));
-            switch_thread_cond_create(&d->cond_start_processing, switch_core_session_get_pool(fs_session));
-            ++offset;
-            ++idx;
-        }
-    }
-    idx = 0;
-    resolution = 1;
-    offset = 0;
-    while (idx < avmd_session->settings.detectors_lagged_n) {
-            d = &avmd_session->detectors[avmd_session->settings.detectors_n + idx];
-            if (avmd_init_buffer(&d->buffer, buf_sz, resolution, offset, fs_session) != SWITCH_STATUS_SUCCESS) {
-                status = SWITCH_STATUS_FALSE;
-                goto end;
-            }
-            d->s = avmd_session;
-            d->flag_processing_done = 1;
-            d->flag_should_exit = 1;
-            d->idx = avmd_session->settings.detectors_n + idx;
-            d->thread = NULL;
-            switch_mutex_init(&d->mutex, SWITCH_MUTEX_DEFAULT, switch_core_session_get_pool(fs_session));
-            switch_thread_cond_create(&d->cond_start_processing, switch_core_session_get_pool(fs_session));
-            ++idx;
-    }
-    switch_mutex_init(&avmd_session->mutex_detectors_done, SWITCH_MUTEX_DEFAULT, switch_core_session_get_pool(fs_session));
-    switch_thread_cond_create(&avmd_session->cond_detectors_done, switch_core_session_get_pool(fs_session));
+       uint8_t          idx, resolution, offset;
+       size_t            buf_sz;
+       struct avmd_detector *d;
+       switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+       if (mutex != NULL)
+       {
+               switch_mutex_lock(mutex);
+       }
+
+       /*! This is a worst case sample rate estimate */
+       avmd_session->rate = 48000;
+       INIT_CIRC_BUFFER(&avmd_session->b, (size_t) AVMD_BEEP_LEN(avmd_session->rate), (size_t) AVMD_FRAME_LEN(avmd_session->rate), fs_session);
+       if (avmd_session->b.buf == NULL) {
+               status =  SWITCH_STATUS_MEMERR;
+               goto end;
+       }
+       avmd_session->session = fs_session;
+       avmd_session->pos = 0;
+       avmd_session->f = 0.0;
+       avmd_session->state.last_beep = 0;
+       avmd_session->state.beep_state = BEEP_NOTDETECTED;
+       switch_mutex_init(&avmd_session->mutex, SWITCH_MUTEX_DEFAULT, switch_core_session_get_pool(fs_session));
+       avmd_session->frame_n = 0;
+       avmd_session->detection_start_time = 0;
+       avmd_session->detection_stop_time = 0;
+       avmd_session->frame_n_to_skip = 0;
+
+       buf_sz = AVMD_BEEP_LEN((uint32_t)avmd_session->rate) / (uint32_t) AVMD_SINE_LEN(avmd_session->rate);
+       if (buf_sz < 1) {
+               status = SWITCH_STATUS_MORE_DATA;
+               goto end;
+       }
+       avmd_session->detectors = (struct avmd_detector*) switch_core_session_alloc(fs_session, (avmd_session->settings.detectors_n + avmd_session->settings.detectors_lagged_n) * sizeof(struct avmd_detector));
+       if (avmd_session->detectors == NULL) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Can't allocate memory for avmd detectors!\n");
+               status = SWITCH_STATUS_NOT_INITALIZED;
+               goto end;
+       }
+       idx = 0;
+       resolution = 0;
+       while (idx < avmd_session->settings.detectors_n) {
+               ++resolution;
+               offset = 0;
+               while ((offset < resolution) && (idx < avmd_session->settings.detectors_n)) {
+                       d = &avmd_session->detectors[idx];
+                       if (avmd_init_buffer(&d->buffer, buf_sz, resolution, offset, fs_session) != SWITCH_STATUS_SUCCESS) {
+                               status = SWITCH_STATUS_FALSE;
+                               goto end;
+                       }
+                       d->s = avmd_session;
+                       d->flag_processing_done = 1;
+                       d->flag_should_exit = 1;
+                       d->idx = idx;
+                       d->thread = NULL;
+                       switch_mutex_init(&d->mutex, SWITCH_MUTEX_DEFAULT, switch_core_session_get_pool(fs_session));
+                       switch_thread_cond_create(&d->cond_start_processing, switch_core_session_get_pool(fs_session));
+                       ++offset;
+                       ++idx;
+               }
+       }
+       idx = 0;
+       resolution = 1;
+       offset = 0;
+       while (idx < avmd_session->settings.detectors_lagged_n) {
+                       d = &avmd_session->detectors[avmd_session->settings.detectors_n + idx];
+                       if (avmd_init_buffer(&d->buffer, buf_sz, resolution, offset, fs_session) != SWITCH_STATUS_SUCCESS) {
+                               status = SWITCH_STATUS_FALSE;
+                               goto end;
+                       }
+                       d->s = avmd_session;
+                       d->flag_processing_done = 1;
+                       d->flag_should_exit = 1;
+                       d->idx = avmd_session->settings.detectors_n + idx;
+                       d->thread = NULL;
+                       switch_mutex_init(&d->mutex, SWITCH_MUTEX_DEFAULT, switch_core_session_get_pool(fs_session));
+                       switch_thread_cond_create(&d->cond_start_processing, switch_core_session_get_pool(fs_session));
+                       ++idx;
+       }
+       switch_mutex_init(&avmd_session->mutex_detectors_done, SWITCH_MUTEX_DEFAULT, switch_core_session_get_pool(fs_session));
+       switch_thread_cond_create(&avmd_session->cond_detectors_done, switch_core_session_get_pool(fs_session));
 
 end:
-    if (mutex != NULL)
-    {
-        switch_mutex_unlock(mutex);
-    }
-    return status;
+       if (mutex != NULL)
+       {
+               switch_mutex_unlock(mutex);
+       }
+       return status;
 }
 
 static void avmd_session_close(avmd_session_t *s) {
-    uint8_t                 idx;
-    struct avmd_detector    *d;
-    switch_status_t         status;
-
-    switch_mutex_lock(s->mutex);
-
-    switch_mutex_lock(s->mutex_detectors_done);
-    while (avmd_detection_in_progress(s) == 1) {
-        switch_thread_cond_wait(s->cond_detectors_done, s->mutex_detectors_done);
-    }
-    switch_mutex_unlock(s->mutex_detectors_done);
-
-    idx = 0;
-    while (idx < (s->settings.detectors_n + s->settings.detectors_lagged_n)) {
-        d = &s->detectors[idx];
-        switch_mutex_lock(d->mutex);
-        d = &s->detectors[idx];
-        d->flag_processing_done = 0;
-        d->flag_should_exit = 1;
-        d->samples = 0;
-        switch_thread_cond_signal(d->cond_start_processing);
-        switch_mutex_unlock(d->mutex);
-
-        switch_thread_join(&status, d->thread);
-        d->thread = NULL;
-
-        switch_mutex_destroy(d->mutex);
-        switch_thread_cond_destroy(d->cond_start_processing);
-        ++idx;
-    }
-    switch_mutex_unlock(s->mutex);
-    switch_mutex_destroy(s->mutex_detectors_done);
-    switch_thread_cond_destroy(s->cond_detectors_done);
-    switch_mutex_destroy(s->mutex);
+       uint8_t                          idx;
+       struct avmd_detector    *d;
+       switch_status_t          status;
+
+       switch_mutex_lock(s->mutex);
+
+       switch_mutex_lock(s->mutex_detectors_done);
+       while (avmd_detection_in_progress(s) == 1) {
+               switch_thread_cond_wait(s->cond_detectors_done, s->mutex_detectors_done);
+       }
+       switch_mutex_unlock(s->mutex_detectors_done);
+
+       idx = 0;
+       while (idx < (s->settings.detectors_n + s->settings.detectors_lagged_n)) {
+               d = &s->detectors[idx];
+               switch_mutex_lock(d->mutex);
+               d = &s->detectors[idx];
+               d->flag_processing_done = 0;
+               d->flag_should_exit = 1;
+               d->samples = 0;
+               switch_thread_cond_signal(d->cond_start_processing);
+               switch_mutex_unlock(d->mutex);
+
+               switch_thread_join(&status, d->thread);
+               d->thread = NULL;
+
+               switch_mutex_destroy(d->mutex);
+               switch_thread_cond_destroy(d->cond_start_processing);
+               ++idx;
+       }
+       switch_mutex_unlock(s->mutex);
+       switch_mutex_destroy(s->mutex_detectors_done);
+       switch_thread_cond_destroy(s->cond_detectors_done);
+       switch_mutex_destroy(s->mutex);
 }
 
 /*! \brief The callback function that is called when new audio data becomes available.
@@ -565,321 +565,321 @@ static void avmd_session_close(avmd_session_t *s) {
  * @return The success or failure of the function.
  */
 static switch_bool_t avmd_callback(switch_media_bug_t * bug, void *user_data, switch_abc_type_t type) {
-    avmd_session_t          *avmd_session;
-    switch_codec_t          *read_codec;
-    switch_codec_t          *write_codec;
-    switch_frame_t          *frame;
-    switch_core_session_t   *fs_session;
-    switch_channel_t        *channel = NULL;
-
-
-    avmd_session = (avmd_session_t *) user_data;
-    if (avmd_session == NULL) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No avmd session assigned!\n");
-        return SWITCH_FALSE;
-    }
-    if ((type != SWITCH_ABC_TYPE_INIT) && (type != SWITCH_ABC_TYPE_CLOSE)) {
-        switch_mutex_lock(avmd_session->mutex);
-    }
-    fs_session = avmd_session->session;
-    if (fs_session == NULL) {
-        if (type != SWITCH_ABC_TYPE_INIT) {
-            switch_mutex_unlock(avmd_session->mutex);
-        }
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No FreeSWITCH session assigned!\n");
-        return SWITCH_FALSE;
-    }
-
-    channel = switch_core_session_get_channel(fs_session);
-    if (channel == NULL) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channel for FreeSWITCH session!\n");
-        return SWITCH_FALSE;
-    }
-
-    switch (type) {
-
-        case SWITCH_ABC_TYPE_INIT:
-            if ((SWITCH_CALL_DIRECTION_OUTBOUND == switch_channel_direction(channel)) && (avmd_session->settings.outbound_channnel == 1)) {
-                read_codec = switch_core_session_get_read_codec(fs_session);
-                if (read_codec == NULL) {
-                    switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_WARNING, "No read codec assigned, default session rate to 8000 samples/s\n");
-                    avmd_session->rate = 8000;
-                } else {
-                    if (read_codec->implementation == NULL) {
-                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_WARNING, "No read codec implementation assigned, default session rate to 8000 samples/s\n");
-                        avmd_session->rate = 8000;
-                    } else {
-                        avmd_session->rate = read_codec->implementation->samples_per_second;
-                    }
-                }
-            }
-            if ((SWITCH_CALL_DIRECTION_INBOUND == switch_channel_direction(channel)) && (avmd_session->settings.inbound_channnel == 1)) {
-                write_codec = switch_core_session_get_write_codec(fs_session);
-                if (write_codec == NULL) {
-                    switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_WARNING, "No write codec assigned, default session rate to 8000 samples/s\n");
-                    avmd_session->rate = 8000;
-                } else {
-                    if (write_codec->implementation == NULL) {
-                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_WARNING, "No write codec implementation assigned, default session rate to 8000 samples/s\n");
-                        avmd_session->rate = 8000;
-                    } else {
-                        avmd_session->rate = write_codec->implementation->samples_per_second;
-                    }
-                }
-            }
-            avmd_session->start_time = switch_micro_time_now();
-            /* avmd_session->vmd_codec.channels =  read_codec->implementation->number_of_channels; */
-            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session),SWITCH_LOG_INFO, "Avmd session initialized, [%u] samples/s\n", avmd_session->rate);
-            break;
-
-        case SWITCH_ABC_TYPE_READ_REPLACE:
-            frame = switch_core_media_bug_get_read_replace_frame(bug);
-            avmd_process(avmd_session, frame, AVMD_READ_REPLACE);
-            break;
-
-        case SWITCH_ABC_TYPE_WRITE_REPLACE:
-            frame = switch_core_media_bug_get_write_replace_frame(bug);
-            avmd_process(avmd_session, frame, AVMD_WRITE_REPLACE);
-            break;
-
-        case SWITCH_ABC_TYPE_CLOSE:
-            avmd_session_close(avmd_session);
+       avmd_session_t *avmd_session;
+       switch_codec_t *read_codec;
+       switch_codec_t *write_codec;
+       switch_frame_t *frame;
+       switch_core_session_t *fs_session;
+       switch_channel_t *channel = NULL;
+
+
+       avmd_session = (avmd_session_t *) user_data;
+       if (avmd_session == NULL) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No avmd session assigned!\n");
+               return SWITCH_FALSE;
+       }
+       if ((type != SWITCH_ABC_TYPE_INIT) && (type != SWITCH_ABC_TYPE_CLOSE)) {
+               switch_mutex_lock(avmd_session->mutex);
+       }
+       fs_session = avmd_session->session;
+       if (fs_session == NULL) {
+               if (type != SWITCH_ABC_TYPE_INIT) {
+                       switch_mutex_unlock(avmd_session->mutex);
+               }
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No FreeSWITCH session assigned!\n");
+               return SWITCH_FALSE;
+       }
+
+       channel = switch_core_session_get_channel(fs_session);
+       if (channel == NULL) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channel for FreeSWITCH session!\n");
+               return SWITCH_FALSE;
+       }
+
+       switch (type) {
+
+               case SWITCH_ABC_TYPE_INIT:
+                       if ((SWITCH_CALL_DIRECTION_OUTBOUND == switch_channel_direction(channel)) && (avmd_session->settings.outbound_channnel == 1)) {
+                               read_codec = switch_core_session_get_read_codec(fs_session);
+                               if (read_codec == NULL) {
+                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_WARNING, "No read codec assigned, default session rate to 8000 samples/s\n");
+                                       avmd_session->rate = 8000;
+                               } else {
+                                       if (read_codec->implementation == NULL) {
+                                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_WARNING, "No read codec implementation assigned, default session rate to 8000 samples/s\n");
+                                               avmd_session->rate = 8000;
+                                       } else {
+                                               avmd_session->rate = read_codec->implementation->samples_per_second;
+                                       }
+                               }
+                       }
+                       if ((SWITCH_CALL_DIRECTION_INBOUND == switch_channel_direction(channel)) && (avmd_session->settings.inbound_channnel == 1)) {
+                               write_codec = switch_core_session_get_write_codec(fs_session);
+                               if (write_codec == NULL) {
+                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_WARNING, "No write codec assigned, default session rate to 8000 samples/s\n");
+                                       avmd_session->rate = 8000;
+                               } else {
+                                       if (write_codec->implementation == NULL) {
+                                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_WARNING, "No write codec implementation assigned, default session rate to 8000 samples/s\n");
+                                               avmd_session->rate = 8000;
+                                       } else {
+                                               avmd_session->rate = write_codec->implementation->samples_per_second;
+                                       }
+                               }
+                       }
+                       avmd_session->start_time = switch_micro_time_now();
+                       /* avmd_session->vmd_codec.channels =  read_codec->implementation->number_of_channels; */
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session),SWITCH_LOG_INFO, "Avmd session initialized, [%u] samples/s\n", avmd_session->rate);
+                       break;
+
+               case SWITCH_ABC_TYPE_READ_REPLACE:
+                       frame = switch_core_media_bug_get_read_replace_frame(bug);
+                       avmd_process(avmd_session, frame, AVMD_READ_REPLACE);
+                       break;
+
+               case SWITCH_ABC_TYPE_WRITE_REPLACE:
+                       frame = switch_core_media_bug_get_write_replace_frame(bug);
+                       avmd_process(avmd_session, frame, AVMD_WRITE_REPLACE);
+                       break;
+
+               case SWITCH_ABC_TYPE_CLOSE:
+                       avmd_session_close(avmd_session);
                        switch_mutex_lock(avmd_globals.mutex);
-            if (avmd_globals.session_n > 0) {
-                --avmd_globals.session_n;
-            }
+                       if (avmd_globals.session_n > 0) {
+                               --avmd_globals.session_n;
+                       }
                        switch_mutex_unlock(avmd_globals.mutex);
-            break;
+                       break;
 
-        default:
-            break;
-    }
+               default:
+                       break;
+       }
 
-    if ((type != SWITCH_ABC_TYPE_INIT) && (type != SWITCH_ABC_TYPE_CLOSE)) {
-        switch_mutex_unlock(avmd_session->mutex);
-    }
-    return SWITCH_TRUE;
+       if ((type != SWITCH_ABC_TYPE_INIT) && (type != SWITCH_ABC_TYPE_CLOSE)) {
+               switch_mutex_unlock(avmd_session->mutex);
+       }
+       return SWITCH_TRUE;
 }
 
 static switch_status_t avmd_register_all_events(void) {
-    size_t idx = 0;
-    const char *e = avmd_events_str[0];
-    while (e != NULL)
-    {
-        if (switch_event_reserve_subclass(e) != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass [%s]!\n", e);
-            return SWITCH_STATUS_TERM;
-        }
-        ++idx;
-        e = avmd_events_str[idx];
-    }
-    return SWITCH_STATUS_SUCCESS;
+       size_t idx = 0;
+       const char *e = avmd_events_str[0];
+       while (e != NULL)
+       {
+               if (switch_event_reserve_subclass(e) != SWITCH_STATUS_SUCCESS) {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass [%s]!\n", e);
+                       return SWITCH_STATUS_TERM;
+               }
+               ++idx;
+               e = avmd_events_str[idx];
+       }
+       return SWITCH_STATUS_SUCCESS;
 }
 
 static void avmd_unregister_all_events(void) {
-    size_t idx = 0;
-    const char *e = avmd_events_str[0];
-    while (e != NULL)
-    {
-        switch_event_free_subclass(e);
-        ++idx;
-        e = avmd_events_str[idx];
-    }
-    return;
+       size_t idx = 0;
+       const char *e = avmd_events_str[0];
+       while (e != NULL)
+       {
+               switch_event_free_subclass(e);
+               ++idx;
+               e = avmd_events_str[idx];
+       }
+       return;
 }
 
 static void avmd_fire_event(enum avmd_event type, switch_core_session_t *fs_s, double freq, double v_freq, double amp, double v_amp, avmd_beep_state_t beep_status, uint8_t info,
-        switch_time_t detection_start_time, switch_time_t detection_stop_time, switch_time_t start_time, switch_time_t stop_time, uint8_t resolution, uint8_t offset, uint8_t idx) {
-    int res;
-    switch_event_t      *event;
-    switch_time_t       detection_time, total_time;
-    switch_status_t     status;
-    switch_event_t      *event_copy;
-    char                buf[AVMD_CHAR_BUF_LEN];
-
-    status = switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, avmd_events_str[type]);
-    if (status != SWITCH_STATUS_SUCCESS) {
-        return;
-    }
-    switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(fs_s));
-    switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Call-command", "avmd");
-    switch (type)
-    {
-        case AVMD_EVENT_BEEP:
-            switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Beep-Status", "DETECTED");
-            res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%f", freq);
-            if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Frequency truncated [%s], [%d] attempted!\n", buf, res);
-                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Frequency", "ERROR (TRUNCATED)");
-            }
-            switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Frequency", buf);
-
-            res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%f", v_freq);
-            if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Error, truncated [%s], [%d] attempeted!\n", buf, res);
-                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Frequency-variance", "ERROR (TRUNCATED)");
-            }
-            switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Frequency-variance", buf);
-
-            res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%f", amp);
-            if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Amplitude truncated [%s], [%d] attempted!\n", buf, res);
-                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Amplitude", "ERROR (TRUNCATED)");
-            }
-            switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Amplitude", buf);
-
-            res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%f", v_amp);
-            if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Error, truncated [%s], [%d] attempeted!\n", buf, res);
-                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Amplitude-variance", "ERROR (TRUNCATED)");
-            }
-            switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Amplitude-variance", buf);
-
-            detection_time = detection_stop_time - detection_start_time;
-            res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%" PRId64 "", detection_time);
-            if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Detection time truncated [%s], [%d] attempted!\n", buf, res);
-                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detection-time", "ERROR (TRUNCATED)");
-            }
-            switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detection-time", buf);
-
-            res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%u", resolution);
-            if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Error, truncated [%s], [%d] attempeted!\n", buf, res);
-                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detector-resolution", "ERROR (TRUNCATED)");
-            }
-            switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detector-resolution", buf);
-
-            res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%u", offset);
-            if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Error, truncated [%s], [%d] attempeted!\n", buf, res);
-                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detector-offset", "ERROR (TRUNCATED)");
-            }
-            switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detector-offset", buf);
-
-            res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%u", idx);
-            if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Error, truncated [%s], [%d] attempeted!\n", buf, res);
-                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detector-index", "ERROR (TRUNCATED)");
-            }
-            switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detector-index", buf);
-            break;
-
-        case AVMD_EVENT_SESSION_START:
-            res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%" PRId64 "", start_time);
-            if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Start time truncated [%s], [%d] attempted!\n", buf, res);
-                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Start-time", "ERROR (TRUNCATED)");
-            }
-            switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Start-time", buf);
-            break;
-
-        case AVMD_EVENT_SESSION_STOP:
-            switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Beep-Status", beep_status == BEEP_DETECTED ? "DETECTED" : "NOTDETECTED");
-            if (info == 0) {
-                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Stop-status", "ERROR (AVMD SESSION OBJECT NOT FOUND IN MEDIA BUG)");
-            }
-            total_time = stop_time - start_time;
-            res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%" PRId64 "", total_time);
-            if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Total time truncated [%s], [%d] attempted!\n", buf, res);
-                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Total-time", "ERROR (TRUNCATED)");
-            }
-            switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Total-time", buf);
-            break;
-
-        default:
-            switch_event_destroy(&event);
-            return;
-    }
-
-    if ((switch_event_dup(&event_copy, event)) != SWITCH_STATUS_SUCCESS) {
-        return;
-    }
-
-    switch_core_session_queue_event(fs_s, &event);
-    switch_event_fire(&event_copy);
-    return;
+               switch_time_t detection_start_time, switch_time_t detection_stop_time, switch_time_t start_time, switch_time_t stop_time, uint8_t resolution, uint8_t offset, uint8_t idx) {
+       int res;
+       switch_event_t *event;
+       switch_time_t detection_time, total_time;
+       switch_status_t status;
+       switch_event_t *event_copy;
+       char buf[AVMD_CHAR_BUF_LEN];
+
+       status = switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, avmd_events_str[type]);
+       if (status != SWITCH_STATUS_SUCCESS) {
+               return;
+       }
+       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(fs_s));
+       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Call-command", "avmd");
+       switch (type)
+       {
+               case AVMD_EVENT_BEEP:
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Beep-Status", "DETECTED");
+                       res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%f", freq);
+                       if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Frequency truncated [%s], [%d] attempted!\n", buf, res);
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Frequency", "ERROR (TRUNCATED)");
+                       }
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Frequency", buf);
+
+                       res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%f", v_freq);
+                       if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Error, truncated [%s], [%d] attempeted!\n", buf, res);
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Frequency-variance", "ERROR (TRUNCATED)");
+                       }
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Frequency-variance", buf);
+
+                       res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%f", amp);
+                       if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Amplitude truncated [%s], [%d] attempted!\n", buf, res);
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Amplitude", "ERROR (TRUNCATED)");
+                       }
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Amplitude", buf);
+
+                       res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%f", v_amp);
+                       if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Error, truncated [%s], [%d] attempeted!\n", buf, res);
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Amplitude-variance", "ERROR (TRUNCATED)");
+                       }
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Amplitude-variance", buf);
+
+                       detection_time = detection_stop_time - detection_start_time;
+                       res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%" PRId64 "", detection_time);
+                       if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Detection time truncated [%s], [%d] attempted!\n", buf, res);
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detection-time", "ERROR (TRUNCATED)");
+                       }
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detection-time", buf);
+
+                       res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%u", resolution);
+                       if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Error, truncated [%s], [%d] attempeted!\n", buf, res);
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detector-resolution", "ERROR (TRUNCATED)");
+                       }
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detector-resolution", buf);
+
+                       res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%u", offset);
+                       if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Error, truncated [%s], [%d] attempeted!\n", buf, res);
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detector-offset", "ERROR (TRUNCATED)");
+                       }
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detector-offset", buf);
+
+                       res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%u", idx);
+                       if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Error, truncated [%s], [%d] attempeted!\n", buf, res);
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detector-index", "ERROR (TRUNCATED)");
+                       }
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detector-index", buf);
+                       break;
+
+               case AVMD_EVENT_SESSION_START:
+                       res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%" PRId64 "", start_time);
+                       if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Start time truncated [%s], [%d] attempted!\n", buf, res);
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Start-time", "ERROR (TRUNCATED)");
+                       }
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Start-time", buf);
+                       break;
+
+               case AVMD_EVENT_SESSION_STOP:
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Beep-Status", beep_status == BEEP_DETECTED ? "DETECTED" : "NOTDETECTED");
+                       if (info == 0) {
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Stop-status", "ERROR (AVMD SESSION OBJECT NOT FOUND IN MEDIA BUG)");
+                       }
+                       total_time = stop_time - start_time;
+                       res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%" PRId64 "", total_time);
+                       if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_s), SWITCH_LOG_ERROR, "Total time truncated [%s], [%d] attempted!\n", buf, res);
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Total-time", "ERROR (TRUNCATED)");
+                       }
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Total-time", buf);
+                       break;
+
+               default:
+                       switch_event_destroy(&event);
+                       return;
+       }
+
+       if ((switch_event_dup(&event_copy, event)) != SWITCH_STATUS_SUCCESS) {
+               return;
+       }
+
+       switch_core_session_queue_event(fs_s, &event);
+       switch_event_fire(&event_copy);
+       return;
 }
 
 int avmd_parse_u8_user_input(const char *input, uint8_t *output, uint8_t min, uint8_t max) {
-    char            *pCh;
-    unsigned long   helper;
-    helper = strtoul(input, &pCh, 10);
-    if (helper < min || helper > UINT8_MAX || helper > max || (pCh == input) || (*pCh != '\0')) {
-        return -1;
-    }
-    *output = (uint8_t) helper;
-    return 0;
+       char *pCh;
+       unsigned long helper;
+       helper = strtoul(input, &pCh, 10);
+       if (helper < min || helper > UINT8_MAX || helper > max || (pCh == input) || (*pCh != '\0')) {
+               return -1;
+       }
+       *output = (uint8_t) helper;
+       return 0;
 }
 
 int avmd_parse_u16_user_input(const char *input, uint16_t *output, uint16_t min, uint16_t max) {
-    char            *pCh;
-    unsigned long   helper;
-    if (min > max) {
-        return -1;
-    }
-    helper = strtoul(input, &pCh, 10);
-    if (helper < min || helper > UINT16_MAX || helper > max || (pCh == input) || (*pCh != '\0')) {
-        return -1;
-    }
-    *output = (uint16_t) helper;
-    return 0;
+       char *pCh;
+       unsigned long helper;
+       if (min > max) {
+               return -1;
+       }
+       helper = strtoul(input, &pCh, 10);
+       if (helper < min || helper > UINT16_MAX || helper > max || (pCh == input) || (*pCh != '\0')) {
+               return -1;
+       }
+       *output = (uint16_t) helper;
+       return 0;
 }
 
 static void avmd_set_xml_default_configuration(switch_mutex_t *mutex) {
-    if (mutex != NULL) {
-        switch_mutex_lock(mutex);
-    }
-
-    avmd_globals.settings.debug = 0;
-    avmd_globals.settings.report_status = 1;
-    avmd_globals.settings.fast_math = 0;
-    avmd_globals.settings.require_continuous_streak = 1;
-    avmd_globals.settings.sample_n_continuous_streak = 3;
-    avmd_globals.settings.sample_n_to_skip = 0;
-    avmd_globals.settings.require_continuous_streak_amp = 1;
-    avmd_globals.settings.sample_n_continuous_streak_amp = 3;
-    avmd_globals.settings.simplified_estimation = 1;
-    avmd_globals.settings.inbound_channnel = 0;
-    avmd_globals.settings.outbound_channnel = 1;
-    avmd_globals.settings.mode = AVMD_DETECT_BOTH;
-    avmd_globals.settings.detectors_n = 36;
-    avmd_globals.settings.detectors_lagged_n = 1;
-
-    if (mutex != NULL) {
-        switch_mutex_unlock(avmd_globals.mutex);
-    }
-    return;
+       if (mutex != NULL) {
+               switch_mutex_lock(mutex);
+       }
+
+       avmd_globals.settings.debug = 0;
+       avmd_globals.settings.report_status = 1;
+       avmd_globals.settings.fast_math = 0;
+       avmd_globals.settings.require_continuous_streak = 1;
+       avmd_globals.settings.sample_n_continuous_streak = 3;
+       avmd_globals.settings.sample_n_to_skip = 0;
+       avmd_globals.settings.require_continuous_streak_amp = 1;
+       avmd_globals.settings.sample_n_continuous_streak_amp = 3;
+       avmd_globals.settings.simplified_estimation = 1;
+       avmd_globals.settings.inbound_channnel = 0;
+       avmd_globals.settings.outbound_channnel = 1;
+       avmd_globals.settings.mode = AVMD_DETECT_BOTH;
+       avmd_globals.settings.detectors_n = 36;
+       avmd_globals.settings.detectors_lagged_n = 1;
+
+       if (mutex != NULL) {
+               switch_mutex_unlock(avmd_globals.mutex);
+       }
+       return;
 }
 
 static void avmd_set_xml_inbound_configuration(switch_mutex_t *mutex)
 {
-    if (mutex != NULL) {
-        switch_mutex_lock(mutex);
-    }
+       if (mutex != NULL) {
+               switch_mutex_lock(mutex);
+       }
 
-    avmd_globals.settings.inbound_channnel = 1;
-    avmd_globals.settings.outbound_channnel = 0;
+       avmd_globals.settings.inbound_channnel = 1;
+       avmd_globals.settings.outbound_channnel = 0;
 
-    if (mutex != NULL) {
-        switch_mutex_unlock(avmd_globals.mutex);
-    }
-    return;
+       if (mutex != NULL) {
+               switch_mutex_unlock(avmd_globals.mutex);
+       }
+       return;
 }
 
 static void avmd_set_xml_outbound_configuration(switch_mutex_t *mutex) {
-    if (mutex != NULL) {
-        switch_mutex_lock(mutex);
-    }
+       if (mutex != NULL) {
+               switch_mutex_lock(mutex);
+       }
 
-    avmd_globals.settings.inbound_channnel = 0;
-    avmd_globals.settings.outbound_channnel = 1;
+       avmd_globals.settings.inbound_channnel = 0;
+       avmd_globals.settings.outbound_channnel = 1;
 
-    if (mutex != NULL) {
-        switch_mutex_unlock(avmd_globals.mutex);
-    }
-    return;
+       if (mutex != NULL) {
+               switch_mutex_unlock(avmd_globals.mutex);
+       }
+       return;
 }
 
 static switch_status_t avmd_load_xml_configuration(switch_mutex_t *mutex) {
@@ -1060,249 +1060,249 @@ static switch_status_t avmd_load_xml_configuration(switch_mutex_t *mutex) {
 }
 
 static switch_status_t avmd_load_xml_inbound_configuration(switch_mutex_t *mutex) {
-    if (avmd_load_xml_configuration(mutex) != SWITCH_STATUS_SUCCESS) {
-        return SWITCH_STATUS_TERM;
-    }
+       if (avmd_load_xml_configuration(mutex) != SWITCH_STATUS_SUCCESS) {
+               return SWITCH_STATUS_TERM;
+       }
 
-    if (mutex != NULL) {
-        switch_mutex_lock(mutex);
-    }
+       if (mutex != NULL) {
+               switch_mutex_lock(mutex);
+       }
 
-    avmd_globals.settings.inbound_channnel = 1;
-    avmd_globals.settings.outbound_channnel = 0;
+       avmd_globals.settings.inbound_channnel = 1;
+       avmd_globals.settings.outbound_channnel = 0;
 
-    if (mutex != NULL) {
-        switch_mutex_unlock(avmd_globals.mutex);
-    }
-    return SWITCH_STATUS_SUCCESS;
+       if (mutex != NULL) {
+               switch_mutex_unlock(avmd_globals.mutex);
+       }
+       return SWITCH_STATUS_SUCCESS;
 }
 
 static switch_status_t avmd_load_xml_outbound_configuration(switch_mutex_t *mutex) {
-    if (avmd_load_xml_configuration(mutex) != SWITCH_STATUS_SUCCESS) {
-        return SWITCH_STATUS_TERM;
-    }
+       if (avmd_load_xml_configuration(mutex) != SWITCH_STATUS_SUCCESS) {
+               return SWITCH_STATUS_TERM;
+       }
 
-    if (mutex != NULL) {
-        switch_mutex_lock(mutex);
-    }
+       if (mutex != NULL) {
+               switch_mutex_lock(mutex);
+       }
 
-    avmd_globals.settings.inbound_channnel = 0;
-    avmd_globals.settings.outbound_channnel = 1;
+       avmd_globals.settings.inbound_channnel = 0;
+       avmd_globals.settings.outbound_channnel = 1;
 
-    if (mutex != NULL) {
-        switch_mutex_unlock(avmd_globals.mutex);
-    }
-    return SWITCH_STATUS_SUCCESS;
+       if (mutex != NULL) {
+               switch_mutex_unlock(avmd_globals.mutex);
+       }
+       return SWITCH_STATUS_SUCCESS;
 }
 
 static void avmd_show(switch_stream_handle_t *stream, switch_mutex_t *mutex) {
-    const char *line = "=================================================================================================";
-    if (stream == NULL) {
-        return;
-    }
-
-    if (mutex != NULL) {
-        switch_mutex_lock(mutex);
-    }
-
-    stream->write_function(stream, "\n\n");
-    stream->write_function(stream, "%s\n\n", line);
-    stream->write_function(stream, "%s\n", "Avmd global settings\n\n");
-    stream->write_function(stream, "debug                          \t%u\n", avmd_globals.settings.debug);
-    stream->write_function(stream, "report status                  \t%u\n", avmd_globals.settings.report_status);
-    stream->write_function(stream, "fast_math                      \t%u\n", avmd_globals.settings.fast_math);
-    stream->write_function(stream, "require continuous streak      \t%u\n", avmd_globals.settings.require_continuous_streak);
-    stream->write_function(stream, "sample n continuous streak     \t%u\n", avmd_globals.settings.sample_n_continuous_streak);
-    stream->write_function(stream, "sample n to skip               \t%u\n", avmd_globals.settings.sample_n_to_skip);
-    stream->write_function(stream, "require continuous streak amp  \t%u\n", avmd_globals.settings.require_continuous_streak_amp);
-    stream->write_function(stream, "sample n continuous streak amp \t%u\n", avmd_globals.settings.sample_n_continuous_streak_amp);
-    stream->write_function(stream, "simplified estimation          \t%u\n", avmd_globals.settings.simplified_estimation);
-    stream->write_function(stream, "inbound channel                \t%u\n", avmd_globals.settings.inbound_channnel);
-    stream->write_function(stream, "outbound channel               \t%u\n", avmd_globals.settings.outbound_channnel);
-    stream->write_function(stream, "detection mode                 \t%u\n", avmd_globals.settings.mode);
-    stream->write_function(stream, "sessions                       \t%"PRId64"\n", avmd_globals.session_n);
-    stream->write_function(stream, "detectors n                    \t%u\n", avmd_globals.settings.detectors_n);
-    stream->write_function(stream, "detectors lagged n             \t%u\n", avmd_globals.settings.detectors_lagged_n);
-    stream->write_function(stream, "\n\n");
-
-    if (mutex != NULL) {
-        switch_mutex_unlock(mutex);
-    }
+       const char *line = "=================================================================================================";
+       if (stream == NULL) {
+               return;
+       }
+
+       if (mutex != NULL) {
+               switch_mutex_lock(mutex);
+       }
+
+       stream->write_function(stream, "\n\n");
+       stream->write_function(stream, "%s\n\n", line);
+       stream->write_function(stream, "%s\n", "Avmd global settings\n\n");
+       stream->write_function(stream, "debug                                             \t%u\n", avmd_globals.settings.debug);
+       stream->write_function(stream, "report status                             \t%u\n", avmd_globals.settings.report_status);
+       stream->write_function(stream, "fast_math                                         \t%u\n", avmd_globals.settings.fast_math);
+       stream->write_function(stream, "require continuous streak         \t%u\n", avmd_globals.settings.require_continuous_streak);
+       stream->write_function(stream, "sample n continuous streak       \t%u\n", avmd_globals.settings.sample_n_continuous_streak);
+       stream->write_function(stream, "sample n to skip                           \t%u\n", avmd_globals.settings.sample_n_to_skip);
+       stream->write_function(stream, "require continuous streak amp  \t%u\n", avmd_globals.settings.require_continuous_streak_amp);
+       stream->write_function(stream, "sample n continuous streak amp \t%u\n", avmd_globals.settings.sample_n_continuous_streak_amp);
+       stream->write_function(stream, "simplified estimation             \t%u\n", avmd_globals.settings.simplified_estimation);
+       stream->write_function(stream, "inbound channel                         \t%u\n", avmd_globals.settings.inbound_channnel);
+       stream->write_function(stream, "outbound channel                           \t%u\n", avmd_globals.settings.outbound_channnel);
+       stream->write_function(stream, "detection mode                           \t%u\n", avmd_globals.settings.mode);
+       stream->write_function(stream, "sessions                                           \t%"PRId64"\n", avmd_globals.session_n);
+       stream->write_function(stream, "detectors n                                     \t%u\n", avmd_globals.settings.detectors_n);
+       stream->write_function(stream, "detectors lagged n                       \t%u\n", avmd_globals.settings.detectors_lagged_n);
+       stream->write_function(stream, "\n\n");
+
+       if (mutex != NULL) {
+               switch_mutex_unlock(mutex);
+       }
 }
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_avmd_load) {
 #ifndef WIN32
-    char    err[150];
-    int     ret;
+       char    err[150];
+       int      ret;
 #endif
 
-    switch_application_interface_t *app_interface;
-    switch_api_interface_t *api_interface;
-    /* connect my internal structure to the blank pointer passed to me */
-    *module_interface = switch_loadable_module_create_module_interface(pool, modname);
-
-    if (avmd_register_all_events() != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register avmd events!\n");
-        return SWITCH_STATUS_TERM;
-    }
-
-    memset(&avmd_globals, 0, sizeof(avmd_globals));
-    if (pool == NULL) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No memory pool assigned!\n");
-        return SWITCH_STATUS_TERM;
-    }
-    switch_mutex_init(&avmd_globals.mutex, SWITCH_MUTEX_NESTED, pool);
-    avmd_globals.pool = pool;
-
-    if (avmd_load_xml_configuration(NULL) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't load XML configuration! Loading default settings\n");
-        avmd_set_xml_default_configuration(NULL);
-    }
-
-    if ((switch_event_bind(modname, SWITCH_EVENT_RELOADXML, NULL, avmd_reloadxml_event_handler, NULL) != SWITCH_STATUS_SUCCESS)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind our reloadxml handler! Module will not react to changes made in XML configuration\n");
-        /* Not so severe to prevent further loading, well - it depends, anyway */
-    }
+       switch_application_interface_t *app_interface;
+       switch_api_interface_t *api_interface;
+       /* connect my internal structure to the blank pointer passed to me */
+       *module_interface = switch_loadable_module_create_module_interface(pool, modname);
+
+       if (avmd_register_all_events() != SWITCH_STATUS_SUCCESS) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register avmd events!\n");
+               return SWITCH_STATUS_TERM;
+       }
+
+       memset(&avmd_globals, 0, sizeof(avmd_globals));
+       if (pool == NULL) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No memory pool assigned!\n");
+               return SWITCH_STATUS_TERM;
+       }
+       switch_mutex_init(&avmd_globals.mutex, SWITCH_MUTEX_NESTED, pool);
+       avmd_globals.pool = pool;
+
+       if (avmd_load_xml_configuration(NULL) != SWITCH_STATUS_SUCCESS) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't load XML configuration! Loading default settings\n");
+               avmd_set_xml_default_configuration(NULL);
+       }
+
+       if ((switch_event_bind(modname, SWITCH_EVENT_RELOADXML, NULL, avmd_reloadxml_event_handler, NULL) != SWITCH_STATUS_SUCCESS)) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind our reloadxml handler! Module will not react to changes made in XML configuration\n");
+               /* Not so severe to prevent further loading, well - it depends, anyway */
+       }
 
 #ifndef WIN32
-    if (avmd_globals.settings.fast_math == 1) {
-        ret = init_fast_acosf();
-        if (ret != 0) {
-            strerror_r(errno, err, 150);
-            switch (ret) {
-
-                case -1:
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't access file [%s], error [%s]\n", ACOS_TABLE_FILENAME, err);
-                    break;
-                case -2:
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating file [%s], error [%s]\n", ACOS_TABLE_FILENAME, err);
-                    break;
-                case -3:
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Access rights are OK but can't open file [%s], error [%s]\n", ACOS_TABLE_FILENAME, err);
-                    break;
-                case -4:
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Access rights are OK but can't mmap file [%s], error [%s]\n",ACOS_TABLE_FILENAME, err);
-                    break;
-                default:
-                    switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Unknown error [%d] while initializing fast cos table [%s], errno [%s]\n", ret, ACOS_TABLE_FILENAME, err);
-                    return SWITCH_STATUS_TERM;
-            }
-            return SWITCH_STATUS_TERM;
-        } else
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Advanced voicemail detection: fast math enabled, arc cosine table is [%s]\n", ACOS_TABLE_FILENAME);
-    }
+       if (avmd_globals.settings.fast_math == 1) {
+               ret = init_fast_acosf();
+               if (ret != 0) {
+                       strerror_r(errno, err, 150);
+                       switch (ret) {
+
+                               case -1:
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't access file [%s], error [%s]\n", ACOS_TABLE_FILENAME, err);
+                                       break;
+                               case -2:
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating file [%s], error [%s]\n", ACOS_TABLE_FILENAME, err);
+                                       break;
+                               case -3:
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Access rights are OK but can't open file [%s], error [%s]\n", ACOS_TABLE_FILENAME, err);
+                                       break;
+                               case -4:
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Access rights are OK but can't mmap file [%s], error [%s]\n",ACOS_TABLE_FILENAME, err);
+                                       break;
+                               default:
+                                       switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Unknown error [%d] while initializing fast cos table [%s], errno [%s]\n", ret, ACOS_TABLE_FILENAME, err);
+                                       return SWITCH_STATUS_TERM;
+                       }
+                       return SWITCH_STATUS_TERM;
+               } else
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Advanced voicemail detection: fast math enabled, arc cosine table is [%s]\n", ACOS_TABLE_FILENAME);
+       }
 #endif
 
-    SWITCH_ADD_APP(app_interface, "avmd_start","Start avmd detection", "Start avmd detection", avmd_start_app, "", SAF_NONE);
-    SWITCH_ADD_APP(app_interface, "avmd_stop","Stop avmd detection", "Stop avmd detection", avmd_stop_app, "", SAF_NONE);
-    SWITCH_ADD_APP(app_interface, "avmd","Beep detection", "Advanced detection of voicemail beeps", avmd_start_function, AVMD_SYNTAX, SAF_NONE);
+       SWITCH_ADD_APP(app_interface, "avmd_start","Start avmd detection", "Start avmd detection", avmd_start_app, "", SAF_NONE);
+       SWITCH_ADD_APP(app_interface, "avmd_stop","Stop avmd detection", "Stop avmd detection", avmd_stop_app, "", SAF_NONE);
+       SWITCH_ADD_APP(app_interface, "avmd","Beep detection", "Advanced detection of voicemail beeps", avmd_start_function, AVMD_SYNTAX, SAF_NONE);
 
-    SWITCH_ADD_API(api_interface, "avmd", "Voicemail beep detection", avmd_api_main, AVMD_SYNTAX);
+       SWITCH_ADD_API(api_interface, "avmd", "Voicemail beep detection", avmd_api_main, AVMD_SYNTAX);
 
-    switch_console_set_complete("add avmd ::console::list_uuid ::[start:stop");
-    switch_console_set_complete("add avmd set inbound");    /* set inbound = 1, outbound = 0 */
-    switch_console_set_complete("add avmd set outbound");   /* set inbound = 0, outbound = 1 */
-    switch_console_set_complete("add avmd set default");    /* restore to factory settings */
-    switch_console_set_complete("add avmd load inbound");   /* reload + set inbound */
-    switch_console_set_complete("add avmd load outbound");  /* reload + set outbound */
-    switch_console_set_complete("add avmd reload");         /* reload XML (it loads from FS installation
-                                                             * folder, not module's conf/autoload_configs */
-    switch_console_set_complete("add avmd show");
+       switch_console_set_complete("add avmd ::console::list_uuid ::[start:stop");
+       switch_console_set_complete("add avmd set inbound");    /* set inbound = 1, outbound = 0 */
+       switch_console_set_complete("add avmd set outbound");   /* set inbound = 0, outbound = 1 */
+       switch_console_set_complete("add avmd set default");    /* restore to factory settings */
+       switch_console_set_complete("add avmd load inbound");   /* reload + set inbound */
+       switch_console_set_complete("add avmd load outbound");  /* reload + set outbound */
+       switch_console_set_complete("add avmd reload");          /* reload XML (it loads from FS installation
+                                                                                                                        * folder, not module's conf/autoload_configs */
+       switch_console_set_complete("add avmd show");
 
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Advanced voicemail detection enabled\n");
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Advanced voicemail detection enabled\n");
 
-    return SWITCH_STATUS_SUCCESS; /* indicate that the module should continue to be loaded */
+       return SWITCH_STATUS_SUCCESS; /* indicate that the module should continue to be loaded */
 }
 
 void avmd_config_dump(avmd_session_t *s) {
-    struct avmd_settings *settings;
-
-    if (s == NULL) {
-        return;
-    }
-    settings = &s->settings;
-    switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_INFO, "Avmd dynamic configuration: debug [%u], report_status [%u], fast_math [%u],"
-            " require_continuous_streak [%u], sample_n_continuous_streak [%u], sample_n_to_skip [%u], require_continuous_streak_amp [%u], sample_n_continuous_streak_amp [%u],"
-           " simplified_estimation [%u], inbound_channel [%u], outbound_channel [%u], detection_mode [%u], detectors_n [%u], detectors_lagged_n [%u]\n",
-            settings->debug, settings->report_status, settings->fast_math, settings->require_continuous_streak, settings->sample_n_continuous_streak,
-            settings->sample_n_to_skip, settings->require_continuous_streak_amp, settings->sample_n_continuous_streak_amp,
-            settings->simplified_estimation, settings->inbound_channnel, settings->outbound_channnel, settings->mode, settings->detectors_n, settings->detectors_lagged_n);
-    return;
+       struct avmd_settings *settings;
+
+       if (s == NULL) {
+               return;
+       }
+       settings = &s->settings;
+       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_INFO, "Avmd dynamic configuration: debug [%u], report_status [%u], fast_math [%u],"
+                       " require_continuous_streak [%u], sample_n_continuous_streak [%u], sample_n_to_skip [%u], require_continuous_streak_amp [%u], sample_n_continuous_streak_amp [%u],"
+                  " simplified_estimation [%u], inbound_channel [%u], outbound_channel [%u], detection_mode [%u], detectors_n [%u], detectors_lagged_n [%u]\n",
+                       settings->debug, settings->report_status, settings->fast_math, settings->require_continuous_streak, settings->sample_n_continuous_streak,
+                       settings->sample_n_to_skip, settings->require_continuous_streak_amp, settings->sample_n_continuous_streak_amp,
+                       settings->simplified_estimation, settings->inbound_channnel, settings->outbound_channnel, settings->mode, settings->detectors_n, settings->detectors_lagged_n);
+       return;
 }
 
 static switch_status_t avmd_parse_cmd_data_one_entry(char *candidate, struct avmd_settings *settings) {
-    char        *candidate_parsed[3];
-    int         argc;
-    const char *key;
-    const char *val;
-
-    if (settings == NULL) {
-        return SWITCH_STATUS_TERM;
-    }
-    if (candidate == NULL) {
-        return SWITCH_STATUS_NOOP;
-    }
-
-    argc = switch_separate_string(candidate, '=', candidate_parsed, (sizeof(candidate_parsed) / sizeof(candidate_parsed[0])));
-    if (argc > 2) { /* currently we accept only option=value syntax */
-        return SWITCH_STATUS_IGNORE;
-    }
-
-    /* this may be option parameter if valid */
-    key = candidate_parsed[0];      /* option name */
-    if (zstr(key)) { /* empty key */
-        return SWITCH_STATUS_NOT_INITALIZED;
-    }
-    val = candidate_parsed[1];      /* value of the option: whole string starting at 1 past the '=' */
-    if (zstr(val)) { /* nothing after "=" found, empty value */
-        return SWITCH_STATUS_MORE_DATA;
-    }
-    /* candidate string has "=" somewhere in the middle and some value,
-     * try to find what option it is by comparing at most given number of bytes */
-    if (!strcmp(key, "debug")) {
-        settings->debug = (uint8_t) switch_true(val);
-    } else if (!strcmp(key, "report_status")) {
-        settings->report_status = (uint8_t) switch_true(val);
-    } else if (!strcmp(key, "fast_math")) {
-        settings->fast_math = (uint8_t) switch_true(val);
-    } else if (!strcmp(key, "require_continuous_streak")) {
-        settings->require_continuous_streak = (uint8_t) switch_true(val);
-    } else if (!strcmp(key, "sample_n_continuous_streak")) {
-        if(avmd_parse_u16_user_input(val, &settings->sample_n_continuous_streak, 0, UINT16_MAX) == -1) {
-            return SWITCH_STATUS_FALSE;
-        }
-    } else if (!strcmp(key, "sample_n_to_skip")) {
-        if(avmd_parse_u16_user_input(val, &settings->sample_n_to_skip, 0, UINT16_MAX) == -1) {
-            return SWITCH_STATUS_FALSE;
-        }
-    } else if (!strcmp(key, "require_continuous_streak_amp")) {
-        settings->require_continuous_streak_amp = (uint8_t) switch_true(val);
-    } else if (!strcmp(key, "sample_n_continuous_streak_amp")) {
-        if(avmd_parse_u16_user_input(val, &settings->sample_n_continuous_streak_amp, 0, UINT16_MAX) == -1) {
-            return SWITCH_STATUS_FALSE;
-        }
-    } else if (!strcmp(key, "simplified_estimation")) {
-        settings->simplified_estimation = (uint8_t) switch_true(val);
-    } else if (!strcmp(key, "inbound_channel")) {
-        settings->inbound_channnel = (uint8_t) switch_true(val);
-    } else if (!strcmp(key, "outbound_channel")) {
-        settings->outbound_channnel = (uint8_t) switch_true(val);
-    } else if (!strcmp(key, "detection_mode")) {
-        if(avmd_parse_u8_user_input(val, (uint8_t*)&settings->mode, 0, 2) == -1) {
-            return SWITCH_STATUS_FALSE;
-        }
-    } else if (!strcmp(key, "detectors_n")) {
-        if(avmd_parse_u8_user_input(val, &settings->detectors_n, 0, UINT8_MAX) == -1) {
-            return SWITCH_STATUS_FALSE;
-        }
-    } else if (!strcmp(key, "detectors_lagged_n")) {
-        if(avmd_parse_u8_user_input(val, &settings->detectors_lagged_n, 0, UINT8_MAX) == -1) {
-            return SWITCH_STATUS_FALSE;
-        }
-    } else {
-        return SWITCH_STATUS_NOTFOUND;
-    }
-    return SWITCH_STATUS_SUCCESS;
+       char *candidate_parsed[3];
+       int argc;
+       const char *key;
+       const char *val;
+
+       if (settings == NULL) {
+               return SWITCH_STATUS_TERM;
+       }
+       if (candidate == NULL) {
+               return SWITCH_STATUS_NOOP;
+       }
+
+       argc = switch_separate_string(candidate, '=', candidate_parsed, (sizeof(candidate_parsed) / sizeof(candidate_parsed[0])));
+       if (argc > 2) { /* currently we accept only option=value syntax */
+               return SWITCH_STATUS_IGNORE;
+       }
+
+       /* this may be option parameter if valid */
+       key = candidate_parsed[0];        /* option name */
+       if (zstr(key)) { /* empty key */
+               return SWITCH_STATUS_NOT_INITALIZED;
+       }
+       val = candidate_parsed[1];        /* value of the option: whole string starting at 1 past the '=' */
+       if (zstr(val)) { /* nothing after "=" found, empty value */
+               return SWITCH_STATUS_MORE_DATA;
+       }
+       /* candidate string has "=" somewhere in the middle and some value,
+        * try to find what option it is by comparing at most given number of bytes */
+       if (!strcmp(key, "debug")) {
+               settings->debug = (uint8_t) switch_true(val);
+       } else if (!strcmp(key, "report_status")) {
+               settings->report_status = (uint8_t) switch_true(val);
+       } else if (!strcmp(key, "fast_math")) {
+               settings->fast_math = (uint8_t) switch_true(val);
+       } else if (!strcmp(key, "require_continuous_streak")) {
+               settings->require_continuous_streak = (uint8_t) switch_true(val);
+       } else if (!strcmp(key, "sample_n_continuous_streak")) {
+               if(avmd_parse_u16_user_input(val, &settings->sample_n_continuous_streak, 0, UINT16_MAX) == -1) {
+                       return SWITCH_STATUS_FALSE;
+               }
+       } else if (!strcmp(key, "sample_n_to_skip")) {
+               if(avmd_parse_u16_user_input(val, &settings->sample_n_to_skip, 0, UINT16_MAX) == -1) {
+                       return SWITCH_STATUS_FALSE;
+               }
+       } else if (!strcmp(key, "require_continuous_streak_amp")) {
+               settings->require_continuous_streak_amp = (uint8_t) switch_true(val);
+       } else if (!strcmp(key, "sample_n_continuous_streak_amp")) {
+               if(avmd_parse_u16_user_input(val, &settings->sample_n_continuous_streak_amp, 0, UINT16_MAX) == -1) {
+                       return SWITCH_STATUS_FALSE;
+               }
+       } else if (!strcmp(key, "simplified_estimation")) {
+               settings->simplified_estimation = (uint8_t) switch_true(val);
+       } else if (!strcmp(key, "inbound_channel")) {
+               settings->inbound_channnel = (uint8_t) switch_true(val);
+       } else if (!strcmp(key, "outbound_channel")) {
+               settings->outbound_channnel = (uint8_t) switch_true(val);
+       } else if (!strcmp(key, "detection_mode")) {
+               if(avmd_parse_u8_user_input(val, (uint8_t*)&settings->mode, 0, 2) == -1) {
+                       return SWITCH_STATUS_FALSE;
+               }
+       } else if (!strcmp(key, "detectors_n")) {
+               if(avmd_parse_u8_user_input(val, &settings->detectors_n, 0, UINT8_MAX) == -1) {
+                       return SWITCH_STATUS_FALSE;
+               }
+       } else if (!strcmp(key, "detectors_lagged_n")) {
+               if(avmd_parse_u8_user_input(val, &settings->detectors_lagged_n, 0, UINT8_MAX) == -1) {
+                       return SWITCH_STATUS_FALSE;
+               }
+       } else {
+               return SWITCH_STATUS_NOTFOUND;
+       }
+       return SWITCH_STATUS_SUCCESS;
 }
 
 /* RCU style: reads, copies and then updates only if everything is fine,
@@ -1310,740 +1310,740 @@ static switch_status_t avmd_parse_cmd_data_one_entry(char *candidate, struct avm
  * are updated accordingly to @cmd_data, if SWITCH_STATUS_FALSE then
  * parsing error occurred and avmd session is left untouched */
 static switch_status_t avmd_parse_cmd_data(avmd_session_t *s, const char *cmd_data, enum avmd_app app) {
-    char *mydata;
-    struct avmd_settings    settings;
-    int argc = 0, idx;
-    char *argv[AVMD_PARAMS_APP_MAX * 2] = { 0 };
-    switch_status_t status = SWITCH_STATUS_SUCCESS;
-
-    if (s == NULL) {
-        return SWITCH_STATUS_NOOP;
-    }
-
-    memcpy(&settings, &avmd_globals.settings, sizeof (struct avmd_settings));   /* copy globally set settings first */
-    if (zstr(cmd_data)) {
-        goto end_copy;
-    }
-
-    switch (app) {
-
-        case AVMD_APP_START_APP:
-            /* try to parse settings */
-            mydata = switch_core_session_strdup(s->session, cmd_data);
-            argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0])));
-            if (argc < AVMD_PARAMS_APP_START_MIN || argc > AVMD_PARAMS_APP_START_MAX) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
-                        "Syntax Error, avmd_start APP takes [%u] to [%u] parameters\n",
-                        AVMD_PARAMS_APP_START_MIN, AVMD_PARAMS_APP_START_MAX);
-                switch_goto_status(SWITCH_STATUS_MORE_DATA, fail);
-            }
-            /* iterate over params, check if they mean something to us, set */
-            idx = 0;
-            while (idx < argc) {
-                switch_assert(argv[idx]);
-                status = avmd_parse_cmd_data_one_entry(argv[idx], &settings);
-                if (status != SWITCH_STATUS_SUCCESS) {
-                    if (argv[idx]) {
-                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
-                            "Error parsing option [%d] [%s]\n", idx + 1, argv[idx]);    /* idx + 1 to report option 0 as 1 for users convenience */
-                    }
-                    switch (status)
-                    {
-                        case SWITCH_STATUS_TERM:
-                            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
-                                    "NULL settings struct passed to parser\n");
-                            break;
-                        case SWITCH_STATUS_NOOP:
-                            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
-                                    "NULL settings string passed to parser\n");
-                            break;
-                        case SWITCH_STATUS_IGNORE:
-                            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
-                                    "Syntax error. Currently we accept only option=value syntax\n");
-                            break;
-                        case SWITCH_STATUS_NOT_INITALIZED:
-                            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
-                                    "Syntax error. No key specified\n");
-                            break;
-                        case SWITCH_STATUS_MORE_DATA:
-                            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
-                                    "Syntax error. No value for the key? Currently we accept only option=value syntax\n");
-                            break;
-                        case SWITCH_STATUS_FALSE:
-                            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
-                                    "Bad value for this option\n");
-                            break;
-                        case SWITCH_STATUS_NOTFOUND:
-                            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
-                                    "Option not found. Please check option name is correct\n");
-                            break;
-                        default:
-                            break;
-                    }
-                    status = SWITCH_STATUS_FALSE;
-                    goto fail;
-                }
-                ++idx;
-            }
-            /* OK */
-            goto end_copy;
-        default:
-            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR, "There is no app with index [%u] for avmd\n", app);
-            switch_goto_status(SWITCH_STATUS_NOTFOUND, fail);
-    }
+       char *mydata;
+       struct avmd_settings settings;
+       int argc = 0, idx;
+       char *argv[AVMD_PARAMS_APP_MAX * 2] = { 0 };
+       switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+       if (s == NULL) {
+               return SWITCH_STATUS_NOOP;
+       }
+
+       memcpy(&settings, &avmd_globals.settings, sizeof (struct avmd_settings));   /* copy globally set settings first */
+       if (zstr(cmd_data)) {
+               goto end_copy;
+       }
+
+       switch (app) {
+
+               case AVMD_APP_START_APP:
+                       /* try to parse settings */
+                       mydata = switch_core_session_strdup(s->session, cmd_data);
+                       argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0])));
+                       if (argc < AVMD_PARAMS_APP_START_MIN || argc > AVMD_PARAMS_APP_START_MAX) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
+                                               "Syntax Error, avmd_start APP takes [%u] to [%u] parameters\n",
+                                               AVMD_PARAMS_APP_START_MIN, AVMD_PARAMS_APP_START_MAX);
+                               switch_goto_status(SWITCH_STATUS_MORE_DATA, fail);
+                       }
+                       /* iterate over params, check if they mean something to us, set */
+                       idx = 0;
+                       while (idx < argc) {
+                               switch_assert(argv[idx]);
+                               status = avmd_parse_cmd_data_one_entry(argv[idx], &settings);
+                               if (status != SWITCH_STATUS_SUCCESS) {
+                                       if (argv[idx]) {
+                                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
+                                                       "Error parsing option [%d] [%s]\n", idx + 1, argv[idx]);        /* idx + 1 to report option 0 as 1 for users convenience */
+                                       }
+                                       switch (status)
+                                       {
+                                               case SWITCH_STATUS_TERM:
+                                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
+                                                                       "NULL settings struct passed to parser\n");
+                                                       break;
+                                               case SWITCH_STATUS_NOOP:
+                                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
+                                                                       "NULL settings string passed to parser\n");
+                                                       break;
+                                               case SWITCH_STATUS_IGNORE:
+                                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
+                                                                       "Syntax error. Currently we accept only option=value syntax\n");
+                                                       break;
+                                               case SWITCH_STATUS_NOT_INITALIZED:
+                                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
+                                                                       "Syntax error. No key specified\n");
+                                                       break;
+                                               case SWITCH_STATUS_MORE_DATA:
+                                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
+                                                                       "Syntax error. No value for the key? Currently we accept only option=value syntax\n");
+                                                       break;
+                                               case SWITCH_STATUS_FALSE:
+                                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
+                                                                       "Bad value for this option\n");
+                                                       break;
+                                               case SWITCH_STATUS_NOTFOUND:
+                                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
+                                                                       "Option not found. Please check option name is correct\n");
+                                                       break;
+                                               default:
+                                                       break;
+                                       }
+                                       status = SWITCH_STATUS_FALSE;
+                                       goto fail;
+                               }
+                               ++idx;
+                       }
+                       /* OK */
+                       goto end_copy;
+               default:
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR, "There is no app with index [%u] for avmd\n", app);
+                       switch_goto_status(SWITCH_STATUS_NOTFOUND, fail);
+       }
 
 end_copy:
-    memcpy(&s->settings, &settings, sizeof (struct avmd_settings)); /* commit the change */
-    return SWITCH_STATUS_SUCCESS;
+       memcpy(&s->settings, &settings, sizeof (struct avmd_settings)); /* commit the change */
+       return SWITCH_STATUS_SUCCESS;
 fail:
-    return status;
+       return status;
 }
 
 SWITCH_STANDARD_APP(avmd_start_app) {
-    switch_media_bug_t  *bug = NULL;
-    switch_status_t     status = SWITCH_STATUS_FALSE;
-    switch_channel_t    *channel = NULL;
-    avmd_session_t      *avmd_session = NULL;
-    switch_core_media_flag_t flags = 0;
+       switch_media_bug_t *bug = NULL;
+       switch_status_t status = SWITCH_STATUS_FALSE;
+       switch_channel_t *channel = NULL;
+       avmd_session_t *avmd_session = NULL;
+       switch_core_media_flag_t flags = 0;
        const char *direction = "NO DIRECTION";
        uint8_t report = 0;
 
-    if (session == NULL) {
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "BUGGG. FreeSWITCH session is NULL! Please report to developers\n");
-        return;
-    }
-
-    /* Get current channel of the session to tag the session. This indicates that our module is present
-     * At this moment this cannot return NULL, it will either succeed or assert failed, but we make ourself secure anyway */
-    channel = switch_core_session_get_channel(session);
-    if (channel == NULL) {
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "BUGGG. No channel for FreeSWITCH session! Please report this to the developers.\n");
-        goto end;
-    }
-
-    bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_avmd_"); /* Is this channel already set? */
-    if (bug != NULL) { /* We have already started */
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Avmd already started!\n");
-        return;
-    }
-
-    /* Allocate memory attached to this FreeSWITCH session for use in the callback routine and to store state information */
-    avmd_session = (avmd_session_t *) switch_core_session_alloc(session, sizeof(avmd_session_t));
-    if (avmd_session == NULL) {
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't allocate memory for avmd session!\n");
-        status = SWITCH_STATUS_FALSE;
-        goto end;
-    }
-    avmd_session->session = session;
-
-    status = avmd_parse_cmd_data(avmd_session, data, AVMD_APP_START_APP);   /* dynamic configuation */
-    switch (status) {
-        case SWITCH_STATUS_SUCCESS:
-            break;
-        case SWITCH_STATUS_NOOP:
-            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to set dynamic parameters for avmd session. Session is NULL!\n");
-            goto end;
-        case SWITCH_STATUS_FALSE:
-            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to set dynamic parameters for avmd session. Parsing error, please check the parameters passed to this APP.\n");
-            goto end;
-        default:
-            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to set dynamic parameteres for avmd session. Unknown error\n");
-            goto end;
-    }
+       if (session == NULL) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "BUGGG. FreeSWITCH session is NULL! Please report to developers\n");
+               return;
+       }
+
+       /* Get current channel of the session to tag the session. This indicates that our module is present
+        * At this moment this cannot return NULL, it will either succeed or assert failed, but we make ourself secure anyway */
+       channel = switch_core_session_get_channel(session);
+       if (channel == NULL) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "BUGGG. No channel for FreeSWITCH session! Please report this to the developers.\n");
+               goto end;
+       }
+
+       bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_avmd_"); /* Is this channel already set? */
+       if (bug != NULL) { /* We have already started */
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Avmd already started!\n");
+               return;
+       }
+
+       /* Allocate memory attached to this FreeSWITCH session for use in the callback routine and to store state information */
+       avmd_session = (avmd_session_t *) switch_core_session_alloc(session, sizeof(avmd_session_t));
+       if (avmd_session == NULL) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't allocate memory for avmd session!\n");
+               status = SWITCH_STATUS_FALSE;
+               goto end;
+       }
+       avmd_session->session = session;
+
+       status = avmd_parse_cmd_data(avmd_session, data, AVMD_APP_START_APP);   /* dynamic configuation */
+       switch (status) {
+               case SWITCH_STATUS_SUCCESS:
+                       break;
+               case SWITCH_STATUS_NOOP:
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to set dynamic parameters for avmd session. Session is NULL!\n");
+                       goto end;
+               case SWITCH_STATUS_FALSE:
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to set dynamic parameters for avmd session. Parsing error, please check the parameters passed to this APP.\n");
+                       goto end;
+               default:
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to set dynamic parameteres for avmd session. Unknown error\n");
+                       goto end;
+       }
        
        report = avmd_session->settings.report_status;
 
-    status = init_avmd_session_data(avmd_session, session, avmd_globals.mutex);
-    if (status != SWITCH_STATUS_SUCCESS) {
-        switch (status) {
-            case SWITCH_STATUS_MEMERR:
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to init avmd session. Buffer error!\n");
-                break;
-            case SWITCH_STATUS_MORE_DATA:
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to init avmd session. SMA buffer size is 0!\n");
-                break;
-            case SWITCH_STATUS_FALSE:
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to init avmd session. SMA buffers error\n");
-                break;
-            default:
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to init avmd session. Unknown error\n");
-                break;
-        }
-        goto end;
-    }
-
-    switch_mutex_lock(avmd_session->mutex);
-    if (avmd_session->settings.report_status == 1) { /* dump dynamic parameters */
-        avmd_config_dump(avmd_session);
-    }
-    if ((SWITCH_CALL_DIRECTION_OUTBOUND == switch_channel_direction(channel)) && (avmd_session->settings.outbound_channnel == 1)) {
-            flags |= SMBF_READ_REPLACE;
+       status = init_avmd_session_data(avmd_session, session, avmd_globals.mutex);
+       if (status != SWITCH_STATUS_SUCCESS) {
+               switch (status) {
+                       case SWITCH_STATUS_MEMERR:
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to init avmd session. Buffer error!\n");
+                               break;
+                       case SWITCH_STATUS_MORE_DATA:
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to init avmd session. SMA buffer size is 0!\n");
+                               break;
+                       case SWITCH_STATUS_FALSE:
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to init avmd session. SMA buffers error\n");
+                               break;
+                       default:
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to init avmd session. Unknown error\n");
+                               break;
+               }
+               goto end;
+       }
+
+       switch_mutex_lock(avmd_session->mutex);
+       if (avmd_session->settings.report_status == 1) { /* dump dynamic parameters */
+               avmd_config_dump(avmd_session);
+       }
+       if ((SWITCH_CALL_DIRECTION_OUTBOUND == switch_channel_direction(channel)) && (avmd_session->settings.outbound_channnel == 1)) {
+                       flags |= SMBF_READ_REPLACE;
                        direction = "READ_REPLACE";
-    }
-    if ((SWITCH_CALL_DIRECTION_INBOUND == switch_channel_direction(channel)) && (avmd_session->settings.inbound_channnel == 1)) {
-            flags |= SMBF_WRITE_REPLACE;
+       }
+       if ((SWITCH_CALL_DIRECTION_INBOUND == switch_channel_direction(channel)) && (avmd_session->settings.inbound_channnel == 1)) {
+                       flags |= SMBF_WRITE_REPLACE;
                        if (!strcmp(direction, "READ_REPLACE")) {
                                direction = "READ_REPLACE | WRITE_REPLACE";
                        } else {
                                direction = "WRITE_REPLACE";
                        }
-    }
-
-    if (flags == 0) {
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't set direction for channel [%s]\n", switch_channel_get_name(channel));
-        status = SWITCH_STATUS_FALSE;
-        goto end_unlock;
-    }
-
-    if ((SWITCH_CALL_DIRECTION_OUTBOUND == switch_channel_direction(channel)) && (avmd_session->settings.outbound_channnel == 1)) {
-        if (switch_channel_test_flag(channel, CF_MEDIA_SET) == 0) {
-            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Channel [%s] has no codec assigned yet. Please try again\n", switch_channel_get_name(channel));
-            status = SWITCH_STATUS_FALSE;
-            goto end_unlock;
-        }
-    }
-
-    status = avmd_launch_threads(avmd_session);
-    if (status != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to start detection threads\n");
-        avmd_join_threads(avmd_session);
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Joined detection threads\n");
-        goto end_unlock;
-    }
-
-    status = switch_core_media_bug_add(session, "avmd", NULL, avmd_callback, avmd_session, 0, flags, &bug); /* Add a media bug that allows me to intercept the audio stream */
-    if (status != SWITCH_STATUS_SUCCESS) { /* If adding a media bug fails exit */
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to add media bug!\n");
+       }
+
+       if (flags == 0) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't set direction for channel [%s]\n", switch_channel_get_name(channel));
+               status = SWITCH_STATUS_FALSE;
+               goto end_unlock;
+       }
+
+       if ((SWITCH_CALL_DIRECTION_OUTBOUND == switch_channel_direction(channel)) && (avmd_session->settings.outbound_channnel == 1)) {
+               if (switch_channel_test_flag(channel, CF_MEDIA_SET) == 0) {
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Channel [%s] has no codec assigned yet. Please try again\n", switch_channel_get_name(channel));
+                       status = SWITCH_STATUS_FALSE;
+                       goto end_unlock;
+               }
+       }
+
+       status = avmd_launch_threads(avmd_session);
+       if (status != SWITCH_STATUS_SUCCESS) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to start detection threads\n");
+               avmd_join_threads(avmd_session);
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Joined detection threads\n");
+               goto end_unlock;
+       }
+
+       status = switch_core_media_bug_add(session, "avmd", NULL, avmd_callback, avmd_session, 0, flags, &bug); /* Add a media bug that allows me to intercept the audio stream */
+       if (status != SWITCH_STATUS_SUCCESS) { /* If adding a media bug fails exit */
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to add media bug!\n");
 
                switch_mutex_unlock(avmd_session->mutex);
                avmd_session_close(avmd_session);
-        goto end;
-    }
+               goto end;
+       }
 
-    switch_mutex_lock(avmd_globals.mutex);
-    ++avmd_globals.session_n;
-    switch_mutex_unlock(avmd_globals.mutex);
+       switch_mutex_lock(avmd_globals.mutex);
+       ++avmd_globals.session_n;
+       switch_mutex_unlock(avmd_globals.mutex);
 
-    switch_channel_set_private(channel, "_avmd_", bug); /* Set the avmd tag to detect an existing avmd media bug */
-    avmd_fire_event(AVMD_EVENT_SESSION_START, session, 0, 0, 0, 0, 0, 0, 0, 0, avmd_session->start_time, 0, 0, 0, 0);
-    if (avmd_session->settings.report_status == 1) {
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Avmd on channel [%s] started! direction=%s\n", switch_channel_get_name(channel), direction);
-    }
+       switch_channel_set_private(channel, "_avmd_", bug); /* Set the avmd tag to detect an existing avmd media bug */
+       avmd_fire_event(AVMD_EVENT_SESSION_START, session, 0, 0, 0, 0, 0, 0, 0, 0, avmd_session->start_time, 0, 0, 0, 0);
+       if (avmd_session->settings.report_status == 1) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Avmd on channel [%s] started! direction=%s\n", switch_channel_get_name(channel), direction);
+       }
 
 end_unlock:
-    switch_mutex_unlock(avmd_session->mutex);
+       switch_mutex_unlock(avmd_session->mutex);
 
 end:
-    if (status != SWITCH_STATUS_SUCCESS) {
-        if (avmd_session == NULL || report) {
-            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Avmd on channel [%s] NOT started\n", switch_channel_get_name(channel));
-        }
-    }
-    return;
+       if (status != SWITCH_STATUS_SUCCESS) {
+               if (avmd_session == NULL || report) {
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Avmd on channel [%s] NOT started\n", switch_channel_get_name(channel));
+               }
+       }
+       return;
 }
 
 SWITCH_STANDARD_APP(avmd_stop_app) {
-    switch_media_bug_t  *bug;
-    switch_channel_t    *channel;
-    avmd_session_t      *avmd_session;
-    switch_time_t       start_time, stop_time, total_time;
-    uint8_t             report_status = 0;
-    avmd_beep_state_t   beep_status = BEEP_NOTDETECTED;
-
-    if (session == NULL) {
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "FreeSWITCH is NULL! Please report to developers\n");
-        return;
-    }
-
-    /* Get current channel of the session to tag the session. This indicates that our module is present
-     * At this moment this cannot return NULL, it will either succeed or assert failed, but we make ourself secure anyway */
-    channel = switch_core_session_get_channel(session);
-    if (channel == NULL) {
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No channel for FreeSWITCH session! Please report this to the developers.\n");
-        return;
-    }
-
-    bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_avmd_");
-    if (bug == NULL) {
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Stop failed - no avmd session running on this channel [%s]!\n", switch_channel_get_name(channel));
-        return;
-    }
-
-    avmd_session = switch_core_media_bug_get_user_data(bug);
-    if (avmd_session == NULL) {
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Stop failed - no avmd session object, stop event not fired on this channel [%s]!\n", switch_channel_get_name(channel));
-    } else {
-        switch_mutex_lock(avmd_session->mutex);
-        report_status = avmd_session->settings.report_status;
-        beep_status = avmd_session->state.beep_state;
-        avmd_session->stop_time = switch_micro_time_now();
-        start_time = avmd_session->start_time;
-        stop_time = avmd_session->stop_time;
-        total_time = stop_time - start_time;
-        switch_mutex_unlock(avmd_session->mutex);
-        avmd_fire_event(AVMD_EVENT_SESSION_STOP, session, 0, 0, 0, 0, beep_status, 1, 0, 0, start_time, stop_time, 0, 0, 0);
-        if (report_status == 1) {
-            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Avmd on channel [%s] stopped, beep status: [%s], total running time [%" PRId64 "] [us]\n", switch_channel_get_name(channel), beep_status == BEEP_DETECTED ? "DETECTED" : "NOTDETECTED", total_time);
-        }
-    }
-    switch_channel_set_private(channel, "_avmd_", NULL);
-    switch_core_media_bug_remove(session, &bug);
-
-    return;
+       switch_media_bug_t  *bug;
+       switch_channel_t        *channel;
+       avmd_session_t    *avmd_session;
+       switch_time_t      start_time, stop_time, total_time;
+       uint8_t                  report_status = 0;
+       avmd_beep_state_t   beep_status = BEEP_NOTDETECTED;
+
+       if (session == NULL) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "FreeSWITCH is NULL! Please report to developers\n");
+               return;
+       }
+
+       /* Get current channel of the session to tag the session. This indicates that our module is present
+        * At this moment this cannot return NULL, it will either succeed or assert failed, but we make ourself secure anyway */
+       channel = switch_core_session_get_channel(session);
+       if (channel == NULL) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No channel for FreeSWITCH session! Please report this to the developers.\n");
+               return;
+       }
+
+       bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_avmd_");
+       if (bug == NULL) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Stop failed - no avmd session running on this channel [%s]!\n", switch_channel_get_name(channel));
+               return;
+       }
+
+       avmd_session = switch_core_media_bug_get_user_data(bug);
+       if (avmd_session == NULL) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Stop failed - no avmd session object, stop event not fired on this channel [%s]!\n", switch_channel_get_name(channel));
+       } else {
+               switch_mutex_lock(avmd_session->mutex);
+               report_status = avmd_session->settings.report_status;
+               beep_status = avmd_session->state.beep_state;
+               avmd_session->stop_time = switch_micro_time_now();
+               start_time = avmd_session->start_time;
+               stop_time = avmd_session->stop_time;
+               total_time = stop_time - start_time;
+               switch_mutex_unlock(avmd_session->mutex);
+               avmd_fire_event(AVMD_EVENT_SESSION_STOP, session, 0, 0, 0, 0, beep_status, 1, 0, 0, start_time, stop_time, 0, 0, 0);
+               if (report_status == 1) {
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Avmd on channel [%s] stopped, beep status: [%s], total running time [%" PRId64 "] [us]\n", switch_channel_get_name(channel), beep_status == BEEP_DETECTED ? "DETECTED" : "NOTDETECTED", total_time);
+               }
+       }
+       switch_channel_set_private(channel, "_avmd_", NULL);
+       switch_core_media_bug_remove(session, &bug);
+
+       return;
 }
 
 /*! \brief FreeSWITCH application handler function.
  *  This handles calls made from applications such as LUA and the dialplan.
  */
 SWITCH_STANDARD_APP(avmd_start_function) {
-    switch_media_bug_t  *bug;
-    switch_channel_t    *channel;
-
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "YOU ARE USING DEPRECATED APP INTERFACE. Please read documentation about new syntax\n");
-    if (session == NULL) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No FreeSWITCH session assigned!\n");
-        return;
-    }
-
-    channel = switch_core_session_get_channel(session);
-
-    bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_avmd_");
-    if (bug != NULL) {
-        if (strcasecmp(data, "stop") == 0) {
-            switch_channel_set_private(channel, "_avmd_", NULL);
-            switch_core_media_bug_remove(session, &bug);
-            return;
-        }
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
-        return;
-    }
-    avmd_start_app(session, NULL);
+       switch_media_bug_t *bug;
+       switch_channel_t *channel;
+
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "YOU ARE USING DEPRECATED APP INTERFACE. Please read documentation about new syntax\n");
+       if (session == NULL) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No FreeSWITCH session assigned!\n");
+               return;
+       }
+
+       channel = switch_core_session_get_channel(session);
+
+       bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_avmd_");
+       if (bug != NULL) {
+               if (strcasecmp(data, "stop") == 0) {
+                       switch_channel_set_private(channel, "_avmd_", NULL);
+                       switch_core_media_bug_remove(session, &bug);
+                       return;
+               }
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
+               return;
+       }
+       avmd_start_app(session, NULL);
 }
 
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_avmd_shutdown) {
-    size_t session_n;
+       size_t session_n;
 #ifndef WIN32
-    int res;
+       int res;
 #endif
 
-    switch_mutex_lock(avmd_globals.mutex);
+       switch_mutex_lock(avmd_globals.mutex);
 
-    session_n = avmd_globals.session_n;
-    if (session_n > 0) {
-        switch_mutex_unlock(avmd_globals.mutex);
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PLEASE DO NOT RELOAD MODULE WHILE SESSIONS ARE RUNNING\n");
-    }
+       session_n = avmd_globals.session_n;
+       if (session_n > 0) {
+               switch_mutex_unlock(avmd_globals.mutex);
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PLEASE DO NOT RELOAD MODULE WHILE SESSIONS ARE RUNNING\n");
+       }
 
-    avmd_unregister_all_events();
+       avmd_unregister_all_events();
 
 #ifndef WIN32
-    if (avmd_globals.settings.fast_math == 1) {
-        res = destroy_fast_acosf();
-        if (res != 0) {
-            switch (res) {
-                case -1:
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed unmap arc cosine table\n");
-                    break;
-                case -2:
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed closing arc cosine table\n");
-                    break;
-                default:
-                    break;
-            }
-        }
-    }
+       if (avmd_globals.settings.fast_math == 1) {
+               res = destroy_fast_acosf();
+               if (res != 0) {
+                       switch (res) {
+                               case -1:
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed unmap arc cosine table\n");
+                                       break;
+                               case -2:
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed closing arc cosine table\n");
+                                       break;
+                               default:
+                                       break;
+                       }
+               }
+       }
 #endif
 
-    switch_event_unbind_callback(avmd_reloadxml_event_handler);
-    switch_mutex_unlock(avmd_globals.mutex);
-    switch_mutex_destroy(avmd_globals.mutex);
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Advanced voicemail detection disabled\n");
-    return SWITCH_STATUS_SUCCESS;
+       switch_event_unbind_callback(avmd_reloadxml_event_handler);
+       switch_mutex_unlock(avmd_globals.mutex);
+       switch_mutex_destroy(avmd_globals.mutex);
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Advanced voicemail detection disabled\n");
+       return SWITCH_STATUS_SUCCESS;
 }
 
 /*! \brief FreeSWITCH API handler function. */
 SWITCH_STANDARD_API(avmd_api_main) {
-    switch_media_bug_t  *bug = NULL;
-    avmd_session_t      *avmd_session = NULL;
-    switch_channel_t    *channel = NULL;
-    int         argc;
-    const char  *uuid = NULL, *uuid_dup = NULL;
-    const char  *command = NULL;
-    char        *dupped = NULL, *argv[AVMD_PARAMS_API_MAX + 1] = { 0 };
-    switch_core_media_flag_t    flags = 0;
-    switch_status_t             status = SWITCH_STATUS_SUCCESS;
-    switch_core_session_t       *fs_session = NULL;
-
-    switch_mutex_lock(avmd_globals.mutex);
-
-    if (zstr(cmd)) {
-        stream->write_function(stream, "-ERR, bad command!\n-USAGE: %s\n\n", AVMD_SYNTAX);
-        goto end;
-    }
-
-    dupped = strdup(cmd);
-    switch_assert(dupped);
-    argc = switch_separate_string((char*)dupped, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
-
-    if (argc < AVMD_PARAMS_API_MIN) {
-        stream->write_function(stream, "-ERR, avmd takes [%u] min and [%u] max parameters!\n-USAGE: %s\n\n", AVMD_PARAMS_API_MIN, AVMD_PARAMS_API_MAX, AVMD_SYNTAX);
-        goto end;
-    }
-
-    command = argv[0];
-    if (strcasecmp(command, "reload") == 0) {
-        status = avmd_load_xml_configuration(NULL);
-        if (avmd_globals.settings.report_status == 1) {
-            if (status != SWITCH_STATUS_SUCCESS) {
-                stream->write_function(stream, "-ERR, couldn't reload XML configuration\n");
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't reload XML configuration\n");
-            } else {
-                stream->write_function(stream, "+OK\n XML reloaded\n\n");
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "XML reloaded\n");
-            }
-            goto end;
-        }
-    }
-    if (strcasecmp(command, "load") == 0) {
-        if (argc != 2) {
-            stream->write_function(stream, "-ERR, load command takes 1 parameter!\n-USAGE: %s\n\n", AVMD_SYNTAX);
-            goto end;
-        }
-        command = argv[1];
-        if (strcasecmp(command, "inbound") == 0) {
-            status = avmd_load_xml_inbound_configuration(NULL);
-            if (avmd_globals.settings.report_status == 1) {
-                if (status != SWITCH_STATUS_SUCCESS) {
-                    stream->write_function(stream, "-ERR, couldn't load XML configuration\n");
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't load XML configuration\n");
-                } else {
-                    stream->write_function(stream, "+OK\n inbound XML configuration loaded\n\n");
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Inbound XML configuration loaded\n");
-                }
-                goto end;
-            }
-        } else if (strcasecmp(command, "outbound") == 0) {
-            status = avmd_load_xml_outbound_configuration(NULL);
-            if (avmd_globals.settings.report_status == 1) {
-                if (status != SWITCH_STATUS_SUCCESS) {
-                    stream->write_function(stream, "-ERR, couldn't load XML configuration\n");
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't load XML configuration\n");
-                } else {
-                    stream->write_function(stream, "+OK\n outbound XML configuration loaded\n\n");
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Outbound XML configuration loaded\n");
-                }
-                goto end;
-            }
-        } else {
-            stream->write_function(stream, "-ERR, load command: bad syntax!\n-USAGE: %s\n\n", AVMD_SYNTAX);
-        }
-        goto end;
-    }
-    if (strcasecmp(command, "set") == 0) {
-        if (argc != 2) {
-            stream->write_function(stream, "-ERR, set command takes 1 parameter!\n-USAGE: %s\n\n", AVMD_SYNTAX);
-            goto end;
-        }
-        command = argv[1];
-        if (strcasecmp(command, "inbound") == 0) {
-            avmd_set_xml_inbound_configuration(NULL);
-            if (avmd_globals.settings.report_status == 1) {
-                stream->write_function(stream, "+OK\n inbound XML configuration loaded\n\n");
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Inbound XML configuration loaded\n");
-            }
-        } else if (strcasecmp(command, "outbound") == 0) {
-            avmd_set_xml_outbound_configuration(NULL);
-            if (avmd_globals.settings.report_status == 1) {
-                stream->write_function(stream, "+OK\n outbound XML configuration loaded\n\n");
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Outbound XML configuration loaded\n");
-            }
-        } else if (strcasecmp(command, "default") == 0) {
-            avmd_set_xml_default_configuration(NULL);
-            if (avmd_globals.settings.report_status == 1) {
-                stream->write_function(stream, "+OK\n reset to factory settings\n\n");
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Reset to factory settings\n");
-            }
-        } else {
-            stream->write_function(stream, "-ERR, set command: bad syntax!\n-USAGE: %s\n\n", AVMD_SYNTAX);
-        }
-        goto end;
-    }
-    if (strcasecmp(command, "show") == 0) {
-        avmd_show(stream, NULL);
-        if (avmd_globals.settings.report_status == 1) {
-            stream->write_function(stream, "+OK\n show\n\n");
-        }
-        goto end;
-    }
-
-    uuid = argv[0];
-    command = argv[1];
-
-    fs_session = switch_core_session_locate(uuid);  /* using uuid locate a reference to the FreeSWITCH session */
-    if (fs_session == NULL) {
-        stream->write_function(stream, "-ERR, no FreeSWITCH session for uuid [%s]!\n-USAGE: %s\n\n", uuid, AVMD_SYNTAX);
-        goto end;
-    }
-
-    /* Get current channel of the session to tag the session. This indicates that our module is present
-     * At this moment this cannot return NULL, it will either succeed or assert failed, but we make ourself secure anyway */
-    channel = switch_core_session_get_channel(fs_session);
-    if (channel == NULL) {
-        stream->write_function(stream, "-ERR, no channel for FreeSWITCH session [%s]!\n Please report this to the developers\n\n", uuid);
-        goto end;
-    }
-
-    bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_avmd_");
-    if (bug != NULL) {
-        if (strcasecmp(command, "stop") == 0) {
-            avmd_session = (avmd_session_t*) switch_core_media_bug_get_user_data(bug);
-            if (avmd_session == NULL) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Stop failed - no avmd session object on this channel [%s]!\n", switch_channel_get_name(channel));
-                goto end;
-            }
-            uuid_dup = switch_core_strdup(switch_core_session_get_pool(fs_session), uuid);
-            switch_channel_set_private(channel, "_avmd_", NULL);
-            switch_core_media_bug_remove(fs_session, &bug);
-            avmd_fire_event(AVMD_EVENT_SESSION_STOP, fs_session, 0, 0, 0, 0, 0, 0, 0, 0, avmd_session->start_time, avmd_session->stop_time, 0, 0, 0);
-            if (avmd_globals.settings.report_status == 1) {
-                stream->write_function(stream, "+OK\n [%s] [%s] stopped\n\n", uuid_dup, switch_channel_get_name(channel));
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_INFO, "Avmd on channel [%s] stopped!\n", switch_channel_get_name(channel));
-            }
-            goto end;
-        }
-        if (avmd_globals.settings.report_status == 1) {
-            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Avmd already started!\n");
-            stream->write_function(stream, "-ERR, avmd for FreeSWITCH session [%s]\n already started\n\n", uuid);
-        }
-        goto end;
-    }
-
-    if (strcasecmp(command, "stop") == 0) {
-        uuid_dup = switch_core_strdup(switch_core_session_get_pool(fs_session), uuid);
-        stream->write_function(stream, "+ERR, avmd has not yet been started on\n [%s] [%s]\n\n", uuid_dup, switch_channel_get_name(channel));
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Stop failed - avmd has not yet been started on channel [%s]!\n", switch_channel_get_name(channel));
-        goto end;
-    }
-    if ((SWITCH_CALL_DIRECTION_OUTBOUND == switch_channel_direction(channel)) && (avmd_globals.settings.outbound_channnel == 1)) {
-            flags |= SMBF_READ_REPLACE;
-    }
-    if ((SWITCH_CALL_DIRECTION_INBOUND == switch_channel_direction(channel)) && (avmd_globals.settings.inbound_channnel == 1)) {
-            flags |= SMBF_WRITE_REPLACE;
-    }
-    if (flags == 0) {
-        stream->write_function(stream, "-ERR, can't set direction for channel [%s]\n for FreeSWITCH session [%s]. Please check avmd configuration\n\n", switch_channel_get_name(channel), uuid);
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Can't set direction for channel [%s]\n", switch_channel_get_name(channel));
-        status = SWITCH_STATUS_FALSE;
-        goto end;
-    }
-    if ((SWITCH_CALL_DIRECTION_OUTBOUND == switch_channel_direction(channel)) && (avmd_globals.settings.outbound_channnel == 1)) {
-        if (switch_channel_test_flag(channel, CF_MEDIA_SET) == 0) {
-            stream->write_function(stream, "-ERR, channel [%s] for FreeSWITCH session [%s]\n has no read codec assigned yet. Please try again.\n\n", switch_channel_get_name(channel), uuid);
-            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Channel [%s] has no codec assigned yet. Please try again\n", switch_channel_get_name(channel));
-            status = SWITCH_STATUS_FALSE;
-            goto end;
-        }
-    }
-    if (strcasecmp(command, "start") != 0) { /* If we don't see the expected start exit */
-        stream->write_function(stream, "-ERR, did you mean\n api avmd %s start ?\n-USAGE: %s\n\n", uuid, AVMD_SYNTAX);
-        goto end;
-    }
-
-    avmd_session = (avmd_session_t *) switch_core_session_alloc(fs_session, sizeof(avmd_session_t)); /* Allocate memory attached to this FreeSWITCH session for use in the callback routine and to store state information */
-    status = init_avmd_session_data(avmd_session, fs_session, NULL);
-    if (status != SWITCH_STATUS_SUCCESS) {
-        stream->write_function(stream, "-ERR, failed to initialize avmd session\n for FreeSWITCH session [%s]\n", uuid);
-        switch (status) {
-            case SWITCH_STATUS_MEMERR:
-                stream->write_function(stream, "-ERR, buffer error\n\n");
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Failed to init avmd session. Buffer error!\n");
-                break;
-            case SWITCH_STATUS_MORE_DATA:
-                stream->write_function(stream, "-ERR, SMA buffer size is 0\n\n");
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Failed to init avmd session. SMA buffer size is 0!\n");
-                break;
-            case SWITCH_STATUS_FALSE:
-                stream->write_function(stream, "-ERR, SMA buffer error\n\n");
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Failed to init avmd session. SMA buffers error\n");
-                break;
-            default:
-                stream->write_function(stream, "-ERR, unknown error\n\n");
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Failed to init avmd session. Unknown error\n");
-                break;
-        }
-        goto end;
-    }
-
-    status = switch_core_media_bug_add(fs_session, "avmd", NULL, avmd_callback, avmd_session, 0, flags, &bug); /* Add a media bug that allows me to intercept the reading leg of the audio stream */
-
-    if (status != SWITCH_STATUS_SUCCESS) { /* If adding a media bug fails exit */
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Failed to add media bug!\n");
-        stream->write_function(stream, "-ERR, [%s] failed to add media bug!\n\n", uuid);
-        goto end;
-    }
-
-    switch_channel_set_private(channel, "_avmd_", bug); /* Set the vmd tag to detect an existing vmd media bug */
-
-    avmd_fire_event(AVMD_EVENT_SESSION_START, fs_session, 0, 0, 0, 0, 0, 0, 0, 0, avmd_session->start_time, 0, 0, 0, 0);
-    if (avmd_globals.settings.report_status == 1) {
-        stream->write_function(stream, "+OK\n [%s] [%s] started!\n\n", uuid, switch_channel_get_name(channel));
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_INFO, "Avmd on channel [%s] started!\n", switch_channel_get_name(channel));
-        switch_assert(status == SWITCH_STATUS_SUCCESS);
-    }
+       switch_media_bug_t *bug = NULL;
+       avmd_session_t *avmd_session = NULL;
+       switch_channel_t *channel = NULL;
+       int argc;
+       const char *uuid = NULL, *uuid_dup = NULL;
+       const char *command = NULL;
+       char *dupped = NULL, *argv[AVMD_PARAMS_API_MAX + 1] = { 0 };
+       switch_core_media_flag_t flags = 0;
+       switch_status_t status = SWITCH_STATUS_SUCCESS;
+       switch_core_session_t *fs_session = NULL;
+
+       switch_mutex_lock(avmd_globals.mutex);
+
+       if (zstr(cmd)) {
+               stream->write_function(stream, "-ERR, bad command!\n-USAGE: %s\n\n", AVMD_SYNTAX);
+               goto end;
+       }
+
+       dupped = strdup(cmd);
+       switch_assert(dupped);
+       argc = switch_separate_string((char*)dupped, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+
+       if (argc < AVMD_PARAMS_API_MIN) {
+               stream->write_function(stream, "-ERR, avmd takes [%u] min and [%u] max parameters!\n-USAGE: %s\n\n", AVMD_PARAMS_API_MIN, AVMD_PARAMS_API_MAX, AVMD_SYNTAX);
+               goto end;
+       }
+
+       command = argv[0];
+       if (strcasecmp(command, "reload") == 0) {
+               status = avmd_load_xml_configuration(NULL);
+               if (avmd_globals.settings.report_status == 1) {
+                       if (status != SWITCH_STATUS_SUCCESS) {
+                               stream->write_function(stream, "-ERR, couldn't reload XML configuration\n");
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't reload XML configuration\n");
+                       } else {
+                               stream->write_function(stream, "+OK\n XML reloaded\n\n");
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "XML reloaded\n");
+                       }
+                       goto end;
+               }
+       }
+       if (strcasecmp(command, "load") == 0) {
+               if (argc != 2) {
+                       stream->write_function(stream, "-ERR, load command takes 1 parameter!\n-USAGE: %s\n\n", AVMD_SYNTAX);
+                       goto end;
+               }
+               command = argv[1];
+               if (strcasecmp(command, "inbound") == 0) {
+                       status = avmd_load_xml_inbound_configuration(NULL);
+                       if (avmd_globals.settings.report_status == 1) {
+                               if (status != SWITCH_STATUS_SUCCESS) {
+                                       stream->write_function(stream, "-ERR, couldn't load XML configuration\n");
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't load XML configuration\n");
+                               } else {
+                                       stream->write_function(stream, "+OK\n inbound XML configuration loaded\n\n");
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Inbound XML configuration loaded\n");
+                               }
+                               goto end;
+                       }
+               } else if (strcasecmp(command, "outbound") == 0) {
+                       status = avmd_load_xml_outbound_configuration(NULL);
+                       if (avmd_globals.settings.report_status == 1) {
+                               if (status != SWITCH_STATUS_SUCCESS) {
+                                       stream->write_function(stream, "-ERR, couldn't load XML configuration\n");
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't load XML configuration\n");
+                               } else {
+                                       stream->write_function(stream, "+OK\n outbound XML configuration loaded\n\n");
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Outbound XML configuration loaded\n");
+                               }
+                               goto end;
+                       }
+               } else {
+                       stream->write_function(stream, "-ERR, load command: bad syntax!\n-USAGE: %s\n\n", AVMD_SYNTAX);
+               }
+               goto end;
+       }
+       if (strcasecmp(command, "set") == 0) {
+               if (argc != 2) {
+                       stream->write_function(stream, "-ERR, set command takes 1 parameter!\n-USAGE: %s\n\n", AVMD_SYNTAX);
+                       goto end;
+               }
+               command = argv[1];
+               if (strcasecmp(command, "inbound") == 0) {
+                       avmd_set_xml_inbound_configuration(NULL);
+                       if (avmd_globals.settings.report_status == 1) {
+                               stream->write_function(stream, "+OK\n inbound XML configuration loaded\n\n");
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Inbound XML configuration loaded\n");
+                       }
+               } else if (strcasecmp(command, "outbound") == 0) {
+                       avmd_set_xml_outbound_configuration(NULL);
+                       if (avmd_globals.settings.report_status == 1) {
+                               stream->write_function(stream, "+OK\n outbound XML configuration loaded\n\n");
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Outbound XML configuration loaded\n");
+                       }
+               } else if (strcasecmp(command, "default") == 0) {
+                       avmd_set_xml_default_configuration(NULL);
+                       if (avmd_globals.settings.report_status == 1) {
+                               stream->write_function(stream, "+OK\n reset to factory settings\n\n");
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Reset to factory settings\n");
+                       }
+               } else {
+                       stream->write_function(stream, "-ERR, set command: bad syntax!\n-USAGE: %s\n\n", AVMD_SYNTAX);
+               }
+               goto end;
+       }
+       if (strcasecmp(command, "show") == 0) {
+               avmd_show(stream, NULL);
+               if (avmd_globals.settings.report_status == 1) {
+                       stream->write_function(stream, "+OK\n show\n\n");
+               }
+               goto end;
+       }
+
+       uuid = argv[0];
+       command = argv[1];
+
+       fs_session = switch_core_session_locate(uuid);  /* using uuid locate a reference to the FreeSWITCH session */
+       if (fs_session == NULL) {
+               stream->write_function(stream, "-ERR, no FreeSWITCH session for uuid [%s]!\n-USAGE: %s\n\n", uuid, AVMD_SYNTAX);
+               goto end;
+       }
+
+       /* Get current channel of the session to tag the session. This indicates that our module is present
+        * At this moment this cannot return NULL, it will either succeed or assert failed, but we make ourself secure anyway */
+       channel = switch_core_session_get_channel(fs_session);
+       if (channel == NULL) {
+               stream->write_function(stream, "-ERR, no channel for FreeSWITCH session [%s]!\n Please report this to the developers\n\n", uuid);
+               goto end;
+       }
+
+       bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_avmd_");
+       if (bug != NULL) {
+               if (strcasecmp(command, "stop") == 0) {
+                       avmd_session = (avmd_session_t*) switch_core_media_bug_get_user_data(bug);
+                       if (avmd_session == NULL) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Stop failed - no avmd session object on this channel [%s]!\n", switch_channel_get_name(channel));
+                               goto end;
+                       }
+                       uuid_dup = switch_core_strdup(switch_core_session_get_pool(fs_session), uuid);
+                       switch_channel_set_private(channel, "_avmd_", NULL);
+                       switch_core_media_bug_remove(fs_session, &bug);
+                       avmd_fire_event(AVMD_EVENT_SESSION_STOP, fs_session, 0, 0, 0, 0, 0, 0, 0, 0, avmd_session->start_time, avmd_session->stop_time, 0, 0, 0);
+                       if (avmd_globals.settings.report_status == 1) {
+                               stream->write_function(stream, "+OK\n [%s] [%s] stopped\n\n", uuid_dup, switch_channel_get_name(channel));
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_INFO, "Avmd on channel [%s] stopped!\n", switch_channel_get_name(channel));
+                       }
+                       goto end;
+               }
+               if (avmd_globals.settings.report_status == 1) {
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Avmd already started!\n");
+                       stream->write_function(stream, "-ERR, avmd for FreeSWITCH session [%s]\n already started\n\n", uuid);
+               }
+               goto end;
+       }
+
+       if (strcasecmp(command, "stop") == 0) {
+               uuid_dup = switch_core_strdup(switch_core_session_get_pool(fs_session), uuid);
+               stream->write_function(stream, "+ERR, avmd has not yet been started on\n [%s] [%s]\n\n", uuid_dup, switch_channel_get_name(channel));
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Stop failed - avmd has not yet been started on channel [%s]!\n", switch_channel_get_name(channel));
+               goto end;
+       }
+       if ((SWITCH_CALL_DIRECTION_OUTBOUND == switch_channel_direction(channel)) && (avmd_globals.settings.outbound_channnel == 1)) {
+                       flags |= SMBF_READ_REPLACE;
+       }
+       if ((SWITCH_CALL_DIRECTION_INBOUND == switch_channel_direction(channel)) && (avmd_globals.settings.inbound_channnel == 1)) {
+                       flags |= SMBF_WRITE_REPLACE;
+       }
+       if (flags == 0) {
+               stream->write_function(stream, "-ERR, can't set direction for channel [%s]\n for FreeSWITCH session [%s]. Please check avmd configuration\n\n", switch_channel_get_name(channel), uuid);
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Can't set direction for channel [%s]\n", switch_channel_get_name(channel));
+               status = SWITCH_STATUS_FALSE;
+               goto end;
+       }
+       if ((SWITCH_CALL_DIRECTION_OUTBOUND == switch_channel_direction(channel)) && (avmd_globals.settings.outbound_channnel == 1)) {
+               if (switch_channel_test_flag(channel, CF_MEDIA_SET) == 0) {
+                       stream->write_function(stream, "-ERR, channel [%s] for FreeSWITCH session [%s]\n has no read codec assigned yet. Please try again.\n\n", switch_channel_get_name(channel), uuid);
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Channel [%s] has no codec assigned yet. Please try again\n", switch_channel_get_name(channel));
+                       status = SWITCH_STATUS_FALSE;
+                       goto end;
+               }
+       }
+       if (strcasecmp(command, "start") != 0) { /* If we don't see the expected start exit */
+               stream->write_function(stream, "-ERR, did you mean\n api avmd %s start ?\n-USAGE: %s\n\n", uuid, AVMD_SYNTAX);
+               goto end;
+       }
+
+       avmd_session = (avmd_session_t *) switch_core_session_alloc(fs_session, sizeof(avmd_session_t)); /* Allocate memory attached to this FreeSWITCH session for use in the callback routine and to store state information */
+       status = init_avmd_session_data(avmd_session, fs_session, NULL);
+       if (status != SWITCH_STATUS_SUCCESS) {
+               stream->write_function(stream, "-ERR, failed to initialize avmd session\n for FreeSWITCH session [%s]\n", uuid);
+               switch (status) {
+                       case SWITCH_STATUS_MEMERR:
+                               stream->write_function(stream, "-ERR, buffer error\n\n");
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Failed to init avmd session. Buffer error!\n");
+                               break;
+                       case SWITCH_STATUS_MORE_DATA:
+                               stream->write_function(stream, "-ERR, SMA buffer size is 0\n\n");
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Failed to init avmd session. SMA buffer size is 0!\n");
+                               break;
+                       case SWITCH_STATUS_FALSE:
+                               stream->write_function(stream, "-ERR, SMA buffer error\n\n");
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Failed to init avmd session. SMA buffers error\n");
+                               break;
+                       default:
+                               stream->write_function(stream, "-ERR, unknown error\n\n");
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Failed to init avmd session. Unknown error\n");
+                               break;
+               }
+               goto end;
+       }
+
+       status = switch_core_media_bug_add(fs_session, "avmd", NULL, avmd_callback, avmd_session, 0, flags, &bug); /* Add a media bug that allows me to intercept the reading leg of the audio stream */
+
+       if (status != SWITCH_STATUS_SUCCESS) { /* If adding a media bug fails exit */
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR, "Failed to add media bug!\n");
+               stream->write_function(stream, "-ERR, [%s] failed to add media bug!\n\n", uuid);
+               goto end;
+       }
+
+       switch_channel_set_private(channel, "_avmd_", bug); /* Set the vmd tag to detect an existing vmd media bug */
+
+       avmd_fire_event(AVMD_EVENT_SESSION_START, fs_session, 0, 0, 0, 0, 0, 0, 0, 0, avmd_session->start_time, 0, 0, 0, 0);
+       if (avmd_globals.settings.report_status == 1) {
+               stream->write_function(stream, "+OK\n [%s] [%s] started!\n\n", uuid, switch_channel_get_name(channel));
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_INFO, "Avmd on channel [%s] started!\n", switch_channel_get_name(channel));
+               switch_assert(status == SWITCH_STATUS_SUCCESS);
+       }
 end:
 
-    if (status != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_INFO, "AVMD session NOT started\n");
-            if (avmd_globals.settings.report_status == 1) {
-                if ((uuid != NULL) && (channel != NULL)) {
-                    stream->write_function(stream, "+ERR\n [%s] [%s] NOT started!\n\n", uuid, switch_channel_get_name(channel));
-                } else {
-                    stream->write_function(stream, "+ERR\n AVMD session NOT started!\n\n", switch_channel_get_name(channel));
-                }
-            }
-    }
-    if (fs_session) {
-        switch_core_session_rwunlock(fs_session);
-    }
-
-    switch_safe_free(dupped);
-
-    switch_mutex_unlock(avmd_globals.mutex);
-
-    return SWITCH_STATUS_SUCCESS;
+       if (status != SWITCH_STATUS_SUCCESS) {
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_INFO, "AVMD session NOT started\n");
+                       if (avmd_globals.settings.report_status == 1) {
+                               if ((uuid != NULL) && (channel != NULL)) {
+                                       stream->write_function(stream, "+ERR\n [%s] [%s] NOT started!\n\n", uuid, switch_channel_get_name(channel));
+                               } else {
+                                       stream->write_function(stream, "+ERR\n AVMD session NOT started!\n\n", switch_channel_get_name(channel));
+                               }
+                       }
+       }
+       if (fs_session) {
+               switch_core_session_rwunlock(fs_session);
+       }
+
+       switch_safe_free(dupped);
+
+       switch_mutex_unlock(avmd_globals.mutex);
+
+       return SWITCH_STATUS_SUCCESS;
 }
 
 static int
 avmd_decision_amplitude(const avmd_session_t *s, const struct avmd_buffer *b, double v, double rsd_threshold) {
-    double a, rsd;
-    size_t lpos;
-
-    lpos = b->sma_b.lpos;
-    if ((lpos >= AVMD_BEEP_LEN(s->rate) / b->resolution) && ((s->settings.require_continuous_streak_amp == 1 && (b->sma_amp_b.lpos > s->settings.sample_n_continuous_streak_amp) && (b->samples_streak_amp == 0))
-            || (s->settings.require_continuous_streak_amp == 0 && (b->sma_amp_b.lpos > 1)))) {
-        a = fabs(b->sma_amp_b.sma);
-        if (a < AVMD_MIN_AMP) {
-            return 0;
-        }
-        rsd = sqrt(v) / a;
-        if (rsd < rsd_threshold) {
-            return 1;
-        }
-    }
-    return 0;
+       double a, rsd;
+       size_t lpos;
+
+       lpos = b->sma_b.lpos;
+       if ((lpos >= AVMD_BEEP_LEN(s->rate) / b->resolution) && ((s->settings.require_continuous_streak_amp == 1 && (b->sma_amp_b.lpos > s->settings.sample_n_continuous_streak_amp) && (b->samples_streak_amp == 0))
+                       || (s->settings.require_continuous_streak_amp == 0 && (b->sma_amp_b.lpos > 1)))) {
+               a = fabs(b->sma_amp_b.sma);
+               if (a < AVMD_MIN_AMP) {
+                       return 0;
+               }
+               rsd = sqrt(v) / a;
+               if (rsd < rsd_threshold) {
+                       return 1;
+               }
+       }
+       return 0;
 }
 
 static int
 avmd_decision_freq(const avmd_session_t *s, const struct avmd_buffer *b, double v, double rsd_threshold) {
-    double f, rsd;
-    size_t lpos;
-    f = AVMD_TO_HZ(s->rate, fabs(b->sma_b_fir.sma));
-    if ((f < AVMD_MIN_FREQUENCY) || (f > AVMD_MAX_FREQUENCY)) {
-        return 0;
-    }
-    lpos = b->sma_b.lpos;
-    if ((lpos >= AVMD_BEEP_LEN(s->rate) / b->resolution) && ((s->settings.require_continuous_streak == 1 && (b->sma_b.lpos > s->settings.sample_n_continuous_streak) && (b->samples_streak == 0))
-            || (s->settings.require_continuous_streak == 0 && (b->sma_b.lpos > 1)))) {
-        rsd = sqrt(v) / f;
-        if ((rsd < 0.3 * rsd_threshold) && (b->sma_amp_b.sma >= 0.005 * b->amplitude_max)) {
-            return 1;
-        }
-        if ((rsd < 0.6 * rsd_threshold) && (b->sma_amp_b.sma >= 0.01 * b->amplitude_max)) {
-            return 1;
-        }
-        if ((rsd < rsd_threshold) && (b->sma_amp_b.sma >= 0.015 * b->amplitude_max)) {
-            return 1;
-        }
-    }
-    return 0;
+       double f, rsd;
+       size_t lpos;
+       f = AVMD_TO_HZ(s->rate, fabs(b->sma_b_fir.sma));
+       if ((f < AVMD_MIN_FREQUENCY) || (f > AVMD_MAX_FREQUENCY)) {
+               return 0;
+       }
+       lpos = b->sma_b.lpos;
+       if ((lpos >= AVMD_BEEP_LEN(s->rate) / b->resolution) && ((s->settings.require_continuous_streak == 1 && (b->sma_b.lpos > s->settings.sample_n_continuous_streak) && (b->samples_streak == 0))
+                       || (s->settings.require_continuous_streak == 0 && (b->sma_b.lpos > 1)))) {
+               rsd = sqrt(v) / f;
+               if ((rsd < 0.3 * rsd_threshold) && (b->sma_amp_b.sma >= 0.005 * b->amplitude_max)) {
+                       return 1;
+               }
+               if ((rsd < 0.6 * rsd_threshold) && (b->sma_amp_b.sma >= 0.01 * b->amplitude_max)) {
+                       return 1;
+               }
+               if ((rsd < rsd_threshold) && (b->sma_amp_b.sma >= 0.015 * b->amplitude_max)) {
+                       return 1;
+               }
+       }
+       return 0;
 }
 
 static void avmd_report_detection(avmd_session_t *s, enum avmd_detection_mode mode, const struct avmd_detector *d) {
-    switch_channel_t    *channel;
-    switch_time_t       detection_time;
-    double      f_sma = 0.0;
-    double      v_amp = 9999.9, v_fir = 9999.9;
-
-    const struct avmd_buffer *b = &d->buffer;
-    const sma_buffer_t    *sma_b_fir = &b->sma_b_fir;
-    const sma_buffer_t    *sqa_b_fir = &b->sqa_b_fir;
-
-    const sma_buffer_t    *sma_amp_b = &b->sma_amp_b;
-    const sma_buffer_t    *sqa_amp_b = &b->sqa_amp_b;
-
-    channel = switch_core_session_get_channel(s->session);
-
-    s->detection_stop_time = switch_micro_time_now();                                                           /* stop detection timer     */
-    detection_time = s->detection_stop_time - s->detection_start_time;                                          /* detection time length    */
-    switch_channel_set_variable_printf(channel, "avmd_total_time", "[%" PRId64 "]", detection_time / 1000);
-    switch_channel_execute_on(channel, "execute_on_avmd_beep");
-    switch_channel_set_variable(channel, "avmd_detect", "TRUE");
-    switch (mode) {
-
-        case AVMD_DETECT_AMP:
-            v_amp = sqa_amp_b->sma - (sma_amp_b->sma * sma_amp_b->sma);                                               /* calculate variance of amplitude (biased estimator) */
-            avmd_fire_event(AVMD_EVENT_BEEP, s->session, 0, 0, sma_amp_b->sma, v_amp, 0, 0, s->detection_start_time, s->detection_stop_time, 0, 0, b->resolution, b->offset, d->idx);
-            if (s->settings.report_status == 1) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_INFO, "<<< AVMD - Beep Detected [%u][%u][%u][%u]: amplitude = [%f](max [%f]) variance = [%f], detection time [%" PRId64 "] [us] >>>\n",
-                        mode, b->resolution, b->offset, d->idx, sma_amp_b->sma, b->amplitude_max, v_amp, detection_time);
-            }
-            break;
-
-        case AVMD_DETECT_FREQ:
-            f_sma = sma_b_fir->sma;
-            v_fir = sqa_b_fir->sma - (sma_b_fir->sma * sma_b_fir->sma);                                               /* calculate variance of filtered samples */
-            avmd_fire_event(AVMD_EVENT_BEEP, s->session, AVMD_TO_HZ(s->rate, f_sma), v_fir, 0, 0, 0, 0, s->detection_start_time, s->detection_stop_time, 0, 0, b->resolution, b->offset, d->idx);
-            if (s->settings.report_status == 1) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_INFO, "<<< AVMD - Beep Detected [%u][%u][%u][%u]: f = [%f] variance = [%f], detection time [%" PRId64 "] [us] >>>\n",
-                        mode, b->resolution, b->offset, d->idx, AVMD_TO_HZ(s->rate, f_sma), v_fir, detection_time);
-            }
-            break;
-
-        case AVMD_DETECT_BOTH:
-            v_amp = sqa_amp_b->sma - (sma_amp_b->sma * sma_amp_b->sma);                                               /* calculate variance of amplitude (biased estimator) */
-            f_sma = sma_b_fir->sma;
-            v_fir = sqa_b_fir->sma - (sma_b_fir->sma * sma_b_fir->sma);                                               /* calculate variance of filtered samples */
-            avmd_fire_event(AVMD_EVENT_BEEP, s->session, AVMD_TO_HZ(s->rate, f_sma), v_fir, sma_amp_b->sma, v_amp, 0, 0, s->detection_start_time, s->detection_stop_time, 0, 0, b->resolution, b->offset, d->idx);
-            if (s->settings.report_status == 1) {
-                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_INFO, "<<< AVMD - Beep Detected [%u][%u][%u][%u]: f = [%f] variance = [%f], amplitude = [%f](max [%f]) variance = [%f], detection time [%" PRId64 "] [us] >>>\n",
-                        mode, b->resolution, b->offset, d->idx, AVMD_TO_HZ(s->rate, f_sma), v_fir, sma_amp_b->sma, b->amplitude_max, v_amp, detection_time);
-            }
-            break;
-
-        default:
-            break;
-    }
-    s->state.beep_state = BEEP_DETECTED;
+       switch_channel_t *channel;
+       switch_time_t detection_time;
+       double f_sma = 0.0;
+       double v_amp = 9999.9, v_fir = 9999.9;
+
+       const struct avmd_buffer *b = &d->buffer;
+       const sma_buffer_t *sma_b_fir = &b->sma_b_fir;
+       const sma_buffer_t *sqa_b_fir = &b->sqa_b_fir;
+
+       const sma_buffer_t *sma_amp_b = &b->sma_amp_b;
+       const sma_buffer_t *sqa_amp_b = &b->sqa_amp_b;
+
+       channel = switch_core_session_get_channel(s->session);
+
+       s->detection_stop_time = switch_micro_time_now();                                                                                                                  /* stop detection timer       */
+       detection_time = s->detection_stop_time - s->detection_start_time;                                                                                /* detection time length      */
+       switch_channel_set_variable_printf(channel, "avmd_total_time", "[%" PRId64 "]", detection_time / 1000);
+       switch_channel_execute_on(channel, "execute_on_avmd_beep");
+       switch_channel_set_variable(channel, "avmd_detect", "TRUE");
+       switch (mode) {
+
+               case AVMD_DETECT_AMP:
+                       v_amp = sqa_amp_b->sma - (sma_amp_b->sma * sma_amp_b->sma);                                                                                        /* calculate variance of amplitude (biased estimator) */
+                       avmd_fire_event(AVMD_EVENT_BEEP, s->session, 0, 0, sma_amp_b->sma, v_amp, 0, 0, s->detection_start_time, s->detection_stop_time, 0, 0, b->resolution, b->offset, d->idx);
+                       if (s->settings.report_status == 1) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_INFO, "<<< AVMD - Beep Detected [%u][%u][%u][%u]: amplitude = [%f](max [%f]) variance = [%f], detection time [%" PRId64 "] [us] >>>\n",
+                                               mode, b->resolution, b->offset, d->idx, sma_amp_b->sma, b->amplitude_max, v_amp, detection_time);
+                       }
+                       break;
+
+               case AVMD_DETECT_FREQ:
+                       f_sma = sma_b_fir->sma;
+                       v_fir = sqa_b_fir->sma - (sma_b_fir->sma * sma_b_fir->sma);                                                                                        /* calculate variance of filtered samples */
+                       avmd_fire_event(AVMD_EVENT_BEEP, s->session, AVMD_TO_HZ(s->rate, f_sma), v_fir, 0, 0, 0, 0, s->detection_start_time, s->detection_stop_time, 0, 0, b->resolution, b->offset, d->idx);
+                       if (s->settings.report_status == 1) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_INFO, "<<< AVMD - Beep Detected [%u][%u][%u][%u]: f = [%f] variance = [%f], detection time [%" PRId64 "] [us] >>>\n",
+                                               mode, b->resolution, b->offset, d->idx, AVMD_TO_HZ(s->rate, f_sma), v_fir, detection_time);
+                       }
+                       break;
+
+               case AVMD_DETECT_BOTH:
+                       v_amp = sqa_amp_b->sma - (sma_amp_b->sma * sma_amp_b->sma);                                                                                        /* calculate variance of amplitude (biased estimator) */
+                       f_sma = sma_b_fir->sma;
+                       v_fir = sqa_b_fir->sma - (sma_b_fir->sma * sma_b_fir->sma);                                                                                        /* calculate variance of filtered samples */
+                       avmd_fire_event(AVMD_EVENT_BEEP, s->session, AVMD_TO_HZ(s->rate, f_sma), v_fir, sma_amp_b->sma, v_amp, 0, 0, s->detection_start_time, s->detection_stop_time, 0, 0, b->resolution, b->offset, d->idx);
+                       if (s->settings.report_status == 1) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_INFO, "<<< AVMD - Beep Detected [%u][%u][%u][%u]: f = [%f] variance = [%f], amplitude = [%f](max [%f]) variance = [%f], detection time [%" PRId64 "] [us] >>>\n",
+                                               mode, b->resolution, b->offset, d->idx, AVMD_TO_HZ(s->rate, f_sma), v_fir, sma_amp_b->sma, b->amplitude_max, v_amp, detection_time);
+                       }
+                       break;
+
+               default:
+                       break;
+       }
+       s->state.beep_state = BEEP_DETECTED;
 }
 
 static uint8_t
 avmd_detection_in_progress(avmd_session_t *s) {
-    uint8_t idx = 0;
-    while (idx < (s->settings.detectors_n + s->settings.detectors_lagged_n)) {
-        switch_mutex_lock(s->detectors[idx].mutex);
-        if (s->detectors[idx].flag_processing_done == 0) {
-            switch_mutex_unlock(s->detectors[idx].mutex);
-            return 1;
-        }
-        switch_mutex_unlock(s->detectors[idx].mutex);
-        ++idx;
-    }
-    return 0;
+       uint8_t idx = 0;
+       while (idx < (s->settings.detectors_n + s->settings.detectors_lagged_n)) {
+               switch_mutex_lock(s->detectors[idx].mutex);
+               if (s->detectors[idx].flag_processing_done == 0) {
+                       switch_mutex_unlock(s->detectors[idx].mutex);
+                       return 1;
+               }
+               switch_mutex_unlock(s->detectors[idx].mutex);
+               ++idx;
+       }
+       return 0;
 }
 
 static enum avmd_detection_mode
 avmd_detection_result(avmd_session_t *s) {
-    enum avmd_detection_mode res;
-    uint8_t idx = 0;
-    while (idx < (s->settings.detectors_n + s->settings.detectors_lagged_n)) {
-        res = s->detectors[idx].result;
-        if (res != AVMD_DETECT_NONE) {
-            avmd_report_detection(s, res, &s->detectors[idx]);
-            return res;
-        }
-        ++idx;
-    }
-    return AVMD_DETECT_NONE;
+       enum avmd_detection_mode res;
+       uint8_t idx = 0;
+       while (idx < (s->settings.detectors_n + s->settings.detectors_lagged_n)) {
+               res = s->detectors[idx].result;
+               if (res != AVMD_DETECT_NONE) {
+                       avmd_report_detection(s, res, &s->detectors[idx]);
+                       return res;
+               }
+               ++idx;
+       }
+       return AVMD_DETECT_NONE;
 }
 
 /*! \brief Process one frame of data with avmd algorithm.
@@ -2051,258 +2051,258 @@ avmd_detection_result(avmd_session_t *s) {
  * @param frame An audio frame.
  */
 static void avmd_process(avmd_session_t *s, switch_frame_t *frame, uint8_t direction) {
-    circ_buffer_t           *b;
-    uint8_t                 idx;
-    struct avmd_detector    *d;
+       circ_buffer_t *b;
+       uint8_t idx;
+       struct avmd_detector *d;
 
 
-    b = &s->b;
+       b = &s->b;
 
-    switch_mutex_lock(s->mutex_detectors_done);
-    while (avmd_detection_in_progress(s) == 1) {
-        switch_thread_cond_wait(s->cond_detectors_done, s->mutex_detectors_done);
-    }
-    switch_mutex_unlock(s->mutex_detectors_done);
+       switch_mutex_lock(s->mutex_detectors_done);
+       while (avmd_detection_in_progress(s) == 1) {
+               switch_thread_cond_wait(s->cond_detectors_done, s->mutex_detectors_done);
+       }
+       switch_mutex_unlock(s->mutex_detectors_done);
 
-    if (s->state.beep_state == BEEP_DETECTED) {                         /* If beep has already been detected skip the CPU heavy stuff */
-        return;
-    }
+       if (s->state.beep_state == BEEP_DETECTED) {                                              /* If beep has already been detected skip the CPU heavy stuff */
+               return;
+       }
 
-    if (s->frame_n_to_skip > 0) {
-        s->frame_n_to_skip--;
-        return;
-    }
+       if (s->frame_n_to_skip > 0) {
+               s->frame_n_to_skip--;
+               return;
+       }
 
        if (s->settings.debug) {
                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_INFO, "AVMD: processing frame [%zu], direction=%s\n", s->frame_n, direction == AVMD_READ_REPLACE ? "READ" : "WRITE");
        }
 
-    if (s->detection_start_time == 0) {
-        s->detection_start_time = switch_micro_time_now();              /* start detection timer */
-    }
-
-    INSERT_INT16_FRAME(b, (int16_t *)(frame->data), frame->samples);    /* Insert frame of 16 bit samples into buffer */
-
-    idx = 0;
-    while (idx < (s->settings.detectors_n + s->settings.detectors_lagged_n)) {
-        d = &s->detectors[idx];
-        switch_mutex_lock(d->mutex);
-        d = &s->detectors[idx];
-        if (d->result == AVMD_DETECT_NONE) {
-            d->flag_processing_done = 0;
-            d->flag_should_exit = 0;
-            d->samples = (s->frame_n == 0 ? frame->samples - AVMD_P : frame->samples);
-            switch_thread_cond_signal(d->cond_start_processing);
-        }
-        switch_mutex_unlock(d->mutex);
-        ++idx;
-    }
-
-    switch_mutex_lock(s->mutex_detectors_done);
-    while (avmd_detection_in_progress(s) == 1) {
-        switch_thread_cond_wait(s->cond_detectors_done, s->mutex_detectors_done);
-    }
-    avmd_detection_result(s);
-    switch_mutex_unlock(s->mutex_detectors_done);
-
-    ++s->frame_n;
-    if (s->frame_n == 1) {
-        s->pos += frame->samples - AVMD_P;
-    } else {
-        s->pos += frame->samples;
-    }
-    s->pos &= b->mask;
-
-    return;
+       if (s->detection_start_time == 0) {
+               s->detection_start_time = switch_micro_time_now();                        /* start detection timer */
+       }
+
+       INSERT_INT16_FRAME(b, (int16_t *)(frame->data), frame->samples);        /* Insert frame of 16 bit samples into buffer */
+
+       idx = 0;
+       while (idx < (s->settings.detectors_n + s->settings.detectors_lagged_n)) {
+               d = &s->detectors[idx];
+               switch_mutex_lock(d->mutex);
+               d = &s->detectors[idx];
+               if (d->result == AVMD_DETECT_NONE) {
+                       d->flag_processing_done = 0;
+                       d->flag_should_exit = 0;
+                       d->samples = (s->frame_n == 0 ? frame->samples - AVMD_P : frame->samples);
+                       switch_thread_cond_signal(d->cond_start_processing);
+               }
+               switch_mutex_unlock(d->mutex);
+               ++idx;
+       }
+
+       switch_mutex_lock(s->mutex_detectors_done);
+       while (avmd_detection_in_progress(s) == 1) {
+               switch_thread_cond_wait(s->cond_detectors_done, s->mutex_detectors_done);
+       }
+       avmd_detection_result(s);
+       switch_mutex_unlock(s->mutex_detectors_done);
+
+       ++s->frame_n;
+       if (s->frame_n == 1) {
+               s->pos += frame->samples - AVMD_P;
+       } else {
+               s->pos += frame->samples;
+       }
+       s->pos &= b->mask;
+
+       return;
 }
 
 static void avmd_reloadxml_event_handler(switch_event_t *event) {
-    avmd_load_xml_configuration(avmd_globals.mutex);
+       avmd_load_xml_configuration(avmd_globals.mutex);
 }
 
 static enum avmd_detection_mode avmd_process_sample(avmd_session_t *s, circ_buffer_t *b, size_t sample_n, size_t pos, struct avmd_detector *d) {
-    struct avmd_buffer          *buffer = &d->buffer;
-    uint16_t                    sample_to_skip_n = s->settings.sample_n_to_skip;
-    enum avmd_detection_mode    mode = s->settings.mode;
-    uint8_t     valid_amplitude = 1, valid_omega = 1;
-    double      omega = 0.0, amplitude = 0.0;
-    double      f = 0.0, f_fir = 0.0;
-    double      v_amp = 9999.9, v_fir = 9999.9;
-
-    sma_buffer_t    *sma_b = &buffer->sma_b;
-    sma_buffer_t    *sqa_b = &buffer->sqa_b;
-
-    sma_buffer_t    *sma_b_fir = &buffer->sma_b_fir;
-    sma_buffer_t    *sqa_b_fir = &buffer->sqa_b_fir;
-
-    sma_buffer_t    *sma_amp_b = &buffer->sma_amp_b;
-    sma_buffer_t    *sqa_amp_b = &buffer->sqa_amp_b;
-
-    if (sample_to_skip_n > 0) {
-        sample_to_skip_n--;
-        valid_amplitude = 0;
-        valid_omega = 0;
-        return AVMD_DETECT_NONE;
-    }
-
-    omega = avmd_desa2_tweaked(b, pos + sample_n, &amplitude);
-
-    if (mode == AVMD_DETECT_AMP || mode == AVMD_DETECT_BOTH) {
-        if (ISNAN(amplitude) || ISINF(amplitude)) {
-            valid_amplitude = 0;
-            if (s->settings.require_continuous_streak_amp == 1) {
-                RESET_SMA_BUFFER(sma_amp_b);
-                RESET_SMA_BUFFER(sqa_amp_b);
-                buffer->samples_streak_amp = s->settings.sample_n_continuous_streak_amp;
-                sample_to_skip_n = s->settings.sample_n_to_skip;
-            }
-        } else {
-            if (ISINF(amplitude)) {
-                amplitude = buffer->amplitude_max;
-            }
-            if (valid_amplitude == 1) {
-                APPEND_SMA_VAL(sma_amp_b, amplitude);               /* append amplitude */
-                APPEND_SMA_VAL(sqa_amp_b, amplitude * amplitude);
-                if (s->settings.require_continuous_streak_amp == 1) {
-                    if (buffer->samples_streak_amp > 0) {
-                        --buffer->samples_streak_amp;
-                        valid_amplitude = 0;
-                    }
-                }
-            }
-            if (sma_amp_b->sma > buffer->amplitude_max) {
-                buffer->amplitude_max = sma_amp_b->sma;
-            }
-        }
-    }
-
-    if (mode == AVMD_DETECT_FREQ || mode == AVMD_DETECT_BOTH) {
-        if (ISNAN(omega)) {
-            valid_omega = 0;
-            if (s->settings.require_continuous_streak == 1) {
-                RESET_SMA_BUFFER(sma_b);
-                RESET_SMA_BUFFER(sqa_b);
-                RESET_SMA_BUFFER(sma_b_fir);
-                RESET_SMA_BUFFER(sqa_b_fir);
-                buffer->samples_streak = s->settings.sample_n_continuous_streak;
-                sample_to_skip_n = s->settings.sample_n_to_skip;
-            }
-            sample_to_skip_n = s->settings.sample_n_to_skip;
-        } else if (omega < -0.99999 || omega > 0.99999) {
-            valid_omega = 0;
-            if (s->settings.require_continuous_streak == 1) {
-                RESET_SMA_BUFFER(sma_b);
-                RESET_SMA_BUFFER(sqa_b);
-                RESET_SMA_BUFFER(sma_b_fir);
-                RESET_SMA_BUFFER(sqa_b_fir);
-                buffer->samples_streak = s->settings.sample_n_continuous_streak;
-                sample_to_skip_n = s->settings.sample_n_to_skip;
-            }
-        } else {
-            if (valid_omega) {
+       struct avmd_buffer *buffer = &d->buffer;
+       uint16_t sample_to_skip_n = s->settings.sample_n_to_skip;
+       enum avmd_detection_mode mode = s->settings.mode;
+       uint8_t valid_amplitude = 1, valid_omega = 1;
+       double omega = 0.0, amplitude = 0.0;
+       double f = 0.0, f_fir = 0.0;
+       double v_amp = 9999.9, v_fir = 9999.9;
+
+       sma_buffer_t *sma_b = &buffer->sma_b;
+       sma_buffer_t *sqa_b = &buffer->sqa_b;
+
+       sma_buffer_t *sma_b_fir = &buffer->sma_b_fir;
+       sma_buffer_t *sqa_b_fir = &buffer->sqa_b_fir;
+
+       sma_buffer_t *sma_amp_b = &buffer->sma_amp_b;
+       sma_buffer_t *sqa_amp_b = &buffer->sqa_amp_b;
+
+       if (sample_to_skip_n > 0) {
+               sample_to_skip_n--;
+               valid_amplitude = 0;
+               valid_omega = 0;
+               return AVMD_DETECT_NONE;
+       }
+
+       omega = avmd_desa2_tweaked(b, pos + sample_n, &amplitude);
+
+       if (mode == AVMD_DETECT_AMP || mode == AVMD_DETECT_BOTH) {
+               if (ISNAN(amplitude) || ISINF(amplitude)) {
+                       valid_amplitude = 0;
+                       if (s->settings.require_continuous_streak_amp == 1) {
+                               RESET_SMA_BUFFER(sma_amp_b);
+                               RESET_SMA_BUFFER(sqa_amp_b);
+                               buffer->samples_streak_amp = s->settings.sample_n_continuous_streak_amp;
+                               sample_to_skip_n = s->settings.sample_n_to_skip;
+                       }
+               } else {
+                       if (ISINF(amplitude)) {
+                               amplitude = buffer->amplitude_max;
+                       }
+                       if (valid_amplitude == 1) {
+                               APPEND_SMA_VAL(sma_amp_b, amplitude);                      /* append amplitude */
+                               APPEND_SMA_VAL(sqa_amp_b, amplitude * amplitude);
+                               if (s->settings.require_continuous_streak_amp == 1) {
+                                       if (buffer->samples_streak_amp > 0) {
+                                               --buffer->samples_streak_amp;
+                                               valid_amplitude = 0;
+                                       }
+                               }
+                       }
+                       if (sma_amp_b->sma > buffer->amplitude_max) {
+                               buffer->amplitude_max = sma_amp_b->sma;
+                       }
+               }
+       }
+
+       if (mode == AVMD_DETECT_FREQ || mode == AVMD_DETECT_BOTH) {
+               if (ISNAN(omega)) {
+                       valid_omega = 0;
+                       if (s->settings.require_continuous_streak == 1) {
+                               RESET_SMA_BUFFER(sma_b);
+                               RESET_SMA_BUFFER(sqa_b);
+                               RESET_SMA_BUFFER(sma_b_fir);
+                               RESET_SMA_BUFFER(sqa_b_fir);
+                               buffer->samples_streak = s->settings.sample_n_continuous_streak;
+                               sample_to_skip_n = s->settings.sample_n_to_skip;
+                       }
+                       sample_to_skip_n = s->settings.sample_n_to_skip;
+               } else if (omega < -0.99999 || omega > 0.99999) {
+                       valid_omega = 0;
+                       if (s->settings.require_continuous_streak == 1) {
+                               RESET_SMA_BUFFER(sma_b);
+                               RESET_SMA_BUFFER(sqa_b);
+                               RESET_SMA_BUFFER(sma_b_fir);
+                               RESET_SMA_BUFFER(sqa_b_fir);
+                               buffer->samples_streak = s->settings.sample_n_continuous_streak;
+                               sample_to_skip_n = s->settings.sample_n_to_skip;
+                       }
+               } else {
+                       if (valid_omega) {
 
 #if !defined(WIN32) && defined(AVMD_FAST_MATH)
-                f =  0.5 * (double) fast_acosf((float)omega);
+                               f =  0.5 * (double) fast_acosf((float)omega);
 #else
-                f = 0.5 * acos(omega);
+                               f = 0.5 * acos(omega);
 #endif /* !WIN32 && AVMD_FAST_MATH */
-                f_fir = sma_b->pos > 1 ? (AVMD_MEDIAN_FILTER(sma_b->data[sma_b->pos - 2], sma_b->data[sma_b->pos - 1], f)) : f;
-
-                APPEND_SMA_VAL(sma_b, f);                                                                           /* append frequency             */
-                APPEND_SMA_VAL(sqa_b, f * f);
-                APPEND_SMA_VAL(sma_b_fir, f_fir);                                                                   /* append filtered frequency    */
-                APPEND_SMA_VAL(sqa_b_fir, f_fir * f_fir);
-                if (s->settings.require_continuous_streak == 1) {
-                    if (buffer->samples_streak > 0) {
-                        --buffer->samples_streak;
-                        valid_omega = 0;
-                    }
-                }
-            }
-        }
-    }
-
-    if (((mode == AVMD_DETECT_AMP) || (mode == AVMD_DETECT_BOTH)) && (valid_amplitude == 1)) {
-        v_amp = sqa_amp_b->sma - (sma_amp_b->sma * sma_amp_b->sma);                                               /* calculate variance of amplitude (biased estimator) */
-        if ((mode == AVMD_DETECT_AMP) && (avmd_decision_amplitude(s, buffer, v_amp, AVMD_AMPLITUDE_RSD_THRESHOLD) == 1)) {
-            return AVMD_DETECT_AMP;
-        }
-    }
-    if (((mode == AVMD_DETECT_FREQ) || (mode == AVMD_DETECT_BOTH)) && (valid_omega == 1)) {
-        v_fir = sqa_b_fir->sma - (sma_b_fir->sma * sma_b_fir->sma);                                               /* calculate variance of filtered samples */
-        if ((mode == AVMD_DETECT_FREQ) && (avmd_decision_freq(s, buffer, v_fir, AVMD_VARIANCE_RSD_THRESHOLD) == 1)) {
-            return AVMD_DETECT_FREQ;
-        }
-        if (mode == AVMD_DETECT_BOTH) {
-            if ((avmd_decision_amplitude(s, buffer, v_amp, AVMD_AMPLITUDE_RSD_THRESHOLD) == 1) && (avmd_decision_freq(s, buffer, v_fir, AVMD_VARIANCE_RSD_THRESHOLD) == 1))  {
-                return AVMD_DETECT_BOTH;
-            }
-        }
-    }
-    return AVMD_DETECT_NONE;
+                               f_fir = sma_b->pos > 1 ? (AVMD_MEDIAN_FILTER(sma_b->data[sma_b->pos - 2], sma_b->data[sma_b->pos - 1], f)) : f;
+
+                               APPEND_SMA_VAL(sma_b, f); /* append frequency */
+                               APPEND_SMA_VAL(sqa_b, f * f);
+                               APPEND_SMA_VAL(sma_b_fir, f_fir); /* append filtered frequency */
+                               APPEND_SMA_VAL(sqa_b_fir, f_fir * f_fir);
+                               if (s->settings.require_continuous_streak == 1) {
+                                       if (buffer->samples_streak > 0) {
+                                               --buffer->samples_streak;
+                                               valid_omega = 0;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       if (((mode == AVMD_DETECT_AMP) || (mode == AVMD_DETECT_BOTH)) && (valid_amplitude == 1)) {
+               v_amp = sqa_amp_b->sma - (sma_amp_b->sma * sma_amp_b->sma); /* calculate variance of amplitude (biased estimator) */
+               if ((mode == AVMD_DETECT_AMP) && (avmd_decision_amplitude(s, buffer, v_amp, AVMD_AMPLITUDE_RSD_THRESHOLD) == 1)) {
+                       return AVMD_DETECT_AMP;
+               }
+       }
+       if (((mode == AVMD_DETECT_FREQ) || (mode == AVMD_DETECT_BOTH)) && (valid_omega == 1)) {
+               v_fir = sqa_b_fir->sma - (sma_b_fir->sma * sma_b_fir->sma); /* calculate variance of filtered samples */
+               if ((mode == AVMD_DETECT_FREQ) && (avmd_decision_freq(s, buffer, v_fir, AVMD_VARIANCE_RSD_THRESHOLD) == 1)) {
+                       return AVMD_DETECT_FREQ;
+               }
+               if (mode == AVMD_DETECT_BOTH) {
+                       if ((avmd_decision_amplitude(s, buffer, v_amp, AVMD_AMPLITUDE_RSD_THRESHOLD) == 1) && (avmd_decision_freq(s, buffer, v_fir, AVMD_VARIANCE_RSD_THRESHOLD) == 1))  {
+                               return AVMD_DETECT_BOTH;
+                       }
+               }
+       }
+       return AVMD_DETECT_NONE;
 }
 
 static void* SWITCH_THREAD_FUNC
 avmd_detector_func(switch_thread_t *thread, void *arg) {
-    size_t      sample_n = 0, samples = AVMD_P;
-    size_t      pos;
-    uint8_t     resolution, offset;
-    avmd_session_t  *s;
-    enum avmd_detection_mode res = AVMD_DETECT_NONE;
-    struct avmd_detector *d;
-
-
-    d = (struct avmd_detector*) arg;
-    s = d->s;
-    pos = s->pos;
-    while (1) {
-        switch_mutex_lock(d->mutex);
-        while ((d->flag_processing_done == 1) && (d->flag_should_exit == 0)) {
-            switch_thread_cond_wait(d->cond_start_processing, d->mutex);
-        }
-        /* master set processing_done flag to 0 or thread should exit */
-        if (d->flag_should_exit == 1) {
-            d->flag_processing_done = 1;
-            goto end;
-        }
-        resolution = d->buffer.resolution;
-        offset = d->buffer.offset;
-        samples = d->samples;
-
-        if (d->lagged == 1) {
-            if (d->lag > 0) {
-                --d->lag;
-                goto done;
-            }
-            pos += AVMD_P;
-        }
-
-        switch_mutex_unlock(d->mutex);
-        sample_n = 1;
-        while (sample_n <= samples) {
-            if (((sample_n + offset) % resolution) == 0) {
-                res = avmd_process_sample(d->s, &s->b, sample_n, pos, d);
-                if (res != AVMD_DETECT_NONE) {
-                    break;
-                }
-            }
-            ++sample_n;
-        }
-        switch_mutex_lock(d->mutex);
+       size_t sample_n = 0, samples = AVMD_P;
+       size_t pos;
+       uint8_t resolution, offset;
+       avmd_session_t  *s;
+       enum avmd_detection_mode res = AVMD_DETECT_NONE;
+       struct avmd_detector *d;
+
+
+       d = (struct avmd_detector*) arg;
+       s = d->s;
+       pos = s->pos;
+       while (1) {
+               switch_mutex_lock(d->mutex);
+               while ((d->flag_processing_done == 1) && (d->flag_should_exit == 0)) {
+                       switch_thread_cond_wait(d->cond_start_processing, d->mutex);
+               }
+               /* master set processing_done flag to 0 or thread should exit */
+               if (d->flag_should_exit == 1) {
+                       d->flag_processing_done = 1;
+                       goto end;
+               }
+               resolution = d->buffer.resolution;
+               offset = d->buffer.offset;
+               samples = d->samples;
+
+               if (d->lagged == 1) {
+                       if (d->lag > 0) {
+                               --d->lag;
+                               goto done;
+                       }
+                       pos += AVMD_P;
+               }
+
+               switch_mutex_unlock(d->mutex);
+               sample_n = 1;
+               while (sample_n <= samples) {
+                       if (((sample_n + offset) % resolution) == 0) {
+                               res = avmd_process_sample(d->s, &s->b, sample_n, pos, d);
+                               if (res != AVMD_DETECT_NONE) {
+                                       break;
+                               }
+                       }
+                       ++sample_n;
+               }
+               switch_mutex_lock(d->mutex);
 done:
-        d->flag_processing_done = 1;
-        d->result = res;
-        switch_mutex_unlock(d->mutex);
+               d->flag_processing_done = 1;
+               d->result = res;
+               switch_mutex_unlock(d->mutex);
 
-        switch_mutex_lock(s->mutex_detectors_done);
-        switch_thread_cond_signal(s->cond_detectors_done);
-        switch_mutex_unlock(s->mutex_detectors_done);
-    }
-    return NULL;
+               switch_mutex_lock(s->mutex_detectors_done);
+               switch_thread_cond_signal(s->cond_detectors_done);
+               switch_mutex_unlock(s->mutex_detectors_done);
+       }
+       return NULL;
 
 end:
-    switch_mutex_unlock(d->mutex);
-    return NULL;
+       switch_mutex_unlock(d->mutex);
+       return NULL;
 }
 
 
index 80d0caeb6d724f374237e2b11fd693ec0a81ba44..f66f41a6d8678362937ab196c317bd9e0f78b1e1 100644 (file)
@@ -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";
index 9cbc98ea5e6b85292ed9b326015d9ea9e12c7d09..2906e4af415c8a9c4a1d412762250d416b2dd593 100644 (file)
@@ -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 . '}';
-
-    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);
-
-    $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";
-        }
-    }
+       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 . ')';
+
+       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));
+
+       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";
+               }
+       }
 }
index 223cedc5571d4f7dcd19d98b1b1301eda1e203e6..758c89deb1bd466ec82249d04fe41d75933dff36 100644 (file)
@@ -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');
 }
index 8eb791d13cc293b33f52e5f0f7a3e12255418e74..1831d09d5ff7660ab9519b25a870352b529de659 100644 (file)
@@ -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');
 }
index c6f63e1c09465fe12c245832dc7f92a8631c4efd..a32bf03a537d8c3245bc049dd93c884564ce85cb 100755 (executable)
@@ -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!
 }