Sound volume wrong on first PlaySound()

Windows specific forum
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Sound volume wrong on first PlaySound()

Post 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)
Last edited by netmaestro on Sun Oct 26, 2014 9:40 pm, edited 4 times in total.
BERESHEIT
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Sound volume wrong on first PlaySound()

Post 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.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Sound volume wrong on first PlaySound()

Post 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
BERESHEIT
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Sound volume wrong on first PlaySound()

Post 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.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Sound volume wrong on first PlaySound()

Post 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. :mrgreen:
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Sound volume wrong on first PlaySound()

Post 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.
BERESHEIT
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Sound volume wrong on first PlaySound()

Post 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.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Sound volume wrong on first PlaySound()

Post 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.
BERESHEIT
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Re: Sound volume wrong on first PlaySound()

Post 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)
Egypt my love
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Sound volume wrong on first PlaySound()

Post 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.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Sound volume wrong on first PlaySound()

Post 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.
Last edited by netmaestro on Sat Oct 25, 2014 8:54 pm, edited 1 time in total.
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Sound volume wrong on first PlaySound()

Post 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.
BERESHEIT
Thade
Enthusiast
Enthusiast
Posts: 266
Joined: Sun Aug 03, 2003 12:06 am
Location: Austria

Re: Sound volume wrong on first PlaySound()

Post 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+
--------------
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Re: Sound volume wrong on first PlaySound()

Post 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
Last edited by RASHAD on Sat Oct 25, 2014 9:17 pm, edited 2 times in total.
Egypt my love
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Sound volume wrong on first PlaySound()

Post 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.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Post Reply