Z
zgp2000
Unregistered / Unconfirmed
GUEST, unregistred user!
急!如何将几个WAV文件合并为一个WAV文件?我用大富翁里面的找到的一个代码试了一下,可以合并,但是合并后的文件大小是合并后的大小,但是播放时只有第一个文件的播放音,后面几个文件播放没声音。代码如下<br><br>procedure LinkWave(waveFiles, NewWaveFile: string);//WaveFiles:原文件串(必须是完整路径);NewWaveFile:生成的文件名<br>var<br> Files:TStringList;<br> n1,n2,n3,n,WaveLen:Integer;<br> WaveFile,SoureFile:TFileStream;<br> a1,a2,a3:byte;<br> //联接WAV声音文件函数。程序源码:周栋梁<br> //调用方法:将所要联接的声音文件的完整路径用“,”号组成字符串。<br>begin<br>Files:=TStringList.Create;<br>Files.CommaText:=WaveFiles;<br>WaveFile:=TFileStream.Create(NewWaveFile,fmCreate);<br>SoureFile:=TFileStream.Create(Files.Strings[0],fmOpenRead); //打开其中一个声音文件<br>WaveFile.CopyFrom(SoureFile,59); //读取声音文件头<br>WaveLen:=0; //记录声音长度<br>for n:=0 to Files.Count-1 do<br>begin<br> SoureFile.Free;<br> SoureFile:=TFileStream.Create(Files.Strings[n],fmOpenRead);<br> SoureFile.Position:=54;<br> SoureFile.read(a1,1);<br> SoureFile.read(a2,1);<br> SoureFile.read(a3,1);<br> WaveLen:=WaveLen+(ord(a3)*65536)+(ord(a2)*256)+ord(a1);<br> SoureFile.Position:=59;<br> WaveFile.CopyFrom(SoureFile,SoureFile.Size-60);<br>end;<br>WaveFile.Position:=4;<br>n1:=(WaveFile.Size-8) div 65536;<br>n2:=(WaveFile.Size-8-n1*65536) div 256;<br>n3:=WaveFile.Size-8-n1-n2*256;<br>WaveFile.WriteBuffer(n3,1);<br>WaveFile.WriteBuffer(n2,1);<br>WaveFile.WriteBuffer(n1,1);<br><br>n1:=WaveLen div 65536;<br>n2:=(WaveLen-n1*65536) div 256;<br>n3:=WaveLen-n1-n2*256;<br>WaveFile.Position:=54;<br>WaveFile.WriteBuffer(n3,1);<br>WaveFile.WriteBuffer(n2,1);<br>WaveFile.WriteBuffer(n1,1);<br>WaveFile.Position:=46;<br>WaveFile.WriteBuffer(n3,1);<br>WaveFile.WriteBuffer(n2,1);<br>WaveFile.WriteBuffer(n1,1);<br>Files.Free;<br>WaveFile.Free;<br>SoureFile.Free;<br>end;<br><br><br><br><br>procedure TForm1.Button3Click(Sender: TObject);<br>begin<br> LinkWave('f:/0.WAV,f:/1.WAV','4.WAV');<br> playsound('f:/4.WAV',0,0);<br>end;<br><br><br><br><br><br>还有一段代码是这样的,但是也是合并后只有第一个文件的播放音。<br>procedure TForm1.Button1Click(Sender: TObject);<br>var Source1,Source2,Target: TFileStream;<br>begin<br> Source1 := TFileStream.Create('f:/0.wav',FmOpenRead);<br> Source2 := TFileStream.Create('f:/1.wav',FmOpenRead);<br> Target := TFileStream.Create('f:/3.wav',fmcreate);<br> Target.Position := 0;<br> Target.CopyFrom(Source1,0);<br> Target.Seek(0,soFromEnd);<br> Target.CopyFrom(Source2,0);<br> Source1.Free;<br> source2.Free;<br> Target.Free;<br>end;<br><br>急寻高手解答,谢谢!!!!