Page 1 of 3
Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 6:47 pm
by netmaestro
*** Not a PB Bug - mod please move to General Discussion or Windows ***
PB 5.31 beta 3 x86 Windows:
[edit] Updated to B4 - Bug appears in Windows 8.1 but seemingly not in Windows 7
The first time a sound is played the volume is too low. Subsequent calls to PlaySound() are ok though. Please accept this humble snippet, offered for your debugging pleasure:
Code: Select all
InitNetwork()
file$ = GetTemporaryDirectory()+"click.wav"
If FileSize(file$) = -1
Debug "downloading test file"
If Not ReceiveHTTPFile("http://lloydsplace.com/click.wav", file$)
Debug "could not download sound"
End
EndIf
Else
Debug "test file found"
EndIf
InitSound()
LoadSound(0,file$)
SoundVolume(0, 100) ; This doesn't help
PlaySound(0, 0, 100) ; First play, volume is quite low
Delay(1000)
PlaySound(0, 0, 100) ; Second play, volume is correct
Delay(1000)
Re: Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 7:36 pm
by Thunder93
I'm using PB 5.31 Beta 4 (x64 & x86.) Running w/ Windows 7 Home Premium.
I tested the code giving, and it is same volume level for each. Perhaps you should test with the latest Beta before exploring further.
Re: Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 7:44 pm
by netmaestro
Tricked and confounded by Fred's work ethic yet again! Ok - installed the latest beta and retested, still bugged. Tried it on my wife's Win 7 machine and all is well. I'm running windows 8.1
Re: Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 7:57 pm
by Thunder93
Hopefully a Win 8.1 user will test your code out and report back. If it is specific to just you, you may consider upgrading your sound drivers. If no update available, uninstall and re-boot, and reinstall the sound drivers.
Re: Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 8:06 pm
by Thunder93
This only a problem with a short wav file? Are you able to find / use a wav with a longer play time and see if the initial play reaches normal volume level?
This normally shouldn't matter.., however did you try playing a locally found wav and bypassing the downloading procedure?
... I suppose the download was for other people convenience.
Re: Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 8:12 pm
by netmaestro
The test file download was only created to share the sound file so others could test.
A longer file does seem to work ok.
Re: Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 8:23 pm
by Thunder93
Alright. Sounds like your player or codec package is set with 'Auto volume control' that seems very sensitive or glitchy.
If you know what I'm referring to.. try temporarily disabling auto volume control and testing. Naming may be different depending on what you using.
Re: Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 8:32 pm
by netmaestro
I can't find a place to disable auto volume control or similar. Doesn't matter though, I'm sure it exists somewhere.
Bottom line is, this appears not to be a bug in PureBasic. Thanks to Thunder93 for investigating.
Re: Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 8:35 pm
by RASHAD
Hi NM
First of all Happy Birthday
Second I think the code should be as follows
SoundVolume() after PlaySound()
Change the sound volume,
in real-time
Try to set the volume to different values and see yourself
Code: Select all
InitNetwork()
file$ = GetTemporaryDirectory()+"click.wav"
If FileSize(file$) = -1
Debug "downloading test file"
If Not ReceiveHTTPFile("http://lloydsplace.com/click.wav", file$)
Debug "could not download sound"
End
EndIf
Else
Debug "test file found"
EndIf
InitSound()
LoadSound(0,file$)
PlaySound(0, 0, 100) ; First play, volume is quite low
SoundVolume(0, 100,#PB_All ) ; This doesn't help
; PlaySound(0, 0, 100) ; First play, volume is quite low
Delay(1000)
;
; PlaySound(0, 0, 100) ; Second play, volume is correct
; Delay(1000)
Re: Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 8:39 pm
by Thunder93
Happy Birthday!!
..If you interested, I might still be-able to help. If you tell me the Media Player name that you using and name of any audio codec packages installed.
Re: Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 8:40 pm
by netmaestro
@Rashad: Thanks for looking, but moving SoundVolume() right after PlaySound() so that it executes while the sound is playing doesn't change anything here. The 'real time' comment in the doc only means that it will work after the sound has started playing, not that it must execute after play has started. Calling it at top-of-code right after the sound is loaded will work for all subsequent calls to PlaySound. I think my OS is doing this for some reason and it's not related to PB.
Re: Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 8:47 pm
by netmaestro
@Thunder93
I've tested with Windows Media Player as default player for .wav and also with Media Player Classic (from k-lite codec package) and they both behave the same. Proof that PB is not responsible: Playing sound in a loop with either player results in the first click coming at low volume, all subsequent clicks are full volume. As you may have guessed, my audio codecs come from the k-lite standard package, recent but probably not the latest.
Re: Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 8:57 pm
by Thade
Not shure - but it could be a FEATURE in Win 8 and Win 8.1
Win 8+ obviously tries to "optimize" wav files while loading them.
I made several games with 3DRad and I had to convert all Wav files to Ogg because The Mono Wavs I used for 3DSound in 3DRad got converted to Stereo while the program loads. What makes 3DRad stop loading the rest of the program with the Message "Sound must be Mono" ...
After that experience I think its better not to use wavs if you want to avoid trouble in Win 8+
Re: Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 9:10 pm
by RASHAD
@NM
With my system
If I used a different value for sound volume before play it
It does not affect the sound volume at all
But after, it do the job as expected
We have now another point of view by Thade he looks felt in deep with WAV files problems
My system configuration
RealTek HD
Creative 5.1 through optical connection
K-Lite codec 10.5.5
Windows 8.1 x64
Re: Sound volume wrong on first PlaySound()
Posted: Sat Oct 25, 2014 9:11 pm
by Thunder93
I would uninstall the K-Lite Codec package and added Media Player. Restart the computer and see if things are back to normal. If not then I seriously suggest going to the computer manufacture website and download the latest sound drivers for that computer. After download completed, uninstall existing sound driver package and restart. Windows will likely detect and install generic sound drivers. Let it, and once completed run your test. - It should play properly now.
Then continue with install of the latest sound drivers and again .. test.