make teletone use all doubles

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@631 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-02-19 21:01:55 +00:00
parent 374097970d
commit cf67dbefd4
6 changed files with 34 additions and 28 deletions

View File

@ -19,6 +19,6 @@ library_include_HEADERS = src/libteletone.h src/libteletone_detect.h src/libtele
dox:
cd docs && doxygen $(PWD)/docs/Doxygen.conf

View File

@ -731,6 +731,9 @@ uninstall-info: uninstall-info-recursive
uninstall-info-am uninstall-libLTLIBRARIES \ uninstall-info-am uninstall-libLTLIBRARIES \
uninstall-library_includeHEADERS uninstall-library_includeHEADERS
dox:
cd docs && doxygen $(PWD)/docs/Doxygen.conf
# Tell versions [3.59,3.63) of GNU make to not export all variables. # Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded. # Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT: .NOEXPORT:

View File

@ -39,6 +39,8 @@ extern "C" {
#define TELETONE_MAX_TONES 6 #define TELETONE_MAX_TONES 6
#define TELETONE_TONE_RANGE 127 #define TELETONE_TONE_RANGE 127
typedef double teletone_process_t;
/*! \file libteletone.h /*! \file libteletone.h
\brief Top level include file \brief Top level include file
@ -48,7 +50,7 @@ extern "C" {
/*! \brief An abstraction to store a tone mapping */ /*! \brief An abstraction to store a tone mapping */
typedef struct { typedef struct {
/*! An array of tone frequencies */ /*! An array of tone frequencies */
double freqs[TELETONE_MAX_TONES]; teletone_process_t freqs[TELETONE_MAX_TONES];
} teletone_tone_map_t; } teletone_tone_map_t;

View File

@ -63,8 +63,8 @@ static teletone_detection_descriptor_t dtmf_detect_col[GRID_FACTOR];
static teletone_detection_descriptor_t dtmf_detect_row_2nd[GRID_FACTOR]; static teletone_detection_descriptor_t dtmf_detect_row_2nd[GRID_FACTOR];
static teletone_detection_descriptor_t dtmf_detect_col_2nd[GRID_FACTOR]; static teletone_detection_descriptor_t dtmf_detect_col_2nd[GRID_FACTOR];
static float dtmf_row[] = {697.0, 770.0, 852.0, 941.0}; static teletone_process_t dtmf_row[] = {697.0, 770.0, 852.0, 941.0};
static float dtmf_col[] = {1209.0, 1336.0, 1477.0, 1633.0}; static teletone_process_t dtmf_col[] = {1209.0, 1336.0, 1477.0, 1633.0};
static char dtmf_positions[] = "123A" "456B" "789C" "*0#D"; static char dtmf_positions[] = "123A" "456B" "789C" "*0#D";
@ -79,7 +79,7 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state,
int samples) int samples)
{ {
int i; int i;
float v1; teletone_process_t v1;
for (i = 0; i < samples; i++) { for (i = 0; i < samples; i++) {
v1 = goertzel_state->v2; v1 = goertzel_state->v2;
@ -88,7 +88,7 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state,
} }
} }
float teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state) teletone_process_t teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state)
{ {
return goertzel_state->v3 * goertzel_state->v3 + goertzel_state->v2 * goertzel_state->v2 - goertzel_state->v2 * goertzel_state->v3 * goertzel_state->fac; return goertzel_state->v3 * goertzel_state->v3 + goertzel_state->v2 * goertzel_state->v2 - goertzel_state->v2 * goertzel_state->v3 * goertzel_state->fac;
} }
@ -96,21 +96,21 @@ float teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state)
void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate)
{ {
int i; int i;
float theta; teletone_process_t theta;
dtmf_detect_state->hit1 = dtmf_detect_state->hit2 = 0; dtmf_detect_state->hit1 = dtmf_detect_state->hit2 = 0;
for (i = 0; i < GRID_FACTOR; i++) { for (i = 0; i < GRID_FACTOR; i++) {
theta = M_TWO_PI*(dtmf_row[i]/(float)sample_rate); 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 = 2.0*cos(theta);
theta = M_TWO_PI*(dtmf_col[i]/(float)sample_rate); 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 = 2.0*cos(theta);
theta = M_TWO_PI*(dtmf_row[i]*2.0/(float)sample_rate); theta = M_TWO_PI*(dtmf_row[i]*2.0/(teletone_process_t)sample_rate);
dtmf_detect_row_2nd[i].fac = 2.0*cos(theta); dtmf_detect_row_2nd[i].fac = 2.0*cos(theta);
theta = M_TWO_PI*(dtmf_col[i]*2.0/(float)sample_rate); theta = M_TWO_PI*(dtmf_col[i]*2.0/(teletone_process_t)sample_rate);
dtmf_detect_col_2nd[i].fac = 2.0*cos(theta); dtmf_detect_col_2nd[i].fac = 2.0*cos(theta);
goertzel_init (&dtmf_detect_state->row_out[i], &dtmf_detect_row[i]); goertzel_init (&dtmf_detect_state->row_out[i], &dtmf_detect_row[i]);
@ -129,7 +129,7 @@ void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state,
void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map) void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map)
{ {
float theta = 0; teletone_process_t theta = 0;
int x = 0; int x = 0;
if(!mt->min_samples) { if(!mt->min_samples) {
@ -157,7 +157,7 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma
break; break;
} }
mt->tone_count++; mt->tone_count++;
theta = M_TWO_PI*(map->freqs[x]/(float)mt->sample_rate); 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 = 2.0 * cos(theta);
goertzel_init (&mt->gs[x], &mt->tdd[x]); goertzel_init (&mt->gs[x], &mt->tdd[x]);
goertzel_init (&mt->gs2[x], &mt->tdd[x]); goertzel_init (&mt->gs2[x], &mt->tdd[x]);
@ -170,8 +170,8 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt,
int samples) int samples)
{ {
int sample, limit, j, x = 0; int sample, limit, j, x = 0;
float v1, famp; teletone_process_t v1, famp;
float eng_sum = 0, eng_all[TELETONE_MAX_TONES]; teletone_process_t eng_sum = 0, eng_all[TELETONE_MAX_TONES];
int gtest = 0, see_hit = 0; int gtest = 0, see_hit = 0;
for (sample = 0; sample < samples; sample = limit) { for (sample = 0; sample < samples; sample = limit) {
@ -256,10 +256,10 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state,
int16_t sample_buffer[], int16_t sample_buffer[],
int samples) int samples)
{ {
float row_energy[GRID_FACTOR]; teletone_process_t row_energy[GRID_FACTOR];
float col_energy[GRID_FACTOR]; teletone_process_t col_energy[GRID_FACTOR];
float famp; teletone_process_t famp;
float v1; teletone_process_t v1;
int i; int i;
int j; int j;
int sample; int sample;

View File

@ -92,9 +92,9 @@ extern "C" {
/*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */ /*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */
typedef struct { typedef struct {
float v2; teletone_process_t v2;
float v3; teletone_process_t v3;
float fac; teletone_process_t fac;
} teletone_goertzel_state_t; } teletone_goertzel_state_t;
/*! \brief A container for a DTMF detection state.*/ /*! \brief A container for a DTMF detection state.*/
@ -109,7 +109,7 @@ typedef struct {
teletone_goertzel_state_t col_out[GRID_FACTOR]; teletone_goertzel_state_t col_out[GRID_FACTOR];
teletone_goertzel_state_t row_out2nd[GRID_FACTOR]; teletone_goertzel_state_t row_out2nd[GRID_FACTOR];
teletone_goertzel_state_t col_out2nd[GRID_FACTOR]; teletone_goertzel_state_t col_out2nd[GRID_FACTOR];
float energy; teletone_process_t energy;
int current_sample; int current_sample;
char digits[TELETONE_MAX_DTMF_DIGITS + 1]; char digits[TELETONE_MAX_DTMF_DIGITS + 1];
@ -121,7 +121,7 @@ typedef struct {
/*! \brief An abstraction to store the coefficient of a tone frequency */ /*! \brief An abstraction to store the coefficient of a tone frequency */
typedef struct { typedef struct {
float fac; teletone_process_t fac;
} teletone_detection_descriptor_t; } teletone_detection_descriptor_t;
/*! \brief A container for a single multi-tone detection /*! \brief A container for a single multi-tone detection
@ -136,7 +136,7 @@ typedef struct {
teletone_goertzel_state_t gs2[TELETONE_MAX_TONES]; teletone_goertzel_state_t gs2[TELETONE_MAX_TONES];
int tone_count; int tone_count;
float energy; teletone_process_t energy;
int current_sample; int current_sample;
int min_samples; int min_samples;
@ -173,6 +173,7 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt,
/*! /*!
\brief Initilize a DTMF detection state object \brief Initilize a DTMF detection state object
\param dtmf_detect_state the DTMF detection state to initilize
\param sample_rate the desired sample rate \param sample_rate the desired sample rate
*/ */
void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate); void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate);
@ -213,7 +214,7 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state,
\param goertzel_state the goertzel state to retrieve from \param goertzel_state the goertzel state to retrieve from
\return the computed value for consideration in furthur audio tests \return the computed value for consideration in furthur audio tests
*/ */
float teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state); teletone_process_t teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state);

View File

@ -55,7 +55,6 @@ extern "C" {
*/ */
typedef short teletone_audio_t; typedef short teletone_audio_t;
typedef float teletone_process_t;
struct teletone_generation_session; struct teletone_generation_session;
typedef int (*tone_handler)(struct teletone_generation_session *ts, teletone_tone_map_t *map); typedef int (*tone_handler)(struct teletone_generation_session *ts, teletone_tone_map_t *map);
@ -128,6 +127,7 @@ int teletone_set_map(teletone_tone_map_t *map, ...);
\param ts the tone generation session to initilize \param ts the tone generation session to initilize
\param buflen the size of the buffer(in samples) to dynamically allocate \param buflen the size of the buffer(in samples) to dynamically allocate
\param handler a callback function to execute when a tone generation instruction is complete \param handler a callback function to execute when a tone generation instruction is complete
\param user_data optional user data to send
\return 0 \return 0
*/ */
int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data);