Using IStream in Delphi

Started by Marras,

Marras

First of all, I'm new to BASS.

I want to use the BASS WMA addon to
     1 read raw WMA-data from a delphi stream and to
     2 output the PCM data to another delphi stream

The second one is no problem since I get to manipulate the data myself, but the first one makes me puzzled.

I can create a stream from a file by just passing a filename to BASS_WMA_StreamCreateFile, or I can pass a memorylocation to play from, but how do I do to play from a stream?

The data I have doesn't exist in memory or on disk until I read from the stream, and I want to avoid having to read the entire WMA file to memory before beginning to play it.

Can someone tell me what an "IStream object" is (the helpfile does not seem to bother to explain it, and I can't find anything in the forum).

Thanks for any help!
// Marcus

Marras

Maybe I should clarify a little.

I have found the words "IStream object" in the helpfile for BASSWMA 1.8 on the topic "BASS_WMA_StreamCreateFile" and thought that "that is what I need".

The helpfile says this:

HSTREAM WINAPI BASS_WMA_StreamCreateFile(
    BOOL mem,
    void *file,
    DWORD offset,
    DWORD length,
    DWORD flags
);


Parameters

mem     TRUE = stream the file from memory,
        2 = stream from an IStream object.
file    Filename or URL (mem = FALSE) or a memory location
        (mem = TRUE), or a pointer to an IStream object
        (mem = 2).

And that's it about the IStream object.

Maybe the IStream object isn't what I need, but it seemes to me like the only solution.

// Marcus

Ian @ un4seen

Here's the IStream docs...
      http://msdn.microsoft.com/library/en-us/stg/stg/istream.asp

I can't help with using it in Delphi, but there's probably a way (look up TStreamAdapter).

Dana

For clarity, the IStream object defined in the Delphi Visual Component Library (VCL) is a dynamic object that doesn't have any methods, procedures, functions, etc... until these methods are defined in your code. The IStream Object will publish these methods correctly for external COM objects expecting an IStream interface.

Along with the previous reply, you could use most any TStream derived object within your own code implementation, including THandleStream. THandleStream provides access to the file handle variable that Windows API require for many core file read/write API calls. I've derived many custom TStream objects from Delphi's THandleStream that will include its own variable to hold a Delphi untyped "File" variable that empowers my custom THandleStream to include Delphi's file functions(ie: F.Truncate) as well as Windows API.

type
  TMyStream = class(THandleStream)
    F: File;
    end;
var
  F: File;
  Stream: TMyStream ;
begin
  AssignFile(F, 'any.file');
  Stream := TMyStream.Create(TFileRec(F).Handle);
  Stream.F := F;
  end;

Alternatively, someone created a niffty Delphi TMappedFileStream VCL object that is freely available. It wraps the Windows Mapped File API.  You can do a search on the Net.