Skip to main content
gamedev.net
🔒 Locked

Sound problem

Started by pasman 7 replies 850+ views
Original Post
pasman
pasman
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
Eric Grange
Eric Grange
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
---Eric Grangehttp://glscene.org
risingdragon3
risingdragon3
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 playing
if so,
make a new copy.
play copy
return
end if
play original
return

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
turbo
turbo
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 ]
[ Michael Wilson | turbo sys-op | turbo.gamedev.net ]
ggs
ggs
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)
Protected
Function 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;
begin
Result := false;
if not FInitialized then Exit;
assert(GetBuffer <> nil);
assert(FBufferList <> nil);
if FLooped then
begin
Buffer := GetBuffer;
assert(Buffer <> nil);
result := Buffer.Playing;
end
else
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.