dahdi_tools 分析 (七) fxotune
fxotune
A utility for tuning the various settings on the fxo modules
一个用于调节 FXO (SI3050)参数(主要是阻抗)的工具。
usage
Usage: fxotune [-v[vv] (-s | -i <options> | -d <options>)
-s : set previously calibrated echo settings
-i : calibrate echo settings
options : [<dialstring>] [-t <calibtype>]
[-b <startdev>][-e <stopdev>]
[-n <dialstring>][-l <delaytosilence>][-m <silencegoodfor>]
-d : dump input and output waveforms to ./fxotune_dump.vals
options : [-b <device>][-w <waveform>]
[-n <dialstring>][-l <delaytosilence>][-m <silencegoodfor>]
-v : more output (-vv, -vvv also)
-p : print the 5 best candidates for acim and coefficients settings
-x : Perform sin/cos functions using table lookup
-o <path> : Write the received raw 16-bit signed linear audio that is
used in processing to the file specified by <path>
-c <config_file>
<calibtype> - type of calibration
(default 2, old method 1)
<startdev>
<stopdev> - defines a range of devices to test
(default: 1-252)
<dialstring> - string to dial to clear the line
(default 5)
<delaytosilence> - seconds to wait for line to clear (default 0)
<silencegoodfor> - seconds before line will no longer be clear
(default 18)
<device> - the device to perform waveform dump on
(default 1)
<waveform> - -1 for multitone waveform, or frequency of
single tone (default -1)
<config_file> - Alternative file to set from / calibrate to.
(Default: /etc/fxotune.conf)
用法举例
root@localhost:/fxs_test# ./fxotune -i -b 3 -e 3 -p
Tuning module 3
Top 5 results for Acim2_tune Test
Res #1: index=1, 10, 0, 6, 1,254, 2,255, 0, 0: magnitude = 139, echo = -35.3670 dB
Res #2: index=66, 10, 0, 0, 0, 0, 0, 0, 0, 0: magnitude = 192, echo = -32.5711 dB
Res #3: index=32, 4, 0, 0, 0, 0, 0, 0, 0, 0: magnitude = 293, echo = -28.9154 dB
Res #4: index=71, 15, 0, 0, 0, 0, 0, 0, 0, 0: magnitude = 308, echo = -28.4814 dB
Res #5: index=64, 8, 0, 0, 0, 0, 0, 0, 0, 0: magnitude = 335, echo = -27.7510 dB
Done!
- 自动调整阻抗成最佳匹配值。-p 显示前5最佳阻抗参数值。
- 最佳参数值保存在 /etc/fxotune.conf
root@localhost:/fxs_test# cat /etc/fxotune.conf
3=10,0,6,1,254,2,255,0,0
源码分析
核心函数是 acim_tune2
main
-> do_calibrate
-> acim_tune2
echo_trys 里面预定义了 72 组预设值
调用 iotcl WCTDM_SET_ECHOTUNE &echo_trys[trys] 依次设置
发送测试音频,并读取返回的音频数据,计算回声的大小。选出回声最小的参数值。
实测
# 设置 fxs 端阻抗值为 CHINA 200 + (680 || 100 nF)
# insmod mytdm opermode=CHINA fxshonormode=1
root@localhost:/fxs_test# ./fxotune -i -b 3 -e 3 -p
Tuning module 3
Top 5 results for Acim2_tune Test
Res #1: index=1, 10, 0, 6, 1,254, 2,255, 0, 0: magnitude = 139, echo = -35.3670 dB
Res #2: index=66, 10, 0, 0, 0, 0, 0, 0, 0, 0: magnitude = 192, echo = -32.5711 dB
Res #3: index=32, 4, 0, 0, 0, 0, 0, 0, 0, 0: magnitude = 293, echo = -28.9154 dB
Res #4: index=71, 15, 0, 0, 0, 0, 0, 0, 0, 0: magnitude = 308, echo = -28.4814 dB
Res #5: index=64, 8, 0, 0, 0, 0, 0, 0, 0, 0: magnitude = 335, echo = -27.7510 dB
Done!
当 fxs 端阻抗值为 CHINA , fxotune 得到 最佳 acim 值为 10 , 是对的!
# 设置 fxs 端阻抗值为默认值 FCC
# insmod mytdm
root@localhost:/fxs_test# ./fxotune -i -b 3 -e 3 -p
Tuning module 3
Top 5 results for Acim2_tune Test
Res #1: index=0, 0, 0, 0, 0, 0, 0, 0, 0, 0: magnitude = 81, echo = -40.0676 dB
Res #2: index=67, 11, 0, 0, 0, 0, 0, 0, 0, 0: magnitude = 195, echo = -32.4299 dB
Res #3: index=70, 14, 0, 0, 0, 0, 0, 0, 0, 0: magnitude = 419, echo = -25.7992 dB
Res #4: index=1, 10, 0, 6, 1,254, 2,255, 0, 0: magnitude = 473, echo = -24.7599 dB
Res #5: index=69, 13, 0, 0, 0, 0, 0, 0, 0, 0: magnitude = 698, echo = -21.3783 dB
Done!
当 fxs 端阻抗值为 FCC (600) , fxotune 得到 最佳 acim 值为 0, 是对的!
小结
fxotune 的作用是匹配最佳阻抗值,这可以使线路回声达到最小。