Author Topic: BASS_StreamCreateFile() from memory  (Read 7442 times)

3delite

  • Posts: 925
BASS_StreamCreateFile() from memory
« on: 24 Nov '04 - 01:49 »
My idea is to copy (pre-buffer) some files to memory to avoid disk accesing, spinning up the hd, while listening to music. I'm using Delphi. Should I create a TMemoryStream from the files? How to tell BASS_StreamCreateFile() to use these MemoryStreams?
Some help would be appreciated!

(: JOBnik! :)

  • Posts: 1066
Re:BASS_StreamCreateFile() from memory
« Reply #1 on: 24 Nov '04 - 11:10 »
Hi ;D

My idea is to copy (pre-buffer) some files to memory to avoid disk accesing, spinning up the hd, while listening to music. I'm using Delphi. Should I create a TMemoryStream from the files? How to tell BASS_StreamCreateFile() to use these MemoryStreams?
Some help would be appreciated!

Here's a C/C++ example :)
http://www.un4seen.com/forum/?board=1;action=display;threadid=2070;start=msg13513#msg13513

Have fun!

8) JOBnik! 8)

3delite

  • Posts: 925
Re:BASS_StreamCreateFile() from memory
« Reply #2 on: 24 Nov '04 - 17:01 »
Great thanx! :)

This is what finally worked (translated to Delphi):
Code: [Select]
procedure TMainForm.MemPlay1Click(Sender: TObject);
var
  fs: TStream;
  chan: Cardinal;
  memp: Pointer;
begin
    fs := TFileStream.Create('E:\AUDIO\DJRap - Rumble(Special K Remix).mp3', fmOpenRead);
    GetMem(memp, fs.size);
    fs.Read(memp^, fs.Size);
    chan := BASS_StreamCreateFile(True, memp, 0, fs.Size, 0);
    BASS_StreamPlay(chan, False, 0);
    fs.Free;
end;
Thanx again! Cool! 8)

Additionally:
memp := VirtualAlloc(nil, fs.Size, MEM_COMMIT, PAGE_READWRITE OR PAGE_NOCACHE);
together with
VirtualFree(memp, 0, MEM_RELEASE);
for non-paged memory. :)
« Last Edit: 25 Nov '04 - 21:00 by 3delite »