我想把文件流中的多个WAV文件合成到内存流中用playsound读出来,再次倾家荡产!!!(100分)

  • 主题发起人 主题发起人 czly
  • 开始时间 开始时间
C

czly

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TMainfrm.LinkWave(waveFiles: string);
var
Files: TStringList;
n1, n2, n3, n, WaveLen: Integer;

SoureFile: TFileStream;
a1, a2, a3: byte;
begin

Files := TStringList.Create;
Files.CommaText := WaveFiles;

WaveFile := TMemoryStream.Create;
try
SoureFile := TFileStream.Create(Files.Strings[0], fmOpenRead);
//打开其中一个声音文件
WaveFile.CopyFrom(SoureFile, 59);
//读取声音文件头
WaveLen := 0;
//记录声音长度
WaveFile.Size := 0;
for n := 0 to Files.Count - 1do
begin

if Assigned(SoureFile) then
begin

SoureFile.Free;
SoureFile := nil;
end;


try
SoureFile := TFileStream.Create(Files.Strings[n], fmOpenRead);
SoureFile.Position := 54;
SoureFile.read(a1, 1);
SoureFile.read(a2, 1);
SoureFile.read(a3, 1);
WaveLen := WaveLen + (ord(a3) * 65536) + (ord(a2) * 256) + ord(a1);
SoureFile.Position := 59;
WaveFile.CopyFrom(SoureFile, SoureFile.Size - 60);
except
// on E: Exceptiondo

// WriteLog(e.Message);
end;

end;

WaveFile.Position := 4;
n1 := (WaveFile.Size - 8) div 65536;
n2 := (WaveFile.Size - 8 - n1 * 65536) div 256;
n3 := WaveFile.Size - 8 - n1 - n2 * 256;
WaveFile.WriteBuffer(n3, 1);
WaveFile.WriteBuffer(n2, 1);
WaveFile.WriteBuffer(n1, 1);

n1 := WaveLen div 65536;
n2 := (WaveLen - n1 * 65536) div 256;
n3 := WaveLen - n1 - n2 * 256;
WaveFile.Position := 54;
WaveFile.WriteBuffer(n3, 1);
WaveFile.WriteBuffer(n2, 1);
WaveFile.WriteBuffer(n1, 1);
WaveFile.Position := 46;
WaveFile.WriteBuffer(n3, 1);
WaveFile.WriteBuffer(n2, 1);
WaveFile.WriteBuffer(n1, 1);
//PlaySound(WaveFile.Memory, 0, SND_ASYNC + SND_MEMORY);
except
//on E: Exceptiondo

// WriteLog(e.Message);
end;



freeAndNil(Files);
// freeAndNil(WaveFile);
if Assigned(SoureFile) then

freeAndNil(SoureFile);
end;
 
这样读不行啊
 
try
LinkWave(SoundFiles);
// PlaySound(Pchar(ExtractFilePath(ParamStr(0)) + 'FeeSound.wav'), 0, SND_ASYNC + SND_FILENAME);
Win32Check(
PlaySound(WaveFile.Memory, 0, SND_SYNC or SND_MEMORY))

except
// on e: exceptiondo
begin

// WriteLog(e.Message);
end;

end;
 
WaveFile.SaveToFile('c:/a.wav');

输出成文件WINDOWS不认识,不能播
 
用“流”输出、保存成临时文件,然后Play就可以了...
 
自己解决了,太笨了
 
每个WAV文件的前面是文件头后面是数据。把数据合成后在加上头
 
后退
顶部