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

  • 主题发起人 主题发起人 zgp2000
  • 开始时间 开始时间
to 网中戏<br> &nbsp; &nbsp; &nbsp;我就是那一块去文件头再重写不会啊。你将源码帖出,我调试成功就送分给你了!<br>谢谢!
 
var<br> tempSmallInt;integer ;<br>.............<br>Source.Position:=0;//定位<br>[red]Source.ReadBuffer(tempSmallInt,44);//先进读44字节[/red]<br>Target.CopyFrom(Source,0);//因为上面读了44字节现在就会自动从45字节复制了<br>.......................
 
to 网中戏<br> &nbsp; 我加到软件众好像报错,运行不能通过
 
是我这一句错吗?[red]Source.ReadBuffer(tempSmallInt,44);//先进读44字节[/red]<br>别的是你的代码呀!你把流改成功内存流。我用TMemoryStream合成成功的。
 
晕,现成的activex插件,应用代码可以在www.ysza.com下载,qq:171833017,平常都在,隐身。<br>-----------------------------------------<br>更多美图--http://www.mttx365.com<br>幽默笑话--http://www.haha77.com<br>免费影视--http://www.103h.com
 
to 网中戏<br> &nbsp; &nbsp;你干脆将源码全部帖出来得了,或者发到我邮箱啊。source2005@126.com
 
还是没解决啊,弟兄们,帮帮忙啊!
 
我建立一个wav空文件头,将一个语音文件去除文件头,合成成功。<br>但是在此基础上再合成wav文件,则只有第一次合成进去的语音,后面<br>合成的都没有声音。但文件是合并后的大小,合并还是进入了。<br>请高手指点一下。是不是最后要重写文件头?如何重写?只差最后一步了!<br>procedure TForm1.Button8Click(Sender: TObject);<br>var<br> &nbsp;stream: TMemoryStream;<br> &nbsp;TempStream:TFileStream;<br> &nbsp;ThisInt:Int64;<br>begin<br> &nbsp; &nbsp;CreateWav(1, 16, 22050, ('f:/temp.wav'));<br> &nbsp; &nbsp;stream:= TMemoryStream.Create;<br> &nbsp; &nbsp;TempStream:= TFileStream.Create('f:/temp.wav',fmOpenReadWrite or fmShareDenyNone );<br> &nbsp; &nbsp;stream.LoadFromFile('f:/0.wav');<br> &nbsp; &nbsp;stream.ReadBuffer(ThisInt,44);<br> &nbsp; &nbsp;TempStream.CopyFrom(stream,0);<br> &nbsp; &nbsp;stream.Free;<br> &nbsp; &nbsp;TempStream.Free;<br>end;
 
void writewavefile(char* filepath, void* buffer, unsigned long bytestowrite)<br>{<br> FILE* pf;<br> WAVE_FILE_HEADER wfh;<br> pf = fopen(filepath,&quot;r+b&quot;);<br> if (NULL == pf)<br> {<br> pf = fopen(filepath,&quot;wb&quot;);<br> // wite file header<br> wfh.riff_hdr.id[0] = 'R';<br> wfh.riff_hdr.id[1] = 'I';<br> wfh.riff_hdr.id[2] = 'F';<br> wfh.riff_hdr.id[3] = 'F';<br> wfh.riff_hdr.len = 50;<br> <br> wfh.wave_id[0] = 'W';<br> wfh.wave_id[1] = 'A';<br> wfh.wave_id[2] = 'V';<br> wfh.wave_id[3] = 'E';<br><br> wfh.fmt_hdr.id[0] = 'f';<br> wfh.fmt_hdr.id[1] = 'm';<br> wfh.fmt_hdr.id[2] = 't';<br> wfh.fmt_hdr.id[3] = 32;<br> wfh.fmt_hdr.len = 18;<br><br> wfh.fmt_ck.wFormatTag = fc.wFormatTag ;<br> wfh.fmt_ck.wChannels = fc.wChannels;<br> wfh.fmt_ck.dwSamplesPerSec = fc.dwSamplesPerSec;<br> wfh.fmt_ck.dwAvgBytesPerSec = fc.dwAvgBytesPerSec;<br> wfh.fmt_ck.wBlockAlign = fc.wBlockAlign;<br> wfh.fmt_ck.FormatSpecific = fc.FormatSpecific;<br> wfh.fmt_ck.cbSize = fc.cbSize ;<br> <br> wfh.fact_hdr.id[0] = 'f';<br> wfh.fact_hdr.id[1] = 'a';<br> wfh.fact_hdr.id[2] = 'c';<br> wfh.fact_hdr.id[3] = 't';<br> wfh.fact_hdr.len = 4;<br> wfh.fact_ck = 8;<br><br> wfh.data_hdr.id[0] = 'd';<br> wfh.data_hdr.id[1] = 'a';<br> wfh.data_hdr.id[2] = 't';<br> wfh.data_hdr.id[3] = 'a';<br> wfh.data_hdr.len = 0;<br><br> fwrite(&wfh,1,sizeof(wfh),pf);<br> fclose(pf);<br> pf = fopen(filepath,&quot;r+b&quot;);<br> }<br> fseek(pf,0,SEEK_SET);<br> fread(&wfh, 1, sizeof(wfh),pf);<br> wfh.riff_hdr.len += bytestowrite;<br> wfh.fact_ck += bytestowrite;<br> wfh.data_hdr.len += bytestowrite;<br> fseek(pf,0,SEEK_SET);<br> fwrite(&wfh, 1, sizeof(wfh),pf);<br> fseek(pf,0L,SEEK_END);<br> fwrite(buffer,1,bytestowrite,pf);<br> fclose(pf);<br>}
 
楼主,解决了吗,<br>恳请给我一份答案,谢谢dw-wtt@sohu.com
 
没解决啊,楼上帖的是C语言的
 
以前写的一段代码,你看看吧<br>
代码:
<br>unit PCMWaves;<br><br>interface<br><br>uses<br> &nbsp;Classes, SysUtils, MMSystem;<br><br>type<br> &nbsp;TPCMWaveHeader = packed record<br> &nbsp; &nbsp;rID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : array[0..3] of Char; &nbsp; //'RIFF' 标识<br> &nbsp; &nbsp;rLen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Longint;<br> &nbsp; &nbsp;wID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : array[0..3] of Char; &nbsp; //'WAVE' 标识<br> &nbsp; &nbsp;fID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : array[0..3] of Char; &nbsp; //'fmt ' 标识<br> &nbsp; &nbsp;fLen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Longint; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //固定值, 16<br> &nbsp; &nbsp;wFormatTag &nbsp; &nbsp; &nbsp;: Word; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//固定值, 1<br> &nbsp; &nbsp;nChannels &nbsp; &nbsp; &nbsp; : Word; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Mono=1, Stereo=2<br> &nbsp; &nbsp;nSamplesPerSec &nbsp;: Longint; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //采样频率, HZ<br> &nbsp; &nbsp;nAvgBytesPerSec : Longint;<br> &nbsp; &nbsp;nBlockAlign &nbsp; &nbsp; : Word;<br> &nbsp; &nbsp;nBitsPerSample &nbsp;: Word; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//精度, e.g. 8 or 16<br> &nbsp; &nbsp;dId &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : array[0..3]of Char; &nbsp; &nbsp;//'data' 标识<br> &nbsp; &nbsp;dLen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Longint; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //数据长度<br> &nbsp;end;<br><br>type<br> &nbsp;EInvalidPCMWaveFormat = class(Exception);<br> &nbsp;<br> &nbsp;TPCMWave &nbsp;= class(TObject)<br> &nbsp;private<br> &nbsp; &nbsp;FStream : TMemoryStream;<br> &nbsp; &nbsp;FHeader : TPCMWaveHeader;<br><br> &nbsp;protected<br> &nbsp; &nbsp;function isValidFormat(aStream: TStream): Boolean; virtual;<br> &nbsp; &nbsp;function getPCMWaveHeader(aStream: TStream): TPCMWaveHeader; virtual;<br> &nbsp; &nbsp;function getData: Pointer; virtual;<br> &nbsp; &nbsp;<br> &nbsp;public<br> &nbsp; &nbsp;constructor Create; virtual;<br> &nbsp; &nbsp;destructor Destroy; override;<br><br> &nbsp; &nbsp;procedure LoadFromFile(const aFileName: String); virtual;<br> &nbsp; &nbsp;procedure LoadFromStream(aStream: TStream); virtual;<br> &nbsp; &nbsp;procedure SaveToFile(const aFileName: String); virtual;<br> &nbsp; &nbsp;procedure SaveToStream(aStream: TStream); virtual;<br><br> &nbsp; &nbsp;procedure Append(const aFileName: String); overload; virtual;<br> &nbsp; &nbsp;procedure Append(aStream: TStream); overload; virtual;<br><br> &nbsp; &nbsp;procedure Clear;<br><br> &nbsp; &nbsp;procedure Play;<br> &nbsp; &nbsp;procedure Stop;<br> &nbsp; &nbsp;<br> &nbsp; &nbsp;property Header: TPCMWaveHeader read FHeader;<br> &nbsp; &nbsp;property Data: Pointer read getData;<br> &nbsp;end;<br><br>implementation<br>uses<br> &nbsp;LogFiles;<br> &nbsp;<br>constructor TPCMWave.Create;<br>begin<br> &nbsp;FillChar(FHeader, SizeOf(FHeader), 0);<br> &nbsp;with FHeader do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp;rID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := 'RIFF'; &nbsp;//'RIFF' 标识<br> &nbsp; &nbsp;rLen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= 36; &nbsp; &nbsp; &nbsp;//dLen + 36<br> &nbsp; &nbsp;wID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := 'WAVE'; &nbsp;//'WAVE' 标识<br> &nbsp; &nbsp;fID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := 'fmt '; &nbsp;//'fmt ' 标识<br> &nbsp; &nbsp;fLen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= 16; &nbsp; &nbsp; &nbsp;//固定值, 16<br> &nbsp; &nbsp;wFormatTag &nbsp; &nbsp; &nbsp;:= 1; &nbsp; &nbsp; &nbsp; //固定值, 1<br> &nbsp; &nbsp;nChannels &nbsp; &nbsp; &nbsp; := 1; &nbsp; &nbsp; &nbsp; //Mono=1, Stereo=2<br> &nbsp; &nbsp;nSamplesPerSec &nbsp;:= 16000; &nbsp; //采样频率, HZ<br> &nbsp; &nbsp;nAvgBytesPerSec := 32000; &nbsp;//nSamplesPerSec*nChannels*Trunc(nBitsPerSample div 8);<br> &nbsp; &nbsp;nBlockAlign &nbsp; &nbsp; := 2; &nbsp; &nbsp; &nbsp; //nChannels*(nBitsPerSample div 8);<br> &nbsp; &nbsp;nBitsPerSample &nbsp;:= 16; &nbsp; &nbsp; &nbsp;//精度, e.g. 8 or 16<br> &nbsp; &nbsp;dId &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := 'data'; &nbsp;//'data' 标识<br> &nbsp; &nbsp;dLen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= 0;<br> &nbsp; &nbsp;end;<br><br> &nbsp;FStream := TMemoryStream.Create;<br> &nbsp;Assert(FStream &lt;&gt; nil);<br> &nbsp;<br> &nbsp;FStream.Write(FHeader, SizeOf(FHeader));<br>end;<br><br>destructor TPCMWave.Destroy;<br>begin<br> &nbsp;if Assigned(FStream) then FStream.Free;<br> &nbsp;inherited Destroy;<br>end;<br><br>function TPCMWave.isValidFormat(aStream: TStream): Boolean;<br>var<br> &nbsp;Header : TPCMWaveHeader;<br>begin<br> &nbsp;Header := getPCMWaveHeader(aStream);<br> &nbsp;with Header do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp;Result := (rID = 'RIFF') and (wID = 'WAVE') and (wFormatTag = 1);<br> &nbsp; &nbsp;end;<br>end;<br><br>procedure TPCMWave.SaveToFile(const aFileName: String);<br>var<br> &nbsp;Stream: TStream;<br>begin<br> &nbsp;Stream := TFileStream.Create(aFileName, fmCreate);<br> &nbsp;Assert(Stream &lt;&gt; nil);<br> &nbsp;try<br> &nbsp; &nbsp;SaveToStream(Stream);<br> &nbsp;finally<br> &nbsp; &nbsp;Stream.Free;<br> &nbsp;end;<br>end;<br><br>procedure TPCMWave.LoadFromFile(const aFileName: String);<br>var<br> &nbsp;Stream: TStream;<br>begin<br> &nbsp;Stream := TFileStream.Create(aFileName, fmOpenRead or fmShareDenyWrite);<br> &nbsp;Assert(Stream &lt;&gt; nil);<br> &nbsp;try<br> &nbsp; &nbsp;LoadFromStream(Stream);<br> &nbsp;finally<br> &nbsp; &nbsp;Stream.Free;<br> &nbsp;end;<br>end;<br><br>procedure TPCMWave.SaveToStream(aStream: TStream);<br>begin<br> &nbsp;aStream.Seek(0, soFromBeginning);<br> &nbsp;FStream.Seek(0, soFromBeginning);<br> &nbsp;aStream.CopyFrom(FStream, FStream.Size);<br>end;<br><br>procedure TPCMWave.LoadFromStream(aStream: TStream);<br>begin<br> &nbsp;if not isValidFormat(aStream) then<br> &nbsp; &nbsp;raise EInvalidPCMWaveFormat.Create('Invalid PCM Wave Format');<br><br> &nbsp;aStream.Seek(0, soFromBeginning);<br> &nbsp;FStream.Seek(0, soFromBeginning);<br> &nbsp;FStream.CopyFrom(aStream, aStream.Size);<br> &nbsp;FHeader := getPCMWaveHeader(FStream);<br>end;<br><br>function TPCMWave.getPCMWaveHeader(aStream: TStream): TPCMWaveHeader;<br>var<br> &nbsp;Header : TPCMWaveHeader;<br>begin<br> &nbsp;aStream.Seek(0, soFromBeginning);<br> &nbsp;aStream.Read(Header, SizeOf(Header));<br> &nbsp;Result := Header;<br>end;<br><br>function TPCMWave.getData: Pointer;<br>begin<br> &nbsp;Result := FStream.Memory;<br>end;<br><br>procedure TPCMWave.Append(const aFileName: String);<br>var<br> &nbsp;Stream: TStream;<br>begin<br> &nbsp;Stream := TFileStream.Create(aFileName, fmOpenRead or fmShareDenyWrite);<br> &nbsp;Assert(Stream &lt;&gt; nil);<br> &nbsp;try<br> &nbsp; &nbsp;Append(Stream);<br> &nbsp;finally<br> &nbsp; &nbsp;Stream.Free;<br> &nbsp;end;<br>end;<br><br>procedure TPCMWave.Append(aStream: TStream);<br>var<br> &nbsp;Header : TPCMWaveHeader;<br> &nbsp;isSame : Boolean;<br>begin<br> &nbsp;if not isValidFormat(aStream) then<br> &nbsp; &nbsp;raise EInvalidPCMWaveFormat.Create('Invalid PCM Wave Format');<br><br> &nbsp;//数据区非空, 追加<br> &nbsp;if FHeader.dLen &gt; 0 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp;//检测是否是相同的数据格式<br> &nbsp; &nbsp;Header := getPCMWaveHeader(aStream);<br> &nbsp; &nbsp;isSame := (Header.nChannels = FHeader.nChannels) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and (Header.nSamplesPerSec = FHeader.nSamplesPerSec) &nbsp; //<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and (Header.nBitsPerSample = FHeader.nBitsPerSample); &nbsp;//<br><br> &nbsp; &nbsp;//数据格式相同<br> &nbsp; &nbsp;if isSame then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;//处理非标准格式, 按规范定义, rLen不包含RIFF标志和长度共8字节<br> &nbsp; &nbsp; &nbsp;//因此,aStream.Size = SizeOf(TPCMWaveHeader)+Header.dLen<br> &nbsp; &nbsp; &nbsp;// &nbsp; &nbsp; &nbsp;aStream.Size = Header.rLen + 8<br> &nbsp; &nbsp; &nbsp;//但在实际中发现存在rLen值为包含RIFF标志和长度8字节的文件<br> &nbsp; &nbsp; &nbsp;if Header.dLen &gt; aStream.Size-SizeOf(TPCMWaveHeader) then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;Header.dLen := aStream.Size - SizeOf(TPCMWaveHeader);<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp;//计算数据区长度<br> &nbsp; &nbsp; &nbsp;with FHeader do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;rLen := rLen + Header.dLen;<br> &nbsp; &nbsp; &nbsp; &nbsp;dLen := dLen + Header.dLen;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp;//更新文件头<br> &nbsp; &nbsp; &nbsp;FStream.Seek(0, soFromBeginning);<br> &nbsp; &nbsp; &nbsp;FStream.Write(FHeader, SizeOf(FHeader));<br><br> &nbsp; &nbsp; &nbsp;//追加数据<br> &nbsp; &nbsp; &nbsp;FStream.Seek(0, soFromEnd);<br> &nbsp; &nbsp; &nbsp;aStream.Seek(SizeOf(TPCMWaveHeader), soFromBeginning); &nbsp; //跳过文件头<br> &nbsp; &nbsp; &nbsp;FStream.CopyFrom(aStream, Header.dLen);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end<br> &nbsp;else //数据区为空, 读入新的数据<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp;LoadFromStream(aStream);<br> &nbsp; &nbsp;end;<br>end;<br><br>procedure TPCMWave.Clear;<br>begin<br> &nbsp;FillChar(FHeader, SizeOf(FHeader), 0);<br> &nbsp;with FHeader do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp;rID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := 'RIFF'; &nbsp;//'RIFF' 标识<br> &nbsp; &nbsp;rLen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= 36; &nbsp; &nbsp; &nbsp;//dLen + 36<br> &nbsp; &nbsp;wID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := 'WAVE'; &nbsp;//'WAVE' 标识<br> &nbsp; &nbsp;fID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := 'fmt '; &nbsp;//'fmt ' 标识<br> &nbsp; &nbsp;fLen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= 16; &nbsp; &nbsp; &nbsp;//固定值, 16<br> &nbsp; &nbsp;wFormatTag &nbsp; &nbsp; &nbsp;:= 1; &nbsp; &nbsp; &nbsp; //固定值, 1<br> &nbsp; &nbsp;nChannels &nbsp; &nbsp; &nbsp; := 1; &nbsp; &nbsp; &nbsp; //Mono=1, Stereo=2<br> &nbsp; &nbsp;nSamplesPerSec &nbsp;:= 16000; &nbsp; //采样频率, HZ<br> &nbsp; &nbsp;nAvgBytesPerSec := 32000; &nbsp;//nSamplesPerSec*nChannels*Trunc(nBitsPerSample div 8);<br> &nbsp; &nbsp;nBlockAlign &nbsp; &nbsp; := 2; &nbsp; &nbsp; &nbsp; //nChannels*(nBitsPerSample div 8);<br> &nbsp; &nbsp;nBitsPerSample &nbsp;:= 16; &nbsp; &nbsp; &nbsp;//精度, e.g. 8 or 16<br> &nbsp; &nbsp;dId &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := 'data'; &nbsp;//'data' 标识<br> &nbsp; &nbsp;dLen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= 0;<br> &nbsp; &nbsp;end;<br><br> &nbsp;FStream.Clear;<br> &nbsp;FStream.Write(FHeader, SizeOf(FHeader));<br>end;<br><br>procedure TPCMWave.Play;<br>begin<br> &nbsp;//声卡已安装<br> &nbsp;if waveOutGetNumDevs &gt; 0 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp;PlaySound(Data, hInstance, SND_MEMORY or SND_ASYNC);<br> &nbsp; &nbsp;end;<br>end;<br><br>procedure TPCMWave.Stop;<br>begin<br> &nbsp;//声卡已安装<br> &nbsp;if waveOutGetNumDevs &gt; 0 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp;PlaySound(nil, hInstance, 0);<br> &nbsp; &nbsp;end;<br>end;<br><br>end.<br>
 
呵呵,问题解决。感谢tseung关键时刻提供的无私支持。现将我刚刚调试通过的源码公布如下:<br>procedure TForm1.Button1Click(Sender: TObject);<br>var FStream : TMemoryStream;<br> &nbsp; &nbsp;aStream : TMemoryStream;<br> &nbsp; &nbsp;Header : TPCMWaveHeader;<br> &nbsp; &nbsp;isSame : Boolean;<br> &nbsp; &nbsp;FHeader : TPCMWaveHeader;<br>begin<br> &nbsp;FillChar(FHeader, SizeOf(FHeader), 0);<br> &nbsp;with FHeader do<br> &nbsp;begin<br> &nbsp; &nbsp;rID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := 'RIFF'; &nbsp;//'RIFF' 标识<br> &nbsp; &nbsp;rLen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= 36; &nbsp; &nbsp; &nbsp;//dLen + 36<br> &nbsp; &nbsp;wID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := 'WAVE'; &nbsp;//'WAVE' 标识<br> &nbsp; &nbsp;fID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := 'fmt '; &nbsp;//'fmt ' 标识<br> &nbsp; &nbsp;fLen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= 16; &nbsp; &nbsp; &nbsp;//固定值, 16<br> &nbsp; &nbsp;wFormatTag &nbsp; &nbsp; &nbsp;:= 1; &nbsp; &nbsp; &nbsp; //固定值, 1<br> &nbsp; &nbsp;nChannels &nbsp; &nbsp; &nbsp; := 1; &nbsp; &nbsp; &nbsp; //Mono=1, Stereo=2<br> &nbsp; &nbsp;nSamplesPerSec &nbsp;:= 22050; &nbsp; //采样频率, HZ<br> &nbsp; &nbsp;nAvgBytesPerSec := 44100; &nbsp;//nSamplesPerSec*nChannels*Trunc(nBitsPerSample div 8);<br> &nbsp; &nbsp;nBlockAlign &nbsp; &nbsp; := 2; &nbsp; &nbsp; &nbsp; //nChannels*(nBitsPerSample div 8);<br> &nbsp; &nbsp;nBitsPerSample &nbsp;:= 16; &nbsp; &nbsp; &nbsp;//精度, e.g. 8 or 16<br> &nbsp; &nbsp;dId &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := 'data'; &nbsp;//'data' 标识<br> &nbsp; &nbsp;dLen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= 0;<br> &nbsp;end;<br><br> &nbsp;FStream := TMemoryStream.Create;<br> &nbsp;Assert(FStream &lt;&gt; nil);<br><br> &nbsp;FStream.Write(FHeader, SizeOf(FHeader));<br><br> &nbsp;aStream := TMemoryStream.Create;<br> &nbsp;aStream.LoadFromFile('f:/0.wav');<br><br> &nbsp;//处理非标准格式, 按规范定义, rLen不包含RIFF标志和长度共8字节<br> &nbsp;//因此,aStream.Size = SizeOf(TPCMWaveHeader)+Header.dLen<br> &nbsp;// &nbsp; &nbsp; &nbsp;aStream.Size = Header.rLen + 8<br> &nbsp;//但在实际中发现存在rLen值为包含RIFF标志和长度8字节的文件<br> &nbsp;if Header.dLen &gt; aStream.Size-SizeOf(TPCMWaveHeader) then<br> &nbsp;begin<br> &nbsp;Header.dLen := aStream.Size - SizeOf(TPCMWaveHeader);<br> &nbsp;end;<br> &nbsp; &nbsp; &nbsp;//计算数据区长度<br> &nbsp; &nbsp; &nbsp;with FHeader do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;rLen := rLen + Header.dLen;<br> &nbsp; &nbsp; &nbsp; &nbsp;dLen := dLen + Header.dLen;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp;//更新文件头<br> &nbsp; &nbsp; &nbsp;FStream.Seek(0, soFromBeginning);<br> &nbsp; &nbsp; &nbsp;FStream.Write(FHeader, SizeOf(FHeader));<br><br> &nbsp; &nbsp; &nbsp;//追加数据<br> &nbsp; &nbsp; &nbsp;FStream.Seek(0, soFromEnd);<br> &nbsp; &nbsp; &nbsp;aStream.Seek(SizeOf(TPCMWaveHeader), soFromBeginning); &nbsp; //跳过文件头<br> &nbsp; &nbsp; &nbsp;FStream.CopyFrom(aStream, Header.dLen);<br><br> &nbsp;aStream := TMemoryStream.Create;<br> &nbsp;aStream.LoadFromFile('f:/1.wav');<br><br> &nbsp;//处理非标准格式, 按规范定义, rLen不包含RIFF标志和长度共8字节<br> &nbsp;//因此,aStream.Size = SizeOf(TPCMWaveHeader)+Header.dLen<br> &nbsp;// &nbsp; &nbsp; &nbsp;aStream.Size = Header.rLen + 8<br> &nbsp;//但在实际中发现存在rLen值为包含RIFF标志和长度8字节的文件<br> &nbsp;if Header.dLen &gt; aStream.Size-SizeOf(TPCMWaveHeader) then<br> &nbsp;begin<br> &nbsp;Header.dLen := aStream.Size - SizeOf(TPCMWaveHeader);<br> &nbsp;end;<br> &nbsp; &nbsp; &nbsp;//计算数据区长度<br> &nbsp; &nbsp; &nbsp;with FHeader do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;rLen := rLen + Header.dLen;<br> &nbsp; &nbsp; &nbsp; &nbsp;dLen := dLen + Header.dLen;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp;//更新文件头<br> &nbsp; &nbsp; &nbsp;FStream.Seek(0, soFromBeginning);<br> &nbsp; &nbsp; &nbsp;FStream.Write(FHeader, SizeOf(FHeader));<br><br> &nbsp; &nbsp; &nbsp;//追加数据<br> &nbsp; &nbsp; &nbsp;FStream.Seek(0, soFromEnd);<br> &nbsp; &nbsp; &nbsp;aStream.Seek(SizeOf(TPCMWaveHeader), soFromBeginning); &nbsp; //跳过文件头<br> &nbsp; &nbsp; &nbsp;FStream.CopyFrom(aStream, Header.dLen);<br><br> &nbsp; &nbsp; &nbsp;FStream.SaveToFile('f:/ddd.wav');<br><br>end;
 
接受答案了.
 
糟糕,加错分了。应该加给tseug。有办法更改吗?
 
后退
顶部