• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Sound problem

## Recommended Posts

pasman    441
Hi, i''m still writing my RTS game and i''ve got to the part of sound management... So i want my units to speak, like in StarCraft, but when i select a unit, if i double-click it for example the sounds overlap. So how can i wait till the previous sound is done. Is there a way to check if a sound is playing. Thanks

##### Share on other sites
Eric Grange    122
Depends on how and with what you play your sounds.
- BASS and FMOD both have functions (BASS_ChannelIsActive and FSOUND_IsPlaying respectively, IIRC).
- With the TMediaPlayer you have an event (OnNotify).
- And in DirectX you basicly end up feeding and converting the samples yourself, so it''s obvious.

---
Eric Grange
http://glscene.org

##### Share on other sites
pasman    441
Actualy i''m using DelphiXs TDXWaveList for storing my sounds. Any suggestions?
Thanks.

##### Share on other sites
Argh....
You''ll probably have to dig into the source for it, and find the play() function (or whatever it''s called). it''ll do something like this:
  check if it''s playingif so,make a new copy.play copyreturnend ifplay originalreturn

Just change it to add a somekind of bool or value so that for unit sounds, it will skip the copy making and playing

------------------------------
BCB DX Library - RAD C++ Game development for BCB

##### Share on other sites
pasman    441
Yeah, but how do i check if it''s playing.

##### Share on other sites
turbo    115
Here are some options...

You can tell if your DXSound is playing a sound with this function...

if DXSound1.Primary.Playing then doSomething // true

... you can also set how many times a sound can be played on top of itself with this property. Set it to 1 so the sound only can be played once...

DXWaveList1.Items[0].MaxPlayingCount := 1;

... or you could "Stop" the sound *before* playing it -- therefore limiting it to one play at a time...

DXWaveList1.Items[0].Stop;
DXWaveList1.Items[0].Play(false);

Setting the MaxPlayingCount is probably what you want.

[ Michael Wilson | turbo sys-op | turbo.gamedev.net ]

##### Share on other sites
pasman    441
Yeah thanks, but what i really want to find out is how do i check if a specific sound is playing (ex. the 4th sound in the wave list) because what i want in code is something like this:

if (unit_selected) and (not already_playing) then playsound(x);

Thanks

##### Share on other sites
ggs    166
While DelphiX is a good lib, it does have some problems.
One of these problems is its very hard to extent it with out patching the actual source files :/

Steps :
1 - Copy n paste the unit DXSounds to your project dir
2 - Open it up in delphi and find the
3 - add the definitions listed
TWaveCollectionItem = class(TWaveCollectionItem)ProtectedFunction GetPlaying : boolean;Public...Property Playing : boolean read GetPlaying;end;

4 - Copy N past the function GetPlaying into the unit
Function TWaveCollectionItem.GetPlaying : boolean;var  Buffer : TDirectSoundBuffer;  index : integer;beginResult := false;if not FInitialized then Exit;assert(GetBuffer <> nil);assert(FBufferList <> nil);if FLooped then  begin  Buffer := GetBuffer;  assert(Buffer <> nil);  result := Buffer.Playing;  endelse  begin  for index := 0 to FBufferList.Count - 1  do    if TDirectSoundBuffer(FBufferList[index]).Playing then      begin      result := true;      Break;      end;  end;end; {GetPlaying}

Thats it. Now to check if a TWaveCollectionItem is playing use the "Playing" property

Michael you might want to add this to the list of additions to UnDelphiX