提交 de8928f3 authored 作者: Anthony Minessale's avatar Anthony Minessale

sync

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6180 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 06f08e79
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
* Exception: * Exception:
* The author hereby grants the use of this source code under the * The author hereby grants the use of this source code under the
* following license if and only if the source code is distributed * following license if and only if the source code is distributed
* as part of the openzap library. Any use or distribution of this * as part of the openzap library. Any use or distribution of this
* source code outside the scope of the openzap library will nullify the * source code outside the scope of the openzap library will nullify the
* following license and reinact the MPL 1.1 as stated above. * following license and reinact the MPL 1.1 as stated above.
* *
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
...@@ -105,9 +105,9 @@ extern "C" { ...@@ -105,9 +105,9 @@ extern "C" {
*/ */
#ifndef FALSE #ifndef FALSE
#define FALSE 0 #define FALSE 0
#ifndef TRUE #ifndef TRUE
#define TRUE (!FALSE) #define TRUE (!FALSE)
#endif #endif
#endif #endif
...@@ -123,13 +123,13 @@ extern "C" { ...@@ -123,13 +123,13 @@ extern "C" {
* Frequency tolerance +- 1.5% will detect, +-3.5% will reject * Frequency tolerance +- 1.5% will detect, +-3.5% will reject
*/ */
#define DTMF_THRESHOLD 8.0e7 #define DTMF_THRESHOLD 8.0e7
#define DTMF_NORMAL_TWIST 6.3 /* 8dB */ #define DTMF_NORMAL_TWIST 6.3 /* 8dB */
#define DTMF_REVERSE_TWIST 2.5 /* 4dB */ #define DTMF_REVERSE_TWIST 2.5 /* 4dB */
#define DTMF_RELATIVE_PEAK_ROW 6.3 /* 8dB */ #define DTMF_RELATIVE_PEAK_ROW 6.3 /* 8dB */
#define DTMF_RELATIVE_PEAK_COL 6.3 /* 8dB */ #define DTMF_RELATIVE_PEAK_COL 6.3 /* 8dB */
#define DTMF_2ND_HARMONIC_ROW 2.5 /* 4dB */ #define DTMF_2ND_HARMONIC_ROW 2.5 /* 4dB */
#define DTMF_2ND_HARMONIC_COL 63.1 /* 18dB */ #define DTMF_2ND_HARMONIC_COL 63.1 /* 18dB */
#define GRID_FACTOR 4 #define GRID_FACTOR 4
#define BLOCK_LEN 102 #define BLOCK_LEN 102
#define M_TWO_PI 2.0*M_PI #define M_TWO_PI 2.0*M_PI
...@@ -154,7 +154,7 @@ extern "C" { ...@@ -154,7 +154,7 @@ extern "C" {
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; float energy;
int current_sample; int current_sample;
char digits[TELETONE_MAX_DTMF_DIGITS + 1]; char digits[TELETONE_MAX_DTMF_DIGITS + 1];
int current_digits; int current_digits;
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
* Exception: * Exception:
* The author hereby grants the use of this source code under the * The author hereby grants the use of this source code under the
* following license if and only if the source code is distributed * following license if and only if the source code is distributed
* as part of the openzap library. Any use or distribution of this * as part of the openzap library. Any use or distribution of this
* source code outside the scope of the openzap library will nullify the * source code outside the scope of the openzap library will nullify the
* following license and reinact the MPL 1.1 as stated above. * following license and reinact the MPL 1.1 as stated above.
* *
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
...@@ -219,7 +219,8 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m ...@@ -219,7 +219,8 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m
if (map->freqs[0] > 0) { if (map->freqs[0] > 0) {
for (freqlen = 0; map->freqs[freqlen] && freqlen < TELETONE_MAX_TONES; freqlen++) { for (freqlen = 0; map->freqs[freqlen] && freqlen < TELETONE_MAX_TONES; freqlen++) {
teletone_dds_state_set_tone(&tones[freqlen], map->freqs[freqlen], ts->rate, vol); teletone_dds_state_set_tone(&tones[freqlen], map->freqs[freqlen], ts->rate, 0);
teletone_dds_state_set_tx_level(&tones[freqlen], vol);
} }
if (ts->channels > 1) { if (ts->channels > 1) {
...@@ -249,7 +250,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m ...@@ -249,7 +250,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m
sample = 128; sample = 128;
for (i = 0; i < freqlen; i++) { for (i = 0; i < freqlen; i++) {
int32_t s = teletone_dds_modulate_sample(&tones[i]); int32_t s = teletone_dds_state_modulate_sample(&tones[i], 0);
sample += s; sample += s;
} }
sample /= freqlen; sample /= freqlen;
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
* Exception: * Exception:
* The author hereby grants the use of this source code under the * The author hereby grants the use of this source code under the
* following license if and only if the source code is distributed * following license if and only if the source code is distributed
* as part of the openzap library. Any use or distribution of this * as part of the openzap library. Any use or distribution of this
* source code outside the scope of the openzap library will nullify the * source code outside the scope of the openzap library will nullify the
* following license and reinact the MPL 1.1 as stated above. * following license and reinact the MPL 1.1 as stated above.
* *
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
...@@ -80,8 +80,9 @@ extern "C" { ...@@ -80,8 +80,9 @@ extern "C" {
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef _MSC_VER #ifdef _MSC_VER
#undef inline #ifndef __inline__
#define inline __inline #define __inline__ __inline
#endif
typedef unsigned __int64 uint64_t; typedef unsigned __int64 uint64_t;
typedef unsigned __int32 uint32_t; typedef unsigned __int32 uint32_t;
typedef unsigned __int16 uint16_t; typedef unsigned __int16 uint16_t;
...@@ -111,12 +112,12 @@ extern float powf (float, float); ...@@ -111,12 +112,12 @@ extern float powf (float, float);
#define TELETONE_VOL_DB_MAX 0 #define TELETONE_VOL_DB_MAX 0
#define TELETONE_VOL_DB_MIN -63 #define TELETONE_VOL_DB_MIN -63
#define MAX_PHASE_TONES 4
struct teletone_dds_state { struct teletone_dds_state {
uint32_t phase_rate; uint32_t phase_rate[MAX_PHASE_TONES];
uint32_t scale_factor; uint32_t scale_factor;
uint32_t phase_accumulator; uint32_t phase_accumulator;
int16_t sample;
teletone_process_t tx_level; teletone_process_t tx_level;
}; };
typedef struct teletone_dds_state teletone_dds_state_t; typedef struct teletone_dds_state teletone_dds_state_t;
...@@ -130,42 +131,53 @@ typedef struct teletone_dds_state teletone_dds_state_t; ...@@ -130,42 +131,53 @@ typedef struct teletone_dds_state teletone_dds_state_t;
extern int16_t TELETONE_SINES[SINE_TABLE_MAX]; extern int16_t TELETONE_SINES[SINE_TABLE_MAX];
static inline int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds) static __inline__ int32_t teletone_dds_phase_rate(teletone_process_t tone, uint32_t rate)
{ {
int32_t bitmask = dds->phase_accumulator, sine_index = (bitmask >>= 23) & SINE_TABLE_LEN; return (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate);
}
static __inline__ int16_t teletone_dds_state_modulate_sample(teletone_dds_state_t *dds, uint32_t pindex)
{
int32_t bitmask = dds->phase_accumulator, sine_index = (bitmask >>= 23) & SINE_TABLE_LEN;
int16_t sample; int16_t sample;
if (bitmask & SINE_TABLE_MAX) { if (pindex >= MAX_PHASE_TONES) {
sine_index = SINE_TABLE_LEN - sine_index; pindex = 0;
}
if (bitmask & SINE_TABLE_MAX) {
sine_index = SINE_TABLE_LEN - sine_index;
} }
sample = TELETONE_SINES[sine_index]; sample = TELETONE_SINES[sine_index];
if (bitmask & (SINE_TABLE_MAX * 2)) { if (bitmask & (SINE_TABLE_MAX * 2)) {
sample *= -1; sample *= -1;
} }
dds->phase_accumulator += dds->phase_rate; dds->phase_accumulator += dds->phase_rate[pindex];
return (int16_t) (sample * dds->scale_factor >> 15);
return (int16_t) (sample * dds->scale_factor >> 15);
} }
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, float tx_level)
{ {
dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f));
dds->tx_level = tx_level;
} }
static inline void teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, float tx_level) static __inline__ void teletone_dds_state_reset_accum(teletone_dds_state_t *dds)
{ {
dds->phase_accumulator = 0; dds->phase_accumulator = 0;
dds->phase_rate = (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); }
if (dds->tx_level != tx_level || !dds->scale_factor) { static __inline__ int teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, uint32_t pindex)
teletone_dds_state_set_tx_level(dds, tx_level); {
if (pindex < MAX_PHASE_TONES) {
dds->phase_rate[pindex] = teletone_dds_phase_rate(tone, rate);
return 0;
} }
dds->tx_level = tx_level; return -1;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论