]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
use float instead of double for teletone.
authorMichael Jerris <mike@jerris.com>
Thu, 7 Jun 2007 00:33:31 +0000 (00:33 +0000)
committerMichael Jerris <mike@jerris.com>
Thu, 7 Jun 2007 00:33:31 +0000 (00:33 +0000)
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@227 a93c3328-9c30-0410-af19-c9cd2b2d52af

libs/openzap/src/include/libteletone.h
libs/openzap/src/include/libteletone_detect.h
libs/openzap/src/include/libteletone_generate.h
libs/openzap/src/include/openzap.h
libs/openzap/src/libteletone_detect.c
libs/openzap/src/libteletone_generate.c
libs/openzap/src/zap_io.c

index aaf7b0ed4794c4ab9eefb9b5ca53fdd0377b08f4..5c9616cb2aee976d3e02f7414431458db24414c9 100644 (file)
@@ -78,7 +78,7 @@ extern "C" {
 #define TELETONE_MAX_TONES 6
 #define TELETONE_TONE_RANGE 127
 
-typedef double teletone_process_t;
+typedef float teletone_process_t;
 
 /*! \file libteletone.h
     \brief Top level include file
@@ -94,7 +94,7 @@ typedef struct {
 
 #if !defined(M_PI)
 /* C99 systems may not define M_PI */
-#define M_PI 3.14159265358979323846264338327
+#define M_PI 3.14159265358979323846264338327f
 #endif
 
 #ifdef _MSC_VER
index 15d5e9ddfb3ebcf3043cee6dc39a92716164c35a..10fece6cc78234cc1af77610b0ea19dd463963e0 100644 (file)
@@ -132,7 +132,7 @@ extern "C" {
 #define DTMF_2ND_HARMONIC_COL       63.1    /* 18dB */
 #define GRID_FACTOR 4
 #define BLOCK_LEN 102
-#define M_TWO_PI 2.0*M_PI
+#define M_TWO_PI 2.0f*M_PI
 
        /*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */
        typedef struct {
index be791555bd19f6737a8b15b4aa636a022eb2c788..fb2d06b0d7e48108dcbf53fff008142d066a2b8d 100644 (file)
@@ -79,7 +79,23 @@ extern "C" {
 
 #include <stdio.h>
 #include <stdlib.h>
+#ifdef WIN32
+#ifdef _MSC_VER
+#ifndef __inline__
+#define __inline__ __inline
+#endif
+#endif
+typedef unsigned __int64 uint64_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int8 uint8_t;
+typedef __int64 int64_t;
+typedef __int32 int32_t;
+typedef __int16 int16_t;
+typedef __int8 int8_t;
+#else
 #include <stdint.h>
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -89,17 +105,9 @@ extern float powf (float, float);
 #endif
 #include <string.h>
 #include <errno.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 #ifndef _MSC_VER
 #include <unistd.h>
-#include <stdint.h>
 #endif
-#include <fcntl.h>
-#include <sys/types.h>
-#include <errno.h>
 #include <assert.h>
 #include <stdarg.h>
 #include <libteletone.h>
@@ -112,7 +120,7 @@ struct teletone_dds_state {
        uint32_t scale_factor;
        uint32_t phase_accumulator;
        int16_t sample;
-       float tx_level;
+       teletone_process_t tx_level;
 };
 typedef struct teletone_dds_state teletone_dds_state_t;
 
@@ -145,7 +153,7 @@ static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds
     return (int16_t) (sample * dds->scale_factor >> 15);
 }
 
-static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, float tone, uint32_t rate, float tx_level)
+static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, teletone_process_t tx_level)
 {
        dds->phase_accumulator = 0;
        dds->phase_rate = (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate);
@@ -158,7 +166,7 @@ static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, fl
        dds->tx_level = tx_level;
 }
 
-static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level)
+static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, teletone_process_t tx_level)
 {
        dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f));
 }
@@ -196,13 +204,13 @@ struct teletone_generation_session {
        /*! Number of loops to repeat the entire set of instructions*/
        int LOOPS;
        /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */
-       float decay_factor;
+       teletone_process_t decay_factor;
        /*! Direction to perform volume increase/decrease 1/-1*/
        int decay_direction;
        /*! Number of samples between increase/decrease of volume */
        int decay_step;
        /*! Volume factor of the tone */
-       float volume;
+       teletone_process_t volume;
        /*! Debug on/off */
        int debug;
        /*! FILE stream to write debug data to */
index 01eb7e75ba0aeeaffcf3037c1b286e14b2160990..e1dc74c649eb462bf0fc94eb931755fa3ed56fae 100644 (file)
@@ -53,6 +53,9 @@
 #endif
 
 #ifdef _MSC_VER
+#ifndef __inline__
+#define __inline__ __inline
+#endif
 #if (_MSC_VER >= 1400)                 /* VC8+ */
 #ifndef _CRT_SECURE_NO_DEPRECATE
 #define _CRT_SECURE_NO_DEPRECATE
index a089f8fc4878f97bb5cbbcd4103080a0f7a42a38..4148751172d711d6aa2fe9f9170d48f536051e25 100644 (file)
@@ -145,16 +145,16 @@ void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state,
 
     for (i = 0;  i < GRID_FACTOR;  i++) {
         theta = M_TWO_PI*(dtmf_row[i]/(teletone_process_t)sample_rate);
-        dtmf_detect_row[i].fac = 2.0*cos(theta);
+        dtmf_detect_row[i].fac = (teletone_process_t)(2.0f*cos(theta));
 
         theta = M_TWO_PI*(dtmf_col[i]/(teletone_process_t)sample_rate);
-        dtmf_detect_col[i].fac = 2.0*cos(theta);
+        dtmf_detect_col[i].fac = (teletone_process_t)(2.0f*cos(theta));
     
-        theta = M_TWO_PI*(dtmf_row[i]*2.0/(teletone_process_t)sample_rate);
-        dtmf_detect_row_2nd[i].fac = 2.0*cos(theta);
+        theta = M_TWO_PI*(dtmf_row[i]*2.0f/(teletone_process_t)sample_rate);
+        dtmf_detect_row_2nd[i].fac = (teletone_process_t)(2.0f*cos(theta));
 
-        theta = M_TWO_PI*(dtmf_col[i]*2.0/(teletone_process_t)sample_rate);
-        dtmf_detect_col_2nd[i].fac = 2.0*cos(theta);
+        theta = M_TWO_PI*(dtmf_col[i]*2.0f/(teletone_process_t)sample_rate);
+        dtmf_detect_col_2nd[i].fac = (teletone_process_t)(2.0f*cos(theta));
     
                goertzel_init (&dtmf_detect_state->row_out[i], &dtmf_detect_row[i]);
        goertzel_init (&dtmf_detect_state->col_out[i], &dtmf_detect_col[i]);
@@ -201,7 +201,7 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma
                }
                mt->tone_count++;
                theta = M_TWO_PI*(map->freqs[x]/(teletone_process_t)mt->sample_rate);
-               mt->tdd[x].fac = 2.0 * cos(theta);
+               mt->tdd[x].fac = (teletone_process_t)(2.0f * cos(theta));
                goertzel_init (&mt->gs[x], &mt->tdd[x]);
                goertzel_init (&mt->gs2[x], &mt->tdd[x]);
        }
index 5c46b1afd16b7907683e671722be9e53abd04edc..131f795c1e2bcfddf4856b14683d0d28b7b8697a 100644 (file)
@@ -211,7 +211,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m
        int wait = 0;
        int32_t sample;
        int32_t dc = 0;
-       float vol = ts->volume;
+       teletone_process_t vol = ts->volume;
        ts->samples = 0;
        memset(tones, 0, sizeof(tones[0]) * TELETONE_MAX_TONES);
        duration = (ts->tmp_duration > -1) ? ts->tmp_duration : ts->duration;
@@ -234,7 +234,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m
 
                for (ts->samples = 0; ts->samples < ts->datalen && ts->samples < duration; ts->samples++) {
                        if (ts->decay_direction && ++dc >= ts->decay_step) {
-                               float nvol = vol + ts->decay_direction * ts->decay_factor;
+                               teletone_process_t nvol = vol + ts->decay_direction * ts->decay_factor;
                                int j;
 
                                if (nvol <= TELETONE_VOL_DB_MAX && nvol >= TELETONE_VOL_DB_MIN) {
@@ -355,7 +355,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd)
                                        break;
                                case 'v':
                                        {
-                                               float vol = atof(cur + 2);
+                                               teletone_process_t vol = (teletone_process_t)atof(cur + 2);
                                                if (vol <= TELETONE_VOL_DB_MAX && vol >= TELETONE_VOL_DB_MIN) {
                                                        ts->volume = vol;
                                                }
@@ -370,7 +370,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd)
                                        ts->decay_direction = 1;
                                        break;
                                case '+':
-                                       ts->decay_factor = atof(cur + 2);
+                                       ts->decay_factor = (teletone_process_t)atof(cur + 2);
                                        break;
                                case 'w':
                                        ts->wait = atoi(cur + 2) * (ts->rate / 1000);
@@ -419,7 +419,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd)
                                                                        ts->tmp_wait = atoi(p) * (ts->rate / 1000);
                                                                        i++;
                                                                } else {
-                                                                       mymap.freqs[i++ - 2] = atof(p);
+                                                                       mymap.freqs[i++ - 2] = (teletone_process_t)atof(p);
                                                                }
                                                                p = next;
 
index d0da23752f830006eef175f30f9daa26809eb222..d4df53f3ce05afef535c1290578161094575b324 100644 (file)
@@ -306,7 +306,7 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname)
                                        do {
                                                teletone_process_t this;
                                                next = strchr(p, ',');
-                                               this = atof(p);
+                                               this = (teletone_process_t)atof(p);
                                                span->tone_detect_map[index].freqs[i++] = this;
                                                if (next) {
                                                        p = next + 1;