Why is there a delay when I play my sound?

BlitzMax Forums/BlitzMax Beginners Area/Why is there a delay when I play my sound?

UnderwoodNullium(Posted 2008) [#1]
Here is my code:

Global hit:TSound = LoadSound("hit.wav")
If KeyHit(key_enter)
PlaySound(hit)
End If

The hit.wav file is almost a megabyte. I need it to play as soon as enter is pressed, but there is always a delay when I play it, no matter what. I press 'enter', then about half a second later it plays the sound. What is going on? Are there any other ways to play a sound I can try?

Thanks!


xlsior(Posted 2008) [#2]
Are you using Vista, by any chance?

There are several different sound drivers that you can use, and some of them have the delay you describe under certain operating systems. Switching to one of the others may fix your problem.

I don't remember the specific driver options (Directsound, OpenAL, ...?) but you may be able to find it for yourself if you search the forums a bit.


UnderwoodNullium(Posted 2008) [#3]
Yeah, I'm using Vista! Do you think you could give me a little example that shows how to use DirectSound to load and play a sound in BlitzMax? Thanks again.


UnderwoodNullium(Posted 2008) [#4]
Never mind I got it! Thank you so much for your help. I just did:

setaudiodriver("directsound") and it worked.


GfK(Posted 2008) [#5]
DirectSound had some stability problems on certain hardware, too. I don't know if it still does. I'm using OpenAL, anyway.

Its not ideal that Blitzmax doesn't have a single sound driver that works as it should on all hardware. Nobody ever seemed to get to the bottom of it.


Retimer(Posted 2008) [#6]
If it's for an important project..give bruceys FMOD wrapper a look. Once I played around with that, I had absolutely no reason to look elsewhere for any other audio solutions. Beyond streaming it supports a lot of nice jaw dropping features.


tonyg(Posted 2008) [#7]
... does that mean if it is important and you don't mind paying the fmod license fee to use it?


ImaginaryHuman(Posted 2008) [#8]
Notice that KeyHit requires that the key not only be pressed down but also released before it will register as `hit`. You should otherwise test using KeyDown rather than KeyHit, maybe that's got something to do with it.


Koriolis(Posted 2008) [#9]
I don't think it has anything to do with keyhit. There is *really* a 1 second delay when playing a sound on vista with the default audio driver. Choosing another driver does the trick. I'm surprised this hasn't been fixed yet to be honest.


767pilot(Posted 2008) [#10]
I've installed the OPENAL driver and copied the 2 dll into my project root folder.

I use the following

EnableOpenALAudio()

SetAudioDriver("openal")

yet have no sound. Same with

SetAudioDriver("directaudio").

Removing the SetAudioDriver and using the default driver gives me sound again with the delay.

This is on Vista 32 SP1 on a laptop with onboard sound. Any ideas why this would not work?


JazzieB(Posted 2008) [#11]
Try "OpenAL Generic Software" and "Directsound". You need to get the correct name, as I don't think there is one simply called "OpenAL". You can use AudioDrivers() to retrieve the names of all available drivers.