X
xdengni
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure Wave_SaveFile(const FileName, TempFileName: string;
DataLength:
LongInt;
WaveFmt: TWAVEFORMATEX;
Dhio: HMMIO;
tSave: TSave_Type;
const StartPoi: LongInt = 0;
const SaveLength: LongInt = 0);
var
hio: HMMIO;
//音频文件句柄
Buf: PChar;
//用于读取数据的缓冲区
ck: TMMCKINFO;
//音频信息结构
SaveLoop: LongInt;
//循环读取数据的次数
Length: LongInt;
//要保存数据的长度
i: LongInt;
MODSaveSize: LongInt;
//最后一次数据的长度
SaveSize: LongInt;
//要写入文件的数据的长度
TempFile: Integer;
//临时文件句柄 ( 在录音状态下时有效 )
SaveStartPoi: LongInt;
//保存数据在文件中的开始处
begin
Application.ProcessMessages;
//处理 Windows 消息
TempFile := 0;
if (tSave = CS_SAVE_PLAY) and (SaveLength > 0) and (StartPoi < DataLength)
and (StartPoi > 0) and ((StartPoi + SaveLength) <= DataLength) and (StartPoi
< DataLength) then
begin
Length := SaveLength;
SaveStartPoi := StartPoi;
end
else
begin
Length := DataLength;
SaveStartPoi := 0;
end;
SaveLoop := Length div LoadMemSize;
MODSaveSize := 0;
if (Length mod LoadMemSize) <> 0 then
begin
SaveLoop := SaveLoop + 1;
MODSaveSize := Length mod LoadMemSize;
end;
if tSave <> CS_SAVE_NEW then
SendMessage(Application.MainForm.Handle, CM_begin
SAVE, SaveLoop, 0);
if FileExists(FileName) then
//删除已有的目标文件
DeleteFile(FileName);
//创建成一个新的音频文件
hio := mmioOpen(PChar(FileName), nil, MMIO_CREATE + MMIO_READWRITE);
if hio = 0 then
raise EMMIO.Create('无法创建文件');
try
if WaveFmt.wFormatTag = WAVE_FORMAT_PCM then
//波形格式的大小
ck.cksize := Length + 4 + 8 + SizeOf(WaveFmt) - 2 + 8 // Length: 文件大小
else
ck.cksize := Length + 4 + 8 + SizeOf(WaveFmt) + WaveFmt.cbSize + 8;
ck.fccType := mmioStringToFOURCC('WAVE', 0);
//创建文件头
if 0 <> mmioCreateChunk(hio, @ck, MMIO_CREATERIFF) then
raise EMMIO.Create('建立文件头错误');
// 创建fmt chunks
ck.ckid := mmioStringToFOURCC('fmt', 0);
//创建 fmt 块
if WaveFmt.wFormatTag = WAVE_FORMAT_PCM then
ck.cksize := SizeOf(WaveFmt) - 2 //fmt 块的大小
else
ck.cksize := SizeOf(WaveFmt) + WaveFmt.cbSize;
if 0 <> mmioCreateChunk(hio, @ck, 0) then
raise EMMIO.Create('建立 fmt 块错误');
mmioWrite(hio, PChar(@WaveFmt), ck.cksize);
// 创建data chunks
ck.ckid := mmioStringToFOURCC('data', 0);
//创建 data 数据块
ck.cksize := Length;
// Length: 文件大小
if 0 <> mmioCreateChunk(hio, @ck, 0) then
raise EMMIO.Create('建立 data 块错误');
if tSave = CS_SAVE_NEW then
begin
mmioClose(hio, 0);
//关闭目标音频文件
Exit;
end;
case tSave of //把文件指针移到指定位置
CS_SAVE_PLAY: mmioSeek(Dhio, DataLength - SaveStartPoi, SEEK_END);
CS_SAVE_RECORD:
begin
TempFile := FileOpen(TempFileName, fmOpenRead);
//以只读方式打开文件
if TempFile = 0 then
raise EMMIO.Create('数据读取错误');
end;
end;
for i := 1 to SaveLoopdo
begin
if (MODSaveSize <> 0) and (i = SaveLoop) then
begin
//开辟内存
Buf := PChar(GlobalAllocPtr(GMEM_MOVEABLE or GMEM_SHARE, MODSaveSize));
SaveSize := MODSaveSize;
//要播放的音频数据的长度
end
else
begin
Buf := PChar(GlobalAllocPtr(GMEM_MOVEABLE or GMEM_SHARE, LoadMemSize));
SaveSize := LoadMemSize;
end;
try
if Buf = nil then
raise EMMIO.Create('不能分配内存!');
try //读取与写音频数据
case tSave of
CS_SAVE_PLAY:
if mmioRead(Dhio, Buf, SaveSize) <> SaveSize then
raise EMMIO.Create('读取数据出错:可能文件已被破坏!');
CS_SAVE_RECORD:
begin
if FileRead(TempFile, Buf^, SaveSize) <> SaveSize then
raise EMMIO.Create('读取数据出错:可能文件已被破坏!');
end;
end;
if SaveSize <> mmioWrite(hio, Buf, SaveSize) then
raise EMMIO.Create('写语音数据错误');
finally
GloBalFreePtr(Buf);
//释放内存
SendMessage(Application.MainForm.Handle, CM_SAVEPOSI, i, 0);
end;
finally
end;
end;
finally
if tSave = CS_SAVE_RECORD then
FileClose(TempFile);
//关闭临时文件
mmioClose(hio, 0);
//关闭目标音频文件
end;
//发送保存完毕的消息
SendMessage(Application.MainForm.Handle, CM_ENDSAVE, 0, 0);
end;
上面是别人的程序。我不能运行,应该怎么调试呀
DataLength:
LongInt;
WaveFmt: TWAVEFORMATEX;
Dhio: HMMIO;
tSave: TSave_Type;
const StartPoi: LongInt = 0;
const SaveLength: LongInt = 0);
var
hio: HMMIO;
//音频文件句柄
Buf: PChar;
//用于读取数据的缓冲区
ck: TMMCKINFO;
//音频信息结构
SaveLoop: LongInt;
//循环读取数据的次数
Length: LongInt;
//要保存数据的长度
i: LongInt;
MODSaveSize: LongInt;
//最后一次数据的长度
SaveSize: LongInt;
//要写入文件的数据的长度
TempFile: Integer;
//临时文件句柄 ( 在录音状态下时有效 )
SaveStartPoi: LongInt;
//保存数据在文件中的开始处
begin
Application.ProcessMessages;
//处理 Windows 消息
TempFile := 0;
if (tSave = CS_SAVE_PLAY) and (SaveLength > 0) and (StartPoi < DataLength)
and (StartPoi > 0) and ((StartPoi + SaveLength) <= DataLength) and (StartPoi
< DataLength) then
begin
Length := SaveLength;
SaveStartPoi := StartPoi;
end
else
begin
Length := DataLength;
SaveStartPoi := 0;
end;
SaveLoop := Length div LoadMemSize;
MODSaveSize := 0;
if (Length mod LoadMemSize) <> 0 then
begin
SaveLoop := SaveLoop + 1;
MODSaveSize := Length mod LoadMemSize;
end;
if tSave <> CS_SAVE_NEW then
SendMessage(Application.MainForm.Handle, CM_begin
SAVE, SaveLoop, 0);
if FileExists(FileName) then
//删除已有的目标文件
DeleteFile(FileName);
//创建成一个新的音频文件
hio := mmioOpen(PChar(FileName), nil, MMIO_CREATE + MMIO_READWRITE);
if hio = 0 then
raise EMMIO.Create('无法创建文件');
try
if WaveFmt.wFormatTag = WAVE_FORMAT_PCM then
//波形格式的大小
ck.cksize := Length + 4 + 8 + SizeOf(WaveFmt) - 2 + 8 // Length: 文件大小
else
ck.cksize := Length + 4 + 8 + SizeOf(WaveFmt) + WaveFmt.cbSize + 8;
ck.fccType := mmioStringToFOURCC('WAVE', 0);
//创建文件头
if 0 <> mmioCreateChunk(hio, @ck, MMIO_CREATERIFF) then
raise EMMIO.Create('建立文件头错误');
// 创建fmt chunks
ck.ckid := mmioStringToFOURCC('fmt', 0);
//创建 fmt 块
if WaveFmt.wFormatTag = WAVE_FORMAT_PCM then
ck.cksize := SizeOf(WaveFmt) - 2 //fmt 块的大小
else
ck.cksize := SizeOf(WaveFmt) + WaveFmt.cbSize;
if 0 <> mmioCreateChunk(hio, @ck, 0) then
raise EMMIO.Create('建立 fmt 块错误');
mmioWrite(hio, PChar(@WaveFmt), ck.cksize);
// 创建data chunks
ck.ckid := mmioStringToFOURCC('data', 0);
//创建 data 数据块
ck.cksize := Length;
// Length: 文件大小
if 0 <> mmioCreateChunk(hio, @ck, 0) then
raise EMMIO.Create('建立 data 块错误');
if tSave = CS_SAVE_NEW then
begin
mmioClose(hio, 0);
//关闭目标音频文件
Exit;
end;
case tSave of //把文件指针移到指定位置
CS_SAVE_PLAY: mmioSeek(Dhio, DataLength - SaveStartPoi, SEEK_END);
CS_SAVE_RECORD:
begin
TempFile := FileOpen(TempFileName, fmOpenRead);
//以只读方式打开文件
if TempFile = 0 then
raise EMMIO.Create('数据读取错误');
end;
end;
for i := 1 to SaveLoopdo
begin
if (MODSaveSize <> 0) and (i = SaveLoop) then
begin
//开辟内存
Buf := PChar(GlobalAllocPtr(GMEM_MOVEABLE or GMEM_SHARE, MODSaveSize));
SaveSize := MODSaveSize;
//要播放的音频数据的长度
end
else
begin
Buf := PChar(GlobalAllocPtr(GMEM_MOVEABLE or GMEM_SHARE, LoadMemSize));
SaveSize := LoadMemSize;
end;
try
if Buf = nil then
raise EMMIO.Create('不能分配内存!');
try //读取与写音频数据
case tSave of
CS_SAVE_PLAY:
if mmioRead(Dhio, Buf, SaveSize) <> SaveSize then
raise EMMIO.Create('读取数据出错:可能文件已被破坏!');
CS_SAVE_RECORD:
begin
if FileRead(TempFile, Buf^, SaveSize) <> SaveSize then
raise EMMIO.Create('读取数据出错:可能文件已被破坏!');
end;
end;
if SaveSize <> mmioWrite(hio, Buf, SaveSize) then
raise EMMIO.Create('写语音数据错误');
finally
GloBalFreePtr(Buf);
//释放内存
SendMessage(Application.MainForm.Handle, CM_SAVEPOSI, i, 0);
end;
finally
end;
end;
finally
if tSave = CS_SAVE_RECORD then
FileClose(TempFile);
//关闭临时文件
mmioClose(hio, 0);
//关闭目标音频文件
end;
//发送保存完毕的消息
SendMessage(Application.MainForm.Handle, CM_ENDSAVE, 0, 0);
end;
上面是别人的程序。我不能运行,应该怎么调试呀