This question already has an answer here:
I want to join several WAV files in Delphi Xe6. I use this code, but it isn't always working, and doesn't recognize the data chunk if it's position is not 44 bytes. If the file contains metadata at the first part of the file, the result will corrupted. If there is a metadata at the end of the WAV, you hear a cracking after the content.
Do you have any idea? Using DirectX, using a more sophisticated procedure?
Thank you.
The code is:
unit concatwav;
interface
uses
Classes,sysutils;
type
TConcatWave = class(TThread)
private
{ Private declarations }
FileList: TStrings;
FileStream:TFileStream;
protected
procedure Execute; override;
public
constructor createwithlist(wavname:string; suspended:boolean;aFileList: TStrings);
destructor destroy;override;
procedure JoinWavesToFile;
end;
implementation
constructor TConcatWave.createwithlist(wavname:string; suspended:boolean;aFileList: TStrings);
begin
inherited create(true);
freeonterminate:=true;
FileList:=TStringList.Create;
FileList.Text:= aFileList.Text;
FileStream:=TFileStream.Create(wavname,fmCreate);
if not suspended then resume;
end;
destructor TConcatWave.destroy;
begin
FileList.Free;
FileStream.Free;
inherited destroy;
end;
procedure TConcatWave.JoinWavesToFile;
var
I: Integer;
FileSize: LongInt;
InStream: TFileStream;
begin
for I := 0 to FileList.Count -1 do
if FileExists(FileList[I]) then
begin
InStream := TFileStream.Create(FileList[I], fmOpenRead);
try
if I = 0 then
FileStream.CopyFrom(InStream, InStream.Size)
else if InStream.Size>44 then
begin
InStream.Position := 44;
FileStream.CopyFrom(InStream, InStream.Size - 44);
end;
finally
InStream.Free;
end;
end;
FileStream.Position := 4;
FileSize := FileStream.Size - 8;
FileStream.WriteBuffer(FileSize, SizeOf(FileSize));
FileStream.Position := 40;
FileSize := FileStream.Size - 44;
FileStream.WriteBuffer(FileSize, SizeOf(FileSize));
end;
procedure TConcatWave.Execute;
begin
JoinWavesToFile;
end;
end.
Aucun commentaire:
Enregistrer un commentaire