| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 945 人关注过本帖
标题:DELPHI代码改写成C#代码
取消只看楼主 加入收藏
wuyangmouse
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-8-4
收藏
 问题点数:0 回复次数:0 
DELPHI代码改写成C#代码

各位大虾们帮帮忙,谁能把下面的DELPHI代码改写成C#代码,公司一定要用C#实现录音功能,小弟急的快翘辫子了的说!

unit Unit1;

//文件unit1.pas
//描述:DELPHI7的D160A录音系统主程序文件
//版本1.0
//copyright (c) 2002 by 深圳市东进技术股份有限公司 allright reserverd
//联系:techsupport@dj.com.cn
//历史
//index date author notes
// 0 2002-11-07 LRG create this file

interface


uses
tc08a32,Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Grids;

const maxchannel=240;
type ichnltype=(iuser,itrunk,irecord,iempty);

type
channelpara= record
step:integer;
playing:boolean;
chnltype:ichnltype;
end;
TForm1 = class(TForm)
showgrid: TStringGrid;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
chnlnum:integer;
channel:array [0..maxchannel-1] of channelpara;
procedure playmsg(channelno:integer);
procedure resetchannel(channelno:integer);
function cutpcm(sFilename:string;cutlength:integer):integer;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
chnl:integer;
s:string;
begin
loaddrv();
chnlnum:=checkvalidch();
showgrid.RowCount:=chnlnum+1;
showgrid.cells[0,0]:='通道号';
showgrid.cells[1,0]:='通道类型';
showgrid.cells[2,0]:='通道状态';
showgrid.cells[3,0]:='信息内容';
showgrid.ColWidths[3]:=250;
enablecard(chnlnum,1024*60);
setpackrate(0);
setbusypara(320);//原来是320
setdialpara(1000,4000,350,7);
for chnl:=1 to chnlnum do
begin
startsigcheck(chnl-1);
showgrid.cells[0,chnl]:='第'+inttostr(chnl)+'通道号';
if checkchtype(chnl-1)=0 then
begin
showgrid.cells[1,chnl]:='内线';
channel[chnl-1].chnltype:=iuser;
end
else if checkchtype(chnl-1)=1 then
begin
showgrid.cells[1,chnl]:='外线';
channel[chnl-1].chnltype:=itrunk;
end
else if checkchtype(chnl-1)=2 then
begin
showgrid.cells[1,chnl]:='悬空';
showgrid.cells[3,chnl]:='不参与演示';
channel[chnl-1].chnltype:=iempty;
end
else
begin
showgrid.cells[1,chnl]:='录音';
showgrid.cells[3,chnl]:='不参与演示';
channel[chnl-1].chnltype:=irecord;
end;
showgrid.cells[2,chnl]:='挂机';
showgrid.cells[3,chnl]:='空闲';
end;
sig_init(0);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
disablecard();
freedrv();
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
chnl:integer;
begin
push_play;
feedsigfunc;
for chnl:=0 to chnlnum do
begin
if channel[chnl].chnltype=iuser then
begin
if ringdetect(chnl) then
begin
playmsg(chnl);
end
else resetchannel(chnl);
end
else if channel[chnl].chnltype=itrunk then
begin
if channel[chnl].playing then
begin
if sig_checkbusy(chnl)=1 then
begin
resetchannel(chnl);
exit;
end;
playmsg(chnl);
end
else if ringdetect(chnl) then
begin
offhook(chnl);
channel[chnl].playing:=true;
playmsg(chnl);
end
end;
end;


end;

procedure TForm1.playmsg(channelno: integer);
var
i,code:integer;
begin
case channel[channelno].step of
0: begin
startplayfile(channelno,'voc\welcome.pcm',0);
showgrid.Cells[2,channelno+1]:='摘机';
showgrid.Cells[3,channelno+1]:='欢迎致电东进公司…………';
channel[channelno].step:=1;
end;
1:begin
if checkplayend(channelno) then
begin
stopplayfile(channelno);
startrecordfile(channelno,pchar(inttostr(channelno)+'.pcm'),8000*60);//预设置录音长度为1分钟
initdtmfbuf(channelno);
channel[channelno].step:=2;
showgrid.Cells[3,channelno+1]:='开始录音';
end
end;
2:begin
code:=getdtmfcode(channelno);
if code=12 then
begin
stoprecordfile(channelno);
startplayfile(channelno,'voc\end1.pcm',0);
showgrid.Cells[3,channelno+1]:='重播留言';
channel[channelno].step:=3;
exit;
end;
if checkrecordend(channelno) then
begin
stoprecordfile(channelno);
showgrid.Cells[3,channelno+1]:='重播留言';
startplayfile(channelno,'voc\end2.pcm',0);
channel[channelno].step:=3;
end ;
end;
3:begin
if checkplayend(channelno) then
begin
cutpcm(trim(inttostr(channelno)+'.pcm'),3000); //直接去掉末尾3000左右的声音,把最后按键声音去掉
startplayfile(channelno,pchar(inttostr(channelno)+'.pcm'),0);
channel[channelno].step:=4;
end
end;
4:begin
if checkplayend(channelno) then
begin
startplayfile(channelno,'voc\byebye.pcm',0);
channel[channelno].step:=5;
end
end;
5:begin
if checkplayend(channelno) then
begin
resetchannel(channelno);
end
end;
end;
end;

procedure TForm1.resetchannel(channelno: integer);
var
i:integer;
begin
stoprecordfile(channelno);
stopplayfile(channelno);
startsigcheck(channelno);
sig_resetcheck(channelno);
if channel[channelno].chnltype=itrunk then
hangup(channelno);
channel[channelno].step:=0;
channel[channelno].playing:=false;
if showgrid.Cells[2,channelno+1]<>'挂机' then
showgrid.Cells[2,channelno+1]:='挂机';
if showgrid.Cells[3,channelno+1]<>'空闲' then
showgrid.Cells[3,channelno+1]:='空闲';

end;

function TForm1.cutpcm(sFilename: string; cutlength: integer): integer;
var
icount:integer;
cutfile:file;
silence:byte;
begin
{
PCM文件实际上是一个全数据的文件,没有头,也没有尾,因此可以直接对其进行文件
操作,当前例子对其采用在末尾3000左右填充静音的方法,用户也可以采用删除文件
末尾3000方法来实现去录音文件末尾DTMF声音的方法
}
silence:=$55;
if FileExists(sfilename)=false then
begin
result:=-1;
exit;
end;
assignfile(cutfile,sfilename);
reset(cutfile,1);
if filesize(cutfile)<cutlength then
cutlength:=filesize(cutfile);
seek(cutfile,filesize(cutfile)-cutlength);
for icount:=0 to cutlength-1 do
begin
blockwrite(cutfile,silence,1);
end;
closefile(cutfile);
result:=0;
end;

end.

搜索更多相关主题的帖子: DELPHI代码 深圳市 uses Mes 
2006-08-15 10:23
快速回复:DELPHI代码改写成C#代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032397 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved