Play a sound repeteadly without stopping it

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Play a sound repeteadly without stopping it

Post by Fou-Lu »

Before someone get pissed at me: I know there's a topic about this same subject somewhere but I made lots of searches and didn't find it.

My problem is, I have a sound file which length is about one second. Sometimes I need to play it repeteadly and most of the times I play it while it's already being played. Then it stops and starts again. I could solve this by loading the same sound three or four times, but I think it would be kinda dumb...

I don't really care if the sound stops and starts playing again, but everytime this happens I hear a "plac". If that could be avoided I wouldn't mind if the sound doesn't finish before playing again. Any suggestions?

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

You could try editing the sound file with Goldwave or similar and take the plac out so it sounds good played in loop mode if that's feasible.
BERESHEIT
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

No, the plac is NOT in my file, it happens with any file when I try to play it too many times before it finishes. The sound is something like a machine gun, but it plays irregularly, just looping it won't do.

Now I'm wondering, does this "plac" occurs with anyone besides me?

Could you test with this code below?

Code: Select all

Global Stop.l

Procedure WaitingThread()
MessageRequester("Playing Sound...", "Do you hear a ''plac'' ?")
Stop=1
EndProcedure

If InitSound() = 0
MessageRequester("Error", "Couldn't initialize sound!")
EndIf

File$ = OpenFileRequester("Choose a wav file", "c:\", "Wav Files (*.wav)", 0)

LoadSound(0,File$)

CreateThread(@WaitingThread(), 0)

While Stop = 0

Delay(Random(200))
PlaySound(0)

WEnd

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

Fou-Lu wrote:Now I'm wondering, does this "plac" occurs with anyone besides me?
I'm not sure if I heard it. I did hear it if you mean that it sounds interrupted or incomplete. I noticed that a brief delay of a few milliseconds seem to remove almost all of it.

Code: Select all

Delay(Random(200)+7)
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

Hm, "almost" is not enough, but thanks a lot for testing it. :wink: I've never seen this happen before in any game, so I'm sure there must be a solution.

Another very weird issue is that any sound I load, no matter what it's initial frequency is, it always gets converted to 22050hz :? (the sound doesn't get slower or faster, it really is converted). My sound card plays sound files in 44100hz, this only happens with PB.

Anybody, help! :(

*Update*

This was taken from DirectX7 documentation:
Playing the Primary Buffer Continuously

When there are no sounds playing, DirectSound stops the mixer engine and halts DMA (direct memory access) activity. If your application has frequent short intervals of silence, the overhead of starting and stopping the mixer each time a sound is played may be worse than the DMA overhead if you kept the mixer active. Also, some sound hardware or drivers may produce unwanted audible artifacts from frequent starting and stopping of playback. If your application is playing audio almost continuously with only short breaks of silence, you can force the mixer engine to remain active by calling the IDirectSoundBuffer::Play method for the primary buffer. The mixer will continue to run silently.
Now the only thing left is to get a pointer to the primary sound buffer, I tried with the result returned by InitSound() with no success. Does anybody know how to do it?

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
Post Reply