急!如何将几个WAV文件合并为一个WAV文件?(100分)

  • 主题发起人 主题发起人 zgp2000
  • 开始时间 开始时间
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> &nbsp;//联接WAV声音文件函数。程序源码:周栋梁<br> &nbsp;//调用方法:将所要联接的声音文件的完整路径用“,”号组成字符串。<br>begin<br>Files:=TStringList.Create;<br>Files.CommaText:=WaveFiles;<br>WaveFile:=TFileStream.Create(NewWaveFile,fmCreate);<br>SoureFile:=TFileStream.Create(Files.Strings[0],fmOpenRead); &nbsp;//打开其中一个声音文件<br>WaveFile.CopyFrom(SoureFile,59); &nbsp;//读取声音文件头<br>WaveLen:=0; &nbsp;//记录声音长度<br>for n:=0 to Files.Count-1 do<br>begin<br> &nbsp;SoureFile.Free;<br> &nbsp;SoureFile:=TFileStream.Create(Files.Strings[n],fmOpenRead);<br> &nbsp;SoureFile.Position:=54;<br> &nbsp;SoureFile.read(a1,1);<br> &nbsp;SoureFile.read(a2,1);<br> &nbsp;SoureFile.read(a3,1);<br> &nbsp;WaveLen:=WaveLen+(ord(a3)*65536)+(ord(a2)*256)+ord(a1);<br> &nbsp;SoureFile.Position:=59;<br> &nbsp;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> &nbsp; &nbsp;LinkWave('f:/0.WAV,f:/1.WAV','4.WAV');<br> &nbsp; &nbsp;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> &nbsp;Source1 := TFileStream.Create('f:/0.wav',FmOpenRead);<br> &nbsp;Source2 := TFileStream.Create('f:/1.wav',FmOpenRead);<br> &nbsp;Target := TFileStream.Create('f:/3.wav',fmcreate);<br> &nbsp;Target.Position := 0;<br> &nbsp;Target.CopyFrom(Source1,0);<br> &nbsp;Target.Seek(0,soFromEnd);<br> &nbsp;Target.CopyFrom(Source2,0);<br> &nbsp;Source1.Free;<br> &nbsp;source2.Free;<br> &nbsp;Target.Free;<br>end;<br><br>急寻高手解答,谢谢!!!!
 
wave 文件头中包含声音数据长度信息,你必需发修改新WAVE文件的文件头!<br>文件头可用下面的记录表示:<br>TWavHeader = record <br> &nbsp; &nbsp;rId : longint; <br> &nbsp; &nbsp;rLen : longint; <br> &nbsp; &nbsp;wId : longint; <br> &nbsp; &nbsp;fId : longint; <br> &nbsp; &nbsp;fLen : longint; <br> &nbsp; &nbsp;wFormatTag : word; <br> &nbsp; &nbsp;nChannels : word; <br> &nbsp; &nbsp;nSamplesPerSec : longint; <br> &nbsp; &nbsp;nAvgBytesPerSec : longint; <br> &nbsp; &nbsp;nBlockAlign : word; <br> &nbsp; &nbsp;wBitsPerSample : word; <br> &nbsp; &nbsp;dId : longint; <br> &nbsp; &nbsp;wSampleLength : longint; <br>end;
 
to Luckm<br> &nbsp; &nbsp; 能不能说详细点啊,这方面我不是很懂啊。
 
http://www.ysza.com 原创软件里有,你可以看看,需要得话,联系我<br>dxmylove@yahoo.com.cn qq:171833017<br>---------------------------------------<br>http://www.942kdy.com 免费电影<br>http://www.mttx365.com 美图天下365<br>http://www.haha77.com 成人笑话
 
to &nbsp;一生中最爱<br> &nbsp; &nbsp;没有提供源码啊。
 
帮顶!<br><br>╭=========================================╮<br><br> &nbsp; 80G海量源代码,控件,书籍全免费狂下不停!<br><br> &nbsp; http://www.source520.com<br> &nbsp;<br>╰=========================================╯
 
下面是一个创建空白声音文件的例子,你可以参考一下:<br>procedure TForm1.CreateWav( channels : word; { 1(单声)或者2(立体声) }<br>resolution : word; { 8或者16,代表8位或16位声音 }<br>rate : longint; { 声音频率,如11025,22050, 44100}<br>fn : string { 对应的文件名称 } );<br>var<br>wf : file of TWavHeader;<br>wh : TWavHeader;<br>begin<br>wh.rId := $46464952; <br>wh.rLen := 36; <br>wh.wId := $45564157; <br>wh.fId := $20746d66; <br>wh.fLen := 16; <br>wh.wFormatTag := 1; <br>wh.nChannels := channels; <br>wh.nSamplesPerSec := rate; <br>wh.nAvgBytesPerSec := channels*rate*(resolution div 8);<br>wh.nBlockAlign := channels*(resolution div 8);<br>wh.wBitsPerSample := resolution;<br>wh.dId := $61746164; <br>wh.wSampleLength := 0; <br>assignfile(wf,fn); <br>rewrite(wf); <br>write(wf,wh); <br>closefile(wf); <br>end;
 
空的我会建立,关键是怎样合成一个文件。
 
把各个声音文件的文件头砍掉后接起来。在重新写个文件头。把声音的大小写为合成后的大小就行动了。(但是各个声音格式要统一。单声道全部是单声道、或全部是立体声、否则合成后声音变音)
 
弟兄们啊,我需要源码啊。能不能发个例子到我的邮箱啊。我没有<br>做过这类软件啊。我只需要一个简单的例子就可以了。谢谢!<br>source2005@126.com
 
要插件或源码的都可以直接和我联系,qq:171833017,www.ysza.com,dxmylove@yahoo.com.cn<br>---------------------<br>&lt;a href='http://www.942kdy.com'&gt;免费影视--看免费大片&lt;/a&gt;<br>&lt;a href='http://www.mttx365.com'&gt;美图天下--看漂亮妹妹&lt;/a&gt;<br>&lt;a href='http://www.haha77.com'&gt;幽默笑话--让你一次笑个够&lt;/a&gt;
 
to 一生中最爱<br> &nbsp; &nbsp;你老不在线啊,我给你发信息怎么没见回啊?何时在线告诉我一声。我<br>一般中午和晚上在线。我QQ:108407914
 
还是没解决问题,再次求助!
 
帮顶!<br><br>╭=========================================╮<br><br> &nbsp; 80G海量源代码,控件,书籍全免费狂下不停!<br><br> &nbsp; http://www.source520.com<br> &nbsp; <br> &nbsp; 个人网站站长开发推广同盟,让所有人知道你的世界!<br> &nbsp; <br> &nbsp; http://www.source520.com/search/search.asp<br> &nbsp;<br>╰=========================================╯
 
那怎样去掉wav文件的文件头有源码码?有这个也应该可以了
 
把前面44个字节去掉啊。下面是44字节的文件头<br> TWavHeader = record //定义一个Wav文件头格式 &nbsp;44字节<br> &nbsp; rId : longint; &nbsp; &nbsp; //4字节 &nbsp; riff<br> &nbsp; rLen : longint; &nbsp; &nbsp; //4字节<br> &nbsp; wId : longint; &nbsp; &nbsp; &nbsp;//4字节 &nbsp;wave<br> &nbsp; fId : longint; &nbsp; &nbsp; &nbsp;//4字节 &nbsp; fmt<br> &nbsp; fLen : longint; &nbsp; &nbsp; //4字节<br> &nbsp; wFormatTag : word; &nbsp;//2字节 &nbsp;WFormatTag用来设置wav格式<br> &nbsp; nChannels : word; &nbsp; &nbsp;//2字节 &nbsp;nChannels用来设置声道个数;<br> &nbsp; nSamplesPerSec : longint; &nbsp;//4字节 &nbsp;nSamplesPerSec用来设置采样频率;<br> &nbsp; nAvgBytesPerSec : longint; &nbsp;//4字节 &nbsp; nAvgBytesPerSec用来设置每秒所需字节数;<br> &nbsp; nBlockAlign : word; &nbsp; &nbsp; &nbsp; //2字节 &nbsp;nBlockAlign用来设置每个采样点所需总字节数<br> &nbsp; wBitsPerSample : word; &nbsp; &nbsp;//2字节 &nbsp;wBitsPerSample用来设置每个采样点所需Bit数。<br> &nbsp; dId : longint; &nbsp; &nbsp; &nbsp; &nbsp; //4字节 &nbsp;data<br> &nbsp; wSampleLength : longint; &nbsp;//4字节<br> &nbsp;end;
 
如何去?我知道怎么读取,但不会去除文件头
 
读即是去!去即是读!先读44个字节不要就可以了。或从第45个字节处开始读啊
 
帮帮忙,看看我的代码,可能只查一步了,如何从第45个字节读取文件?我合并后文件没有<br>声音。文件格式还是对的。<br><br>Function Cjt_AddtoFile(SourceFile,TargetFile:string):Boolean;<br>var<br>Target,Source:TFileStream;<br>MyFileSize:integer;<br>begin<br>try<br>Source:=TFileStream.Create(SourceFile,fmOpenRead or fmShareExclusive);<br>Target:=TFileStream.Create(TargetFile,fmOpenWrite or fmShareExclusive);<br>try<br>Target.Seek(0,soFromEnd);//往尾部添加资源<br>Target.CopyFrom(Source,0);<br>MyFileSize:=Source.Size+Sizeof(MyFileSize);//计算资源大小,并写入辅程尾部<br>Target.WriteBuffer(MyFileSize,sizeof(MyFileSize));<br>finally<br>Target.Free;<br>Source.Free;<br>end;<br>except<br>Result:=False;<br>Exit;<br>end;<br>Result:=True;<br>end;<br><br><br><br>procedure TForm1.CreateWav( channels : word; { 1(单声)或者2(立体声) }<br>resolution : word; { 8或者16,代表8位或16位声音 }<br>rate : longint; { 声音频率,如11025,22050, 44100}<br>fn : string { 对应的文件名称 } );<br>var<br>wf : file of TWavHeader;<br>wh : TWavHeader;<br>begin<br>wh.rId := $46464952; <br>wh.rLen := 36; <br>wh.wId := $45564157; <br>wh.fId := $20746d66; <br>wh.fLen := 16;<br>wh.wFormatTag := 1; <br>wh.nChannels := channels; <br>wh.nSamplesPerSec := rate; <br>wh.nAvgBytesPerSec := channels*rate*(resolution div 8);<br>wh.nBlockAlign := channels*(resolution div 8);<br>wh.wBitsPerSample := resolution;<br>wh.dId := $61746164; <br>wh.wSampleLength := 0; <br><br>assignfile(wf,fn); {打开对应文件 }<br>rewrite(wf); {移动指针到文件头} <br>write(wf,wh); {写进文件头 } <br>closefile(wf); {关闭文件 } <br>end;<br><br><br>procedure TForm1.Button7Click(Sender: TObject);<br>begin<br> &nbsp;CreateWav(1, 16, 22050, (ExtractFilePath(Application.ExeName)+ 'temp.wav'));<br> &nbsp;Cjt_AddtoFile((ExtractFilePath(Application.ExeName)+ '0.wav'),(ExtractFilePath(Application.ExeName)+ 'temp.wav'));<br> &nbsp;playsound(pchar((ExtractFilePath(Application.ExeName)+ 'temp.wav')),0,0);<br>end;<br><br>end.
 
你这里<br>Target.Seek(0,soFromEnd);//往尾部添加资源<br>Target.CopyFrom(Source,0);<br>[red]Source要先去文件头[/red]<br>合成后要重写文件头中参数<br>wh.wSampleLength := 合成后的大小;
 
后退
顶部