Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / sound issues

Author
Message
CvG NEXUS
5
Years of Service
User Offline
Joined: 28th Nov 2013
Location:
Posted: 28th Nov 2013 15:50
while trying to make a few sound files play when the character is walking, the audio of sound files being played stutter(loops quickly)

example:



I had gotten the file to play normal with using dbWait(milsecs) after
calling dbPlaySound(), but results staggered the program (sound played normal but the sprite was extremely slow on screen).

any Ideas for a fix to foliage?
Mobiius
Valued Member
16
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 28th Nov 2013 21:34 Edited at: 28th Nov 2013 21:36
dbPlaySound restarts the sound from the beginning, so your code will never play the sample in it's entirety.

Try...



The Tall Man
5
Years of Service
User Offline
Joined: 16th Nov 2013
Location: Earth
Posted: 29th Nov 2013 03:14
You could also set a boolean when that key is pressed, to indicate the sound is playing. You can check the state of the boolean to call the dbLoopSound() function, rather than the additional function call of dbSoundPlaying() each frame. It would run quicker, yet.

CvG NEXUS
5
Years of Service
User Offline
Joined: 28th Nov 2013
Location:
Posted: 29th Nov 2013 11:04
thanks for the help friend, code produces same results (sound stutter)
CvG NEXUS
5
Years of Service
User Offline
Joined: 28th Nov 2013
Location:
Posted: 30th Nov 2013 01:56
how would I go about creating a delay function? to call after the dbPlaySound function, just want the audio to be delayed in milsecs not the whole game itself using dbSleep() or dbWait(). the audio file being played for foot steps length is 0.04 of a second and plays rapidly either with dbplaysong() and dbloopsong() because those functions are being handled as rapidly with keystate() being held down.
The Tall Man
5
Years of Service
User Offline
Joined: 16th Nov 2013
Location: Earth
Posted: 30th Nov 2013 09:45
I see what you're doing. I missed the part you said originally about footsteps. Sorry about that. Yeah you don't need loops, just plays.

You can use dbTimer() to create a delay function in ms that doesn't pause the whole program. When you play a particular sound, store the current time. Then once however many ms has passed, play the next one. If that time hasn't passed yet, then don't play the next one. Either way, you check, do or don't do, and let it move on.

And for 2 footstep sounds, you can have an array of 2 elements long for the sound IDs, and have an index to that array MODed by two (or better yet for just 2, ANDed by 1).

Something like this:

FootstepTime = 800; // 800ms

The Tall Man
5
Years of Service
User Offline
Joined: 16th Nov 2013
Location: Earth
Posted: 30th Nov 2013 09:55
As an alternative to dbTimer(), you could have a counter that you reset each time you play a sound. And increment the counter each frame. Then play the next sound after N frames have passed according to the counter.

Or instead of a counter, you could record your position on the floor, or perhaps just the 2D portion. Then calculate the distance of your current position from the position when the sound was played. So after the player's movement has exceeding a certain distance, play the next footstep sound.

distance = sqrt((x-x0)^2 + (y-y0)^2 + (z-z0)^2);

Login to post a reply

Server time is: 2019-09-19 19:58:55
Your offset time is: 2019-09-19 19:58:55