Page 1 of 1

Using TLiveAudioPlayer and TWaveStorage to play a wav file

PostPosted: April 17th, 2008, 4:37 pm
by MervinG
Hi Kambiz,

In this thread, you suggested the following method of supplying the buffer data to the TLiveAudioPlayer component:

Code: Select all
function TForm1.LiveAudioPlayer1DataPtr(Sender: TObject;
  out Buffer: Pointer; var NumLoops: Cardinal;
  var FreeIt: Boolean): Cardinal;
begin
  FreeIt := False;
  Buffer := WaveStorage1.Wave.Data;
  Result := WaveStorage1.Wave.DataSize;
end;



Unfortunately, using v1.87 of your Wave Audio components, WaveStorage1.Wave.Data is invalid. What should I use instead of .Data, please?

Many thanks

Mervin

PostPosted: April 17th, 2008, 4:56 pm
by Kambiz
In the older versions, TWave was subclassed directly from TMemoryStream. However, in the current version, TWave is subclassed from TWaveStreamAdapter and uses a TMemoryStream to store wave data. So, you can use the following code.

Code: Select all
function TForm1.LiveAudioPlayer1DataPtr(Sender: TObject;
  out Buffer: Pointer; var NumLoops: Cardinal;
  var FreeIt: Boolean): Cardinal;
begin
  FreeIt := False;
  Buffer := TMemoryStream(WaveStorage1.Wave.Stream).Memory;
  Inc(PByte(Buffer), WaveStorage1.Wave.DataOffset);
  Result := WaveStorage1.Wave.DataSize;
end;

PostPosted: April 17th, 2008, 7:43 pm
by MervinG
Thanks very much Kambiz, that is just what I needed.

Out of interest, is there a limit on how many LiveAudioPlayers can be playing a wav sound at any one time? My application is needing to play several sounds, looped, through multiple speakers of multiple sound cards. I intend on having a LiveAudioPlayer component for each sound, directed to the speaker (L or R by the volume) and to the soundcard by DeviceID. I'm wondering if there is a limit per sound card or from Windows?

Mervin

PostPosted: April 18th, 2008, 2:28 am
by Kambiz
You'we welcome.

I have never tried to play more than two waves simultaneously. On Windows 9x only one wave could be played, but seems XP drivers can mix waves on the fly.

By the way, check out the update. I just uploaded it.