资源描述:
《delphi合并流文件》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls;typeTForm1=class(TForm)Button1:TButton;Button2:TButton;procedureFormCreate(Sender:TObject);procedureFormDestroy(Sender:TObject);procedureButton1Click(Sender:T
2、Object);procedureButton2Click(Sender:TObject);end;varForm1:TForm1;implementation{$R*.dfm}usesMMSystem;{合并两个Wav文件流的函数}functionConWavStream(AWavStream1,AWavStream2:TStream;varANewStream:TStream):Boolean;typeTWavFormat=packedrecordChunkID:array[0..3]ofAnsiChar;{'RIFF'
3、}ChunkSize:Longword;{size-8}Format:array[0..3]ofAnsiChar;{'WAVE'}SubChunk1ID:array[0..3]ofAnsiChar;{'fmt'}SubChunk1Size:Longword;{hex10}AudioFormat:Word;{hex01}NumOfChannels:Word;{1mono,2stereo}SampleRate:Longword;{numberofsamples/sec}ByteRate:Longword;{samplerate*
4、numofchannels*bytesper(mono)sample}BytesperSample:Word;{sizeof(mono)sample}BitsPerSample:Word;{BytesperSample*8}SubChunk2ID:array[0..3]ofAnsiChar;{'data'}SubChunk2Size:Longword;{numberofdatabytes}end;varvWavFormat1:TWavFormat;vWavFormat2:TWavFormat;vChunkSize1,vChu
5、nkSize2:Integer;beginResult:=False;ifAWavStream1.Read(vWavFormat1,SizeOf(TWavFormat))<>SizeOf(TWavFormat)thenExit;ifAWavStream2.Read(vWavFormat2,SizeOf(TWavFormat))<>SizeOf(TWavFormat)thenExit;ifvWavFormat1.ChunkID<>'RIFF'thenExit;ifvWavFormat1.SubChunk2ID<>'data't
6、henExit;vChunkSize1:=vWavFormat1.SubChunk2Size;vChunkSize2:=vWavFormat2.SubChunk2Size;vWavFormat1.ChunkSize:=0;vWavFormat1.SubChunk2Size:=0;vWavFormat2.ChunkSize:=0;vWavFormat2.SubChunk2Size:=0;ifnotCompareMem(@vWavFormat1,@vWavFormat2,SizeOf(TWavFormat))thenExit;{
7、格式不同}vWavFormat1.ChunkSize:=vChunkSize1+vChunkSize2+SizeOf(vWavFormat1)-8;vWavFormat1.SubChunk2Size:=vChunkSize1+vChunkSize2;ANewStream.Write(vWavFormat1,SizeOf(TWavFormat));ANewStream.CopyFrom(AWavStream1,vChunkSize1);ANewStream.CopyFrom(AWavStream2,vChunkSize2);R
8、esult:=True;end;{ConWavStreamEnd}varWavStream:TStream;{合并两个资源流;之前要在资源中分别加载两个WAV文件,并分别命名:wav1、wav2}procedureTForm1.FormCreate(Sender:TObject);varr