Type
PMemoryStream = ^TMemoryStream;
sf_count_t = Int64;
//pm_get_filelen = ^tm_get_filelen;
tm_get_filelen =
function (pms: PMemoryStream): sf_count_t;
//pm_seek = ^tm_seek;
tm_seek =
function (offset: sf_count_t; whence: Integer; pms: PMemoryStream): sf_count_t;
//pm_read = ^tm_read;
tm_read =
function (buf: Pointer; count: sf_count_t; pms: PMemoryStream): sf_count_t;
//pm_write = ^tm_write;
tm_write =
function (const buf: Pointer; count: sf_count_t; pms: PMemoryStream): sf_count_t;
//pm_tell = ^tm_tell;
tm_tell =
function (pms: PMemoryStream): sf_count_t;
TSF_VIRTUAL = packed record
sf_vio_get_filelen : tm_get_filelen;
sf_vio_seek : tm_seek;
sf_vio_read : tm_read;
sf_vio_write : tm_write;
sf_vio_tell : tm_tell;
end;
function m_get_filelen(pms: PMemoryStream): sf_count_t;
begin
Result:= pms^.Size;
end;
function m_seek(offset: sf_count_t; whence: Integer; pms: PMemoryStream): sf_count_t;
Const
SEEK_SET = 0;
SEEK_CUR = 1;
SEEK_END = 2;
begin
case whence of
SEEK_SET: Result:= pms^.Seek(offset, soFromBeginning);
SEEK_CUR: Result:= pms^.Seek(offset, soFromCurrent);
SEEK_END: Result:= pms^.Seek(offset, soFromEnd);
end;
end;
function m_read(buf: Pointer; count: sf_count_t; pms: PMemoryStream): sf_count_t;
begin
Result:= pms^.Read(buf^,count);
end;
function m_write(const buf: Pointer; count: sf_count_t; pms: PMemoryStream): sf_count_t;
begin
Result:= pms^.Write(buf^,count);
end;
function m_tell(pms: PMemoryStream): sf_count_t;
begin
Result:= pms^.Position;
end;
procedure TSSoundUOS.TestLibSndFile;
Var
sfInfo: TSF_INFO;
sfVirtual: TSF_VIRTUAL;
procedure ShowInfo;
Var
sl: TStringList;
begin
sl:= TStringList.Create;
try
with sfInfo do
begin
sl.Add('frames: '+IntToStr(frames));
sl.Add('samplerate: '+IntToStr(samplerate));
sl.Add('channels: '+IntToStr(channels));
sl.Add('format: '+IntToStr(format));
sl.Add('sections: '+IntToStr(sections));
sl.Add('seekable: '+IntToStr(seekable));
end;
ShowMessage(sl.Text);
finally
sl.Free;
end;
end;
Const
path_test = 'c:\test.flac'; //for simulate
Var
ms: TMemoryStream;
begin
FillChar(sfInfo, SizeOf(sfinfo), 0);
sf_open(path_test, SFM_READ, sfInfo);
ShowInfo;
with sfVirtual do
begin
sf_vio_get_filelen := m_get_filelen;
sf_vio_seek := m_seek;
sf_vio_read := m_read;
sf_vio_write := m_write;
sf_vio_tell := m_tell;
end;
FillChar(sfInfo, SizeOf(sfinfo), 0);
ms:= TMemoryStream.Create;
try
ms.LoadFromFile(path_test);
ms.Position:= 0;
sf_open_virtual(@sfVirtual, SFM_READ, @sfInfo, @ms);
ShowInfo;
finally
ms.Free;
end;
end;