📄 main.cpp
字号:
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
//
// 说明
//
// 这个小程序是测试 DTMF 解码器工作的。
// DTMF 波形数据存储在 "1.wav" 文件中,打开听一下吧 ?
// 运行完本程序后,DTMF 波形将被解码,并将解码结果输出到一个文件中。
//
// author: hendry
// date: 2008/11
//
void main()
{
//
// 解码函数声明
//
extern void init_dtmf_decoder();
extern unsigned char decode_dtmf(signed char sample);
FILE *fin, *fout,*fout1;
signed char ch;
int i;
if ((fin = fopen("1.wav", "rb")) != NULL)
{
if ((fout = fopen("result.txt", "w")) != NULL)
{
//
// 初始化解码器
//
init_dtmf_decoder();
fout1 = fopen("result1.txt", "w");
//
// 读取并丢掉 wav 文件头非音频数据
//
for (i = 0; i < 512; i ++)
{
fgetc(fin);
}
//
// 从 wav 文件读取数据,每次1字节,并连续解码
// 因为 wav 文件是 8000Hz 采样率,DTMF 解码要求 4000Hz 采样率,所以要降采样,详见下面
// 当然,实际应用时直接用 4000Hz 采样就可以啦! 因为我用的录音格式不支持 4000,所以只能选 8000
//
i=0;
while (!feof(fin))
{
fgetc(fin); // 降采样: 很简单,丢掉一个点,就是 4000Hz 采样率了
ch = fgetc(fin);
fprintf(fout1,"%d,",(int)ch);
if (i==20)
fprintf(fout1,"\n");
i++;
ch += -128; // wave 数据是无符号数,要转成有符号数才能送入解码器,切记!!
//fprintf(fout1,"%d,",(int)ch);
ch = decode_dtmf(ch); // 解码
if (ch != 0)
{
fputc(ch, fout); // 输出
}
}
fclose(fin);
fclose(fout1);
fclose(fout); // 现在,解码结果已经在 "result.txt" 文件中了, 打开看看吧 ?
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -