DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Perfect looping possible?

 
   Reply to topic    DELPHI AREA Forum Index -> DELPHI AREA's Products
View previous topic :: View next topic  
Author Message
Cluq
Member


Joined: 04 Nov 2004
Posts: 6

PostPosted: 14/11/04 13:00    Post subject: Perfect looping possible? Reply with quote

Hi

I'm using the AudioPlayer to play a looping wave file. The looping works, but not perfectly. There is a very small silence before the wave starts over again and I would like it to loop without that silence. I have checked the wave file - it loops perfectly in SoundForge.

This is the simple code I've been using:

-----------------
type
TForm1 = class(TForm)
CheckBox1: TCheckBox;
AudioPlayer1: TAudioPlayer;
procedure AudioPlayer1Deactivate(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.AudioPlayer1Deactivate(Sender: TObject);
begin
AudioPlayer1.Active := checkbox1.Checked;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
AudioPlayer1.Active := checkbox1.Checked;
end;
------------

Have any of you a better idea to get perfect looping?

Best regards,
Cluq.
Back to top
View user's profile
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 422
Location: Tehran, Iran

PostPosted: 14/11/04 16:27    Post subject: Reply with quote

Hi,

You can use LiveAudioPlayer. In the event hanlder for supplying the wave data, you can specify the number of loops.

Cheers,
Kambiz
Back to top
View user's profile Send e-mail Visit poster's website
Cluq
Member


Joined: 04 Nov 2004
Posts: 6

PostPosted: 15/11/04 08:32    Post subject: Reply with quote

Ok, thank you very much.

I've been looking at the LiveAudioPlayer Demo (the receiver part). I get the part that the variable WaveFormat is where the actual wave data is loaded into, right? But how would you go about loading wave data from a local wave-file on your harddrive?

/Cluq
Back to top
View user's profile
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 422
Location: Tehran, Iran

PostPosted: 15/11/04 09:12    Post subject: Reply with quote

Use a TWaveStorage instance.

Code:
procedure TForm1.LiveAudioPlayer1Format(Sender: TObject;
  out pWaveFormat: PWaveFormatEx; var FreeIt: Boolean);
begin
  FreeIt := False;
  pWaveFormat := WaveStorage1.Wave.WaveFormat;
end;

function TForm1.LiveAudioPlayer1DataPtr(Sender: TObject;
  out Buffer: Pointer; var NumLoops: Cardinal;
  var FreeIt: Boolean): Cardinal;
begin
  FreeIt := False;
  NumLoops := $FFFFFFFF; // infinite
  Buffer := WaveStorage1.Wave.Data;
  Result := WaveStorage1.Wave.DataSize;
end;


By the way, set LiveAudioPlayer.BufferCount to 1 and LiveAudioPlayer.BufferInternally to False.
Back to top
View user's profile Send e-mail Visit poster's website
Cluq
Member


Joined: 04 Nov 2004
Posts: 6

PostPosted: 15/11/04 12:14    Post subject: Reply with quote

Ahh...of course...I'll be trying that out...

Btw, if I get positive results from this, I will most likely use this in my freeware game I'm writing... It is almost done, except for the sound. I have been using another unit for playing sound, but it had memory leaks and other crappy things wrong with it, so I'm looking for a better unit.

But this is looking quite nice so far...

/Cluq
Back to top
View user's profile
Cluq
Member


Joined: 04 Nov 2004
Posts: 6

PostPosted: 16/11/04 09:24    Post subject: Reply with quote

I have now done exactly as you said, but the sound doesn't loop. It only play once... LiveAudioPlayer.Active remains true - there is just silence...

The audio file is PCM 44,100 kHz, 16bit, Stereo...
Back to top
View user's profile
Cluq
Member


Joined: 04 Nov 2004
Posts: 6

PostPosted: 17/11/04 11:38    Post subject: Reply with quote

Have I found a bug?
Back to top
View user's profile
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 422
Location: Tehran, Iran

PostPosted: 24/11/04 12:02    Post subject: Reply with quote

Yes, there's a bug. Open the WaveOut.pas file and look for

Code:
WHDR_BEGINLOOP or WHDR_BEGINLOOP


then replace it with

Code:
WHDR_BEGINLOOP or WHDR_ENDLOOP



By the way, you can leave the NumLoops as zero. Because when a buffer finished, the OnDataPtr event will be raised once more, until your return zero as result. If you set the NumLoops parameter, in the next call of the event you should return zero. So, my prevoius code is wrong.

Solution 1:
Code:
LiveAudioPlayer1.BufferInternally := False;

procedure TForm1.LiveAudioPlayer1Format(Sender: TObject;
  out pWaveFormat: PWaveFormatEx; var FreeIt: Boolean);
begin
  FreeIt := False;
  pWaveFormat := WaveStorage1.Wave.WaveFormat;
end;

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;


Solution 2:
Code:
var
  AlreadyFed: Boolean = False;

LiveAudioPlayer1.BufferInternally := False;

procedure TForm1.LiveAudioPlayer1Format(Sender: TObject;
  out pWaveFormat: PWaveFormatEx; var FreeIt: Boolean);
begin
  FreeIt := False;
  pWaveFormat := WaveStorage1.Wave.WaveFormat;
end;

function TForm1.LiveAudioPlayer1DataPtr(Sender: TObject;
  out Buffer: Pointer; var NumLoops: Cardinal;
  var FreeIt: Boolean): Cardinal;
begin
  if not AlreadyFed then
  begin
    FreeIt := False;
    NumLoops := $FFFFFFF; // Infinite
    Buffer := WaveStorage1.Wave.Data;
    Result := WaveStorage1.Wave.DataSize;
    AlreadyFed := True;
  end
  else
    Result := 0;
end;


I'm sorry for being so late.
Back to top
View user's profile Send e-mail Visit poster's website
Display posts from previous:   
   Reply to topic    DELPHI AREA Forum Index -> DELPHI AREA's Products All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB 2.0.6 © 2001, 2002 phpBB Group