Jump to content
  • Advertisement


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


Sound problem

This topic is 6187 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites
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 playing
if so,
make a new copy.
play copy
end if
play original

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 this post

Link to post
Share on other sites
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...


Setting the MaxPlayingCount is probably what you want.

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

Share this post

Link to post
Share on other sites
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);


Share this post

Link to post
Share on other sites
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)
Function GetPlaying : boolean;
Property Playing : boolean read GetPlaying;

4 - Copy N past the function GetPlaying into the unit

Function TWaveCollectionItem.GetPlaying : boolean;
Buffer : TDirectSoundBuffer;
index : integer;
Result := false;
if not FInitialized then Exit;
assert(GetBuffer <> nil);
assert(FBufferList <> nil);
if FLooped then
Buffer := GetBuffer;
assert(Buffer <> nil);
result := Buffer.Playing;
for index := 0 to FBufferList.Count - 1 do
if TDirectSoundBuffer(FBufferList[index]).Playing then
result := true;
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

Share this post

Link to post
Share on other sites
Thanks ggs, that''s exactly what i wanted to find out and i''ve managed to solve my problem. Thanks alot.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!