生成一个波文件
点击次数:39 次 发布日期:2008-11-09 08:40:56 作者:源代码网
|
源代码网推荐 源代码网推荐 TPCMWaveHeader = record 源代码网推荐 源代码网推荐 rID : array[0..3] of char; { "RIFF" Identifier } 源代码网推荐 源代码网推荐 rLen : longint; 源代码网推荐 源代码网推荐 wID : array[0..3] of char; { "WAVE" Identifier } 源代码网推荐 源代码网推荐 fId : array[0..3] of char; { "fmt " Identifier } 源代码网推荐 源代码网推荐 fLen : longint; { Fixed, must be 16 } 源代码网推荐 源代码网推荐 wFormatTag : word; { Fixed, must be 1 } 源代码网推荐 源代码网推荐 nChannels : word; { Mono=1, Stereo=2 } 源代码网推荐 源代码网推荐 nSamplesPerSec : longint; { SampleRate in Hertz } 源代码网推荐 源代码网推荐 nAvgBytesPerSec : longint; 源代码网推荐 源代码网推荐 nBlockAlign : word; 源代码网推荐 源代码网推荐 nBitsPerSample : word; { Resolution, e.g. 8 or 16 } 源代码网推荐 源代码网推荐 dId : array[0..3]of char; { "data" Identifier } 源代码网推荐 源代码网推荐 dLen : longint; { Number of following data bytes } 源代码网推荐 源代码网推荐 end; 源代码网推荐 源代码网推荐 源代码网推荐 源代码网推荐 procedure WritePCMWaveFile(Filename : string; Resolution, Channels, Samplerate, Samples : integer; Data : Pointer); 源代码网推荐 源代码网推荐 var h : TPCMWaveHeader; 源代码网推荐 源代码网推荐 f : file; 源代码网推荐 源代码网推荐 databytes : integer; 源代码网推荐 源代码网推荐 begin 源代码网推荐 源代码网推荐 DataBytes:=Samples; 源代码网推荐 源代码网推荐 DataBytes:=DataBytes*Channels; { double if stereo } 源代码网推荐 源代码网推荐 DataBytes:=DataBytes*(Resolution div 8); { double if 16 Bit } 源代码网推荐 源代码网推荐 源代码网推荐 源代码网推荐 源代码网推荐 源代码网推荐 FillChar(h,SizeOf(TPCMWaveHeader),#0); 源代码网推荐 源代码网推荐 with h do 源代码网推荐 源代码网推荐 begin 源代码网推荐 源代码网推荐 rID[0]:="R"; 源代码网推荐 源代码网推荐 rID[1]:="I"; 源代码网推荐 源代码网推荐 rID[2]:="F"; 源代码网推荐 源代码网推荐 rID[3]:="F"; { 1st identifier } 源代码网推荐 源代码网推荐 rLen:=DataBytes 36; 源代码网推荐 源代码网推荐 wID[0]:="W"; 源代码网推荐 源代码网推荐 wID[1]:="A"; 源代码网推荐 源代码网推荐 wID[2]:="V"; 源代码网推荐 源代码网推荐 wID[3]:="E"; { 2nd identifier } 源代码网推荐 源代码网推荐 fId[0]:="f"; 源代码网推荐 源代码网推荐 fId[1]:="m"; 源代码网推荐 源代码网推荐 fId[2]:="t"; 源代码网推荐 源代码网推荐 fID[3]:=Chr($20); { 3rdidentifier ends with a space character } 源代码网推荐 源代码网推荐 fLen:=$10; { Fixed, must be 16 } 源代码网推荐 源代码网推荐 wFormatTag:=1; { Fixed, must be 1 } 源代码网推荐 源代码网推荐 nChannels:=Channels; { Channels } 源代码网推荐 源代码网推荐 nSamplesPerSec:=SampleRate; { Sample rate in Hertz } 源代码网推荐 源代码网推荐 nAvgBytesPerSec:=SampleRate*Channels*trunc(Resolution div 8); 源代码网推荐 源代码网推荐 nBlockAlign:=Channels*(Resolution div 8); { Byte order, see below } 源代码网推荐 源代码网推荐 nBitsPerSample:=Resolution; 源代码网推荐 源代码网推荐 dId[0]:="d"; 源代码网推荐 源代码网推荐 dId[1]:="a"; 源代码网推荐 源代码网推荐 dId[2]:="t"; 源代码网推荐 源代码网推荐 dId[3]:="a"; { Data identifier } 源代码网推荐 源代码网推荐 dLen:=DataBytes; { number of following data bytes } 源代码网推荐 源代码网推荐 end; 源代码网推荐 源代码网推荐 AssignFile(f,filename); 源代码网推荐 源代码网推荐 ReWrite(f,1); 源代码网推荐 源代码网推荐 BlockWrite(f,h,SizeOf(h)); 源代码网推荐 源代码网推荐 BlockWrite(f,pbytearray(data),databytes); 源代码网推荐 源代码网推荐 CloseFile(f); 源代码网推荐 源代码网推荐 { The rest of the file is the wave data. Order is low-high for left channel, 源代码网推荐 源代码网推荐 low-high for right channel, and so on. 源代码网推荐 源代码网推荐 For mono or 8 bit files make the respective changes. } 源代码网推荐 源代码网推荐 end; 源代码网推荐 源代码网供稿. |
