您的位置:程序门 -> delphi -> windows sdk/api



合併多個 wav文件為一個文件


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


合併多個 wav文件為一個文件
发表于:2008-02-20 17:25:44 楼主
網上看了下,提問的多,但是解決了的還沒見著。
那位做過的給點demo吧,謝謝。

就是把幾個文件合併成一個然後播放出來。
发表于:2008-02-20 17:37:481楼 得分:0
delphi(pascal) code
应该类似这样,如果再复杂点就得分析wav文件格式 var aryms:array of tmemorystream; temp: tmemorystream; begin ...... temp.clear; temp.seek(0,sobeginning); aryms[0].seek(0,sofrombeginning); temp.copyfrom( aryms[0],aryms[0].size ); aryms[1].seek(0,sofrombeginning); temp.copyfrom( aryms[1],aryms[1].size ); aryms[3].seek(0,sofrombeginning); temp.copyfrom( aryms[3],aryms[3].size ); aryms[2].seek(0,sofrombeginning); temp.copyfrom( aryms[2],aryms[2].size ); aryms[4].seek(0,sofrombeginning); temp.copyfrom( aryms[4],aryms[4].size ); temp.savetofile( 'f:\av.wav' ); ..... end;
 
发表于:2008-02-20 17:37:492楼 得分:0
一个个的播吧,效果也不错的
发表于:2008-02-20 17:59:043楼 得分:0
現在就是一個一個的播放,這樣cpu佔用會很大,并且有點慢.
发表于:2008-02-21 14:59:074楼 得分:0
做成资源文件,然后用playsound播放
发表于:2008-02-21 14:59:555楼 得分:0
好像是在内存中处理,速度也还不错
发表于:2008-02-22 20:18:046楼 得分:0
沒有更好的辦法了麼?
发表于:2008-02-23 08:54:277楼 得分:0
需要合并的*.wav文件都是动态生成的吧
要不然通过其他软件合并起来再playsound不知道行不行
^_^都是高手,不敢乱说,呵呵
发表于:2008-02-23 12:57:238楼 得分:0
搜了以前的帖子,有种方案是通过分析实现

另外这几个wav文件的音频格式是否相同?

先留个记号,关注一下。
发表于:2008-02-23 14:38:049楼 得分:0
up
发表于:2008-02-23 16:23:0410楼 得分:0
所有文件格式都是一樣的
发表于:2008-02-23 20:05:5611楼 得分:0
参考如下代码:
delphi(pascal) code
type twavformat = packed record chunkid: array[0..3] of char; //'riff' chunksize: longword; // file size - 8 [bytes] format: array[0..3] of char; // 'wave' subchunk1id: array[0..3] of char; // 'fmt ' mind the space! subchunk1size: longword; // hex10 audioformat: word; // hex 01 numofchannels: word; //1 mono, 2 stereo samplerate: longword; // number of samples/sec byterate: longword; // samplerate* num of channels* // bytes per (mono) sample bytespersample: word; // size of (mono) sample [bytes] bitspersample: word; // bytespersample *8 subchunk2id: array[0..3] of char; //'data' subchunk2size: longword; //number of data bytes end; function concatwavfile(awavfile1, awavfile2, anewfile: string): boolean; var vwavformat1: twavformat; vwavformat2: twavformat; vfilehandle1: thandle; vfilehandle2: thandle; vfilestream1: tfilestream; vfilestream2: tfilestream; vchunksize1, vchunksize2: integer; begin result := false; if not fileexists(awavfile1) then exit; if not fileexists(awavfile2) then exit; vfilehandle1 := _lopen(pchar(awavfile1), of_read or of_share_deny_none); vfilehandle2 := _lopen(pchar(awavfile2), of_read or of_share_deny_none); if (integer(vfilehandle1) <= 0) or (integer(vfilehandle2) <= 0) then begin _lclose(vfilehandle1); _lclose(vfilehandle2); exit; end; vfilestream1 := tfilestream.create(vfilehandle1); vfilestream2 := tfilestream.create(vfilehandle2); try if vfilestream1.read(vwavformat1, sizeof(twavformat)) <> sizeof(twavformat) then exit; if vfilestream2.read(vwavformat2, sizeof(twavformat)) <> sizeof(twavformat) then exit; if vwavformat1.chunkid <> 'riff' then exit; if vwavformat1.subchunk2id <> 'data' then exit; vchunksize1 := vwavformat1.subchunk2size; vchunksize2 := vwavformat2.subchunk2size; vwavformat1.chunksize := 0; vwavformat1.subchunk2size := 0; vwavformat2.chunksize := 0; vwavformat2.subchunk2size := 0; if not comparemem(@vwavformat1, @vwavformat2, sizeof(twavformat)) then exit; //格式不相同 with tmemorystream.create do try vwavformat1.chunksize := vchunksize1 + vchunksize2 + sizeof(vwavformat1) - 8; vwavformat1.subchunk2size := vchunksize1 + vchunksize2; write(vwavformat1, sizeof(twavformat)); copyfrom(vfilestream1, vchunksize1); copyfrom(vfilestream2, vchunksize2); try savetofile(anewfile); except exit; end; finally free; end; finally vfilestream1.free; vfilestream2.free; end; result := true; end; { concatwavfile } procedure tform1.button1click(sender: tobject); begin concatwavfile('c:\windows\media\chord.wav', 'c:\windows\media\chimes.wav', 'c:\temp\temp.wav'); end;
发表于:2008-02-24 14:52:5212楼 得分:0
调用dos命令copy不就可以合并了吗?
发表于:2008-02-24 19:04:5213楼 得分:0
如果只是用一下,可以试试goldwave软件合并的效果很好.呵呵.
发表于:2008-02-26 12:35:5514楼 得分:0
copy肯定是不行的,那是针对文本文件有效.

谢谢伴水了,晚上回去试一下.
发表于:2008-02-26 13:01:0115楼 得分:0
if   vwavformat1.subchunk2id   <>   'data'   then   exit;
执行到这里时就退出了。
发表于:2008-02-26 13:19:3116楼 得分:0
读出来的是fact而不是data


快速检索

最新资讯
热门点击