Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectSound setVolume takes its time ....

Started by ChaosIII Dec 29, 2007 at 12:07 PM 7 replies 4.4k views
Original Post
ChaosIII
ChaosIII
First: Yes, I used google .. yes, I used the forum search ... Hi guys (and girls?), I am new to this community and fairly new to DirectX programming. Now I encountered a problem with DirectSound. Arlight, I managed to set up all those buffers and stuff and, yeah, the sound is playing. However when it come to altering the volume I stumbled over something odd. I'll get to the point. Basically this: dsound->play(); Sleep(1000); dsound->setVolume(0); works ... bit this: dsound->play(); dsound->setVolume(0); doesn't! ( dsound->play() basically results in a call to IDirectSoundBuffer8::play(...) and dsound->setVolume(0) to IDirectSoundBuffer8::setVolume(-10000) )The first snipped does exactly what it's supposed to. It plays the sound at full volume, continues to do so for a second and then sets the volume to 0 (silence). However in the second snipped the setVolume() call doesn't seem to have any effect at all. The sound simply continues to play at full volume. Even something like this: dsound->play(); while(1) dsound->setVolume(); doesn't have any effect. (except that the App is caught in an infinite loop ^^). I already checked the function's return values and tried to tinker around with various priority levels and flags, but it didn't help. I simply can't change a sound's volume unless i give it some time to ... yeah what? settle in or something ... I tried changing the primary buffer's volume which worked just fine but doesn't really have the desired effect. So if anyone could give me any advice I'd gladly appreciate it. Thanks.
Kest
Kest
What is setVolume(0)? A custom function? Does it rely on the sound to be playing to work correctly? If so, your custom system may not be allowing enough time for the API or hardware to kick the sound into motion. It's difficult to help you further without knowing what's happening with those custom functions.

Personally, I always set sound properties before I play a sound. Then I set them again when the sound dynamically changes in the game. I also use a timer delay to avoid updating sound properties too excessively.
ChaosIII
ChaosIII
Well ok I'll try to explain my constom code a little...
"dsound" is a pointer to a custom "DirectSound" class, which holds the primary SoundBuffer (IDirectSoundBuffer) and a map of custom "SoundFile" classes. Each SoundFile instance holds one secondary SoundBuffer (IDirectSoundBuffer8) ... always in form of pointers of course.
So when I say: "dsound->play()" it is actually something like this: "dsound->play(1)" where 1 is the key value of the map holding the SoundFile pointers. In play(int) the app then iterates through the map until it finds the corresponding SoundFile and then calls the SoundFile's play-function. Which then in turn calls the secondary SoundBuffer's play-function. The same process applies to the setVolume-function respectively.
So as I said before, "dsound->play(1)" basically results in a call to IDirectSoundBuffer8::play(0,0,0,0) ans "dsound->setVolume(1, 0)" (first argument being the map's key value) to IDirectSoundBuffer8::setVolume(-10000); I didn't like DirectSound habit to set volume control from -10000 to 0 so set my custom-function's inpiut from 0 to 10000 and then simply subtract 10000 to get the correct value for the SoundBuffer's setVolume-function.

I also tried to change the volume before I start playing the sound. That, too, didn't have any effect.

[Edited by - ChaosIII on December 30, 2007 1:28:34 PM]
Kest
Kest
Quote:
Original post by ChaosIII
I also tried to change the volume before I start playing the sound. That, too, didn't have any effect.

I would say it has to be a problem with your OS, your sound driver, your sound hardware, or your implementation code. I've never experienced anything similar with Direct Sound. I did a test run to adjust the playing properties of sounds right after playing them in my own engine, but I didn't notice any problems.

Are you using hardware buffers or software buffers?
ChaosIII
ChaosIII
Quote:
Original post by Kest
I would say it has to be a problem with your OS, your sound driver, your sound hardware, or your implementation code.


Oh bummer ... yeah sure of course. I was developing the app on my laptop for the last couple of days. Man I could have thought of that myself.
I tried the whole thing on my desktop now and everything works fine. No delay, and changing the volume before starting the sound works as well.

Thanks a bunch, Kest!!!

psykr
psykr
Just out of curiosity, what hardware/driver combination were you using?
ChaosIII
ChaosIII
My Laptop is an "Aspire 1351LC" and is equipped with a "Realtek AC'97" sound card. The drivers are from May 2003. And apparently these are the latest you can get.

My desktop only uses onboard sound (the mainboard is an "ASROCK K7S8X"), the device is called "C-Media AC97" and the drivers are from June 2006.

That's what you wanted to know?
Nik02
Nik02
Realtek has a newer AC97 driver available. Unless your laptop requires a driver customized by the motherboard manufacturer, it could prove helpful to try to install it.

Realtek driver homepage
Niko Suni
ChaosIII
ChaosIII
I could kiss you guys! The drivers work perfectly and my App runs like a charm even on the laptop now.

Thanks!!!

Topic Locked

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

Sign in to reply to this topic.