有没有人用过speex?求助:杂音严重

oovoov008 2008-07-19 02:03:55
ID是刚刚注册的,没分可加,请大家帮忙。

我把手册上的sampleenc和sampledec编译了,运行命令:
./enc /dev/dsp | ./dec /dev/dsp

即把声卡的信号编码,解码,再送回声卡播放。
环境很安静,可是播出来的声音非常嘈杂。对着mic说话,解码后的声音完全被杂音所掩盖。

我尝试过其他方法:
cat /dev/dsp > from
./enc from | ./dec to
cat to > /dev/dsp
结果还是一样。
如果直接cat from > /dev/dsp ,声音就很清楚。

在代码里也试过添加VAD设置,也没用。

请问是什么原因?如何解决?十分感谢
...全文
795 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
oovoov008 2008-07-19
  • 打赏
  • 举报
回复
从pdf复制过来的注释有点问题,那些*号是注释里的/*....*/
oovoov008 2008-07-19
  • 打赏
  • 举报
回复
代码如下:
//sampleenc.c

1 #include <speex/speex.h>
2 #include <stdio.h>
3
4 / Theframesizeinhardcodedforthissamplecodebutitdoesn!thavetobe /
* *
5 #define FRAME_SIZE160
6 int main(int argc, char argv)
**
7 {
8 char inFile;
*
9 FILE fin;
*
10 short in[FRAME_SIZE];
11 float input[FRAME_SIZE];
12 char cbits[200];
13 int nbBytes;
14 / Holdsthestateoftheencoder /
* *
15 void state;
*
16 / HoldsbitssotheycanbereadandwrittentobytheSpeexroutines /
* *
17 SpeexBitsbits;
18 int i,tmp;
19
20 / Createanewencoderstateinnarrowbandmode /
* *
21 state=speex_encoder_init(&speex_nb_mode);
22
23 / Setthequalityto8(15kbps) /
* *
24 tmp=8;
25 speex_encoder_ctl(state,SPEEX_SET_QUALITY,&tmp);
26
27 inFile=argv[1];
28 fin=fopen(inFile,"r");
29
30 / Initializationofthestructurethatholdsthebits /
* *
31 speex_bits_init(&bits);
32 while (1)
33 {
34 / Reada16bits/sampleaudioframe /
* *
35 fread(in, sizeof(short),FRAME_SIZE,fin);
36 if (feof(fin))
37 break;
38 / Copythe16bitsvaluestofloatsoSpeexcanworkonthem /
* *
39 for (i=0;i<FRAME_SIZE;i++)
40 input[i]=in[i];
41
42 / Flushallthebitsinthestructsowecanencodeanewframe /
* *
43 speex_bits_reset(&bits);
44
45 / Encodetheframe /
* *
46 speex_encode(state,input,&bits);
47 / Copythebitstoanarrayofcharthatcanbewritten /
* *
48 nbBytes=speex_bits_write(&bits,cbits,200);
49
50 / Writethesizeoftheframefirst.Thisiswhatsampledecexpectsbut
*
51 it!flslikelytobedifferentinyourownapplicatio /
*
52 fwrite(&nbBytes, sizeof(int),1,stdout);
53 / Writethecompresseddata /
* *
54 fwrite(cbits,1,nbBytes,stdout);
55
56 }
57
58 / Destroytheencoderstate /
* *
59 speex_encoder_destroy(state);
60 / Destroythebit-packingstruct /
* *
61 speex_bits_destroy(&bits);
62 fclose(fin);
63 return 0;
64 }

//sampledec.c

1 #include <speex/speex.h>
2 #include <stdio.h>
3
4 / Theframesizeinhardcodedforthissamplecodebutitdoesn!thavetobe /
* *
5 #define FRAME_SIZE160
6 int main(int argc, char argv)
**
7 {
8 char outFile;
*
9 FILE fout;
*
10 / Holdstheaudiothatwillbewrittentofile(16bitspersample) /
* *
11 short out[FRAME_SIZE];
12 / Speexhandlesamplesasfloat,soweneedanarrayoffloats /
* *
13 float output[FRAME_SIZE];
14 char cbits[200];
15 int nbBytes;
16 / Holdsthestateofthedecoder /
* *
17 void state;
*
18 / HoldsbitssotheycanbereadandwrittentobytheSpeexroutines /
* *
19 SpeexBitsbits;
20 int i,tmp;
21
22 / Createanewdecoderstateinnarrowbandmode /
* *
23 state=speex_decoder_init(&speex_nb_mode);
24
25 / Settheperceptualenhancementon /
* *
26 tmp=1;
27 speex_decoder_ctl(state,SPEEX_SET_ENH,&tmp);
28
29 outFile=argv[1];
30 fout=fopen(outFile,"w");
31
32 / Initializationofthestructurethatholdsthebits /
* *
33 speex_bits_init(&bits);
34 while (1)
35 {
36 / Readthesizeencodedbysampleenc,thispartwilllikelybe
*
37 differentinyourapplication /
*
38 fread(&nbBytes, sizeof(int),1,stdin);
%d\n",nbBytes);
39 fprintf(stderr,"nbBytes:
40 if (feof(stdin))
41 break;
42
43 / Readthe"packet"encodedbysampleenc /
* *
44 fread(cbits,1,nbBytes,stdin);
45 / Copythedataintothebit-streamstruct /
* *
46 speex_bits_read_from(&bits,cbits,nbBytes);
47
48 / Decodethedata /
* *
49 speex_decode(state,&bits,output);
50
51 / Copyfromfloattoshort(16bits)foroutput /
* *
52 for (i=0;i<FRAME_SIZE;i++)
53 out[i]=output[i];
54
55 / Writethedecodedaudiotofile /
* *
56 fwrite(out, sizeof(short),FRAME_SIZE,fout);
57 }
58
59 / Destroythedecoderstate /
* *
60 speex_decoder_destroy(state);
61 / Destroythebit-streamtruct /
* *
62 speex_bits_destroy(&bits);
63 fclose(fout);
64 return 0;
65 }

23,127

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧