Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
de8928f3
提交
de8928f3
authored
11月 07, 2007
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync
git-svn-id:
http://svn.freeswitch.org/svn/freeswitch/trunk@6180
d0543943-73ff-0310-b7d9-9358b9ac24b2
上级
06f08e79
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
188 行增加
和
175 行删除
+188
-175
libteletone_detect.c
libs/libteletone/src/libteletone_detect.c
+137
-137
libteletone_detect.h
libs/libteletone/src/libteletone_detect.h
+12
-12
libteletone_generate.c
libs/libteletone/src/libteletone_generate.c
+5
-4
libteletone_generate.h
libs/libteletone/src/libteletone_generate.h
+34
-22
没有找到文件。
libs/libteletone/src/libteletone_detect.c
浏览文件 @
de8928f3
...
@@ -130,7 +130,7 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state,
...
@@ -130,7 +130,7 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state,
}
}
}
}
#define teletone_goertzel_result(gs) (
(gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac
)
#define teletone_goertzel_result(gs) (
float)(((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac)
)
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
)
{
{
...
@@ -141,16 +141,16 @@ void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state,
...
@@ -141,16 +141,16 @@ void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state,
for
(
i
=
0
;
i
<
GRID_FACTOR
;
i
++
)
{
for
(
i
=
0
;
i
<
GRID_FACTOR
;
i
++
)
{
theta
=
(
float
)(
M_TWO_PI
*
(
dtmf_row
[
i
]
/
(
float
)
sample_rate
));
theta
=
(
float
)(
M_TWO_PI
*
(
dtmf_row
[
i
]
/
(
float
)
sample_rate
));
dtmf_detect_row
[
i
].
fac
=
(
float
)(
2
.
0
f
*
cos
(
theta
));
dtmf_detect_row
[
i
].
fac
=
(
float
)(
2
.
0
*
cos
(
theta
));
theta
=
(
float
)(
M_TWO_PI
*
(
dtmf_col
[
i
]
/
(
float
)
sample_rate
));
theta
=
(
float
)(
M_TWO_PI
*
(
dtmf_col
[
i
]
/
(
float
)
sample_rate
));
dtmf_detect_col
[
i
].
fac
=
(
float
)(
2
.
0
f
*
cos
(
theta
));
dtmf_detect_col
[
i
].
fac
=
(
float
)(
2
.
0
*
cos
(
theta
));
theta
=
(
float
)(
M_TWO_PI
*
(
dtmf_row
[
i
]
*
2
.
0
/
(
float
)
sample_rate
));
theta
=
(
float
)(
M_TWO_PI
*
(
dtmf_row
[
i
]
*
2
.
0
/
(
float
)
sample_rate
));
dtmf_detect_row_2nd
[
i
].
fac
=
(
float
)(
2
.
0
f
*
cos
(
theta
));
dtmf_detect_row_2nd
[
i
].
fac
=
(
float
)(
2
.
0
*
cos
(
theta
));
theta
=
(
float
)(
M_TWO_PI
*
(
dtmf_col
[
i
]
*
2
.
0
/
(
float
)
sample_rate
));
theta
=
(
float
)(
M_TWO_PI
*
(
dtmf_col
[
i
]
*
2
.
0
/
(
float
)
sample_rate
));
dtmf_detect_col_2nd
[
i
].
fac
=
(
float
)(
2
.
0
f
*
cos
(
theta
));
dtmf_detect_col_2nd
[
i
].
fac
=
(
float
)(
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
]);
goertzel_init
(
&
dtmf_detect_state
->
col_out
[
i
],
&
dtmf_detect_col
[
i
]);
goertzel_init
(
&
dtmf_detect_state
->
col_out
[
i
],
&
dtmf_detect_col
[
i
]);
...
@@ -197,7 +197,7 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma
...
@@ -197,7 +197,7 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma
}
}
mt
->
tone_count
++
;
mt
->
tone_count
++
;
theta
=
(
float
)(
M_TWO_PI
*
(
map
->
freqs
[
x
]
/
(
float
)
mt
->
sample_rate
));
theta
=
(
float
)(
M_TWO_PI
*
(
map
->
freqs
[
x
]
/
(
float
)
mt
->
sample_rate
));
mt
->
tdd
[
x
].
fac
=
(
float
)(
2
.
0
f
*
cos
(
theta
));
mt
->
tdd
[
x
].
fac
=
(
float
)(
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
]);
}
}
...
@@ -348,15 +348,15 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state,
...
@@ -348,15 +348,15 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state,
}
}
/* We are at the end of a DTMF detection block */
/* We are at the end of a DTMF detection block */
/* Find the peak row and the peak column */
/* Find the peak row and the peak column */
row_energy
[
0
]
=
(
float
)(
teletone_goertzel_result
(
&
dtmf_detect_state
->
row_out
[
0
])
);
row_energy
[
0
]
=
teletone_goertzel_result
(
&
dtmf_detect_state
->
row_out
[
0
]
);
col_energy
[
0
]
=
(
float
)(
teletone_goertzel_result
(
&
dtmf_detect_state
->
col_out
[
0
])
);
col_energy
[
0
]
=
teletone_goertzel_result
(
&
dtmf_detect_state
->
col_out
[
0
]
);
for
(
best_row
=
best_col
=
0
,
i
=
1
;
i
<
GRID_FACTOR
;
i
++
)
{
for
(
best_row
=
best_col
=
0
,
i
=
1
;
i
<
GRID_FACTOR
;
i
++
)
{
row_energy
[
i
]
=
(
float
)(
teletone_goertzel_result
(
&
dtmf_detect_state
->
row_out
[
i
])
);
row_energy
[
i
]
=
teletone_goertzel_result
(
&
dtmf_detect_state
->
row_out
[
i
]
);
if
(
row_energy
[
i
]
>
row_energy
[
best_row
])
{
if
(
row_energy
[
i
]
>
row_energy
[
best_row
])
{
best_row
=
i
;
best_row
=
i
;
}
}
col_energy
[
i
]
=
(
float
)(
teletone_goertzel_result
(
&
dtmf_detect_state
->
col_out
[
i
])
);
col_energy
[
i
]
=
teletone_goertzel_result
(
&
dtmf_detect_state
->
col_out
[
i
]
);
if
(
col_energy
[
i
]
>
col_energy
[
best_col
])
{
if
(
col_energy
[
i
]
>
col_energy
[
best_col
])
{
best_col
=
i
;
best_col
=
i
;
}
}
...
...
libs/libteletone/src/libteletone_detect.h
浏览文件 @
de8928f3
libs/libteletone/src/libteletone_generate.c
浏览文件 @
de8928f3
...
@@ -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
;
...
...
libs/libteletone/src/libteletone_generate.h
浏览文件 @
de8928f3
...
@@ -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,11 +131,20 @@ typedef struct teletone_dds_state teletone_dds_state_t;
...
@@ -130,11 +131,20 @@ 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
)
{
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
;
int32_t
bitmask
=
dds
->
phase_accumulator
,
sine_index
=
(
bitmask
>>=
23
)
&
SINE_TABLE_LEN
;
int16_t
sample
;
int16_t
sample
;
if
(
pindex
>=
MAX_PHASE_TONES
)
{
pindex
=
0
;
}
if
(
bitmask
&
SINE_TABLE_MAX
)
{
if
(
bitmask
&
SINE_TABLE_MAX
)
{
sine_index
=
SINE_TABLE_LEN
-
sine_index
;
sine_index
=
SINE_TABLE_LEN
-
sine_index
;
}
}
...
@@ -145,27 +155,29 @@ static inline int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds)
...
@@ -145,27 +155,29 @@ static inline int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds)
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
.
0
f
,
(
tx_level
-
DBM0_MAX_POWER
)
/
20
.
0
f
)
*
(
32767
.
0
f
*
1
.
414214
f
));
dds
->
scale_factor
=
(
int
)
(
powf
(
10
.
0
f
,
(
tx_level
-
DBM0_MAX_POWER
)
/
20
.
0
f
)
*
(
32767
.
0
f
*
1
.
414214
f
));
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论