Sound bug workaround?

BlitzPlus Forums/BlitzPlus Programming/Sound bug workaround?

DrMartin(Posted 2004) [#1]
Has anybody found a fix or workaround for this bug:
http://www.blitzbasic.com/Community/posts.php?topic=26915
?

Short version: Start a program that use the soundcard while a Blitz program is running, and any sound in the Blitz program will just die. When explorer.exe gets focus the sound comes back again.

--
Martin Gunnarsson


meemoe_uk(Posted 2008) [#2]
Has this bug been fixed yet? I still get it.
For me the sound becomes grainy and crackly, and varys in serverity, from barely noticable to killing the sound completely.
I used to think it was my computers fault, since the sound would break in simular fashion on other applications, doom, unrealT, duke3D... but then it turned up on other computers I was testing on. Sometimes it doesn't occur. Other times it takes a while before it occurs in the blitz prog. Other times it's there from the start.
It's behaviour is different on different computers. There are plenty of apps that don't have this problem at all. I can have other apps running while I load music into blitz's music browser, and get the bug in the blitz music without it in the other app. Bug can occur with min code, i.e. loadsound, playsound. It affects sfx as well as music.

Seems like there's a 'loose variable' somewhere in the blitz sound code. For PC sound, I think some assumption that was correct a while ago is no longer correct, and several apps have been caught out.


meemoe_uk(Posted 2008) [#3]
heh. I've lived with the problem for years, and only occasionally tried to tackle it. I've only just now realised that it helps to close all other apps when running my blitz prog. Seems blitz sound is taking a lower prior than these apps. Doesn't completely solve prob though, only reduces severity. i.e. takes awhile for prob to occur. Doesn't completely destroy sound, only mildly grainy.


meemoe_uk(Posted 2008) [#4]
OK, I've solved my own instance of the problem, I will try to describe.
I was using the 'playmusic, pausechannel' workaround used to avoid loading music during playtime. It seems that some musics misbehave if you do this. I'm not sure why, I suspect it's due to complexity of the music. The one which generated the problem for me was a 22 channel xm file.
Solution. Identify the musics which cause the prob and use stop channel instead of pausechannel. If the you want to stick with the music, you will have to resort to loading music while ingame.

For me the problem was tricky since the sound didn't break until the problem music was loaded and played, paused, some other music was loaded, played, paused, and the some other music was played. ?!? Crazy.

I'm not convinced this is the general solution to the bug for all users. It may crop up in other forms on different computers, since I think it's a 'loose variable' bug. If this doesn't work for you you might try reducing the number of musics loaded and stored with the playmusic,pausechannel workaround.

Here's the code I used to ID the bad music...



s1=PlayMusic(<filename of problem music>)

s2=PlayMusic<filename of ok music1>)
PauseChannel s2
s3=PlayMusic(<filename of ok music2>)
PauseChannel s3

sfx1=LoadSound(<sfx to test for breakage>)

MouseWait()
PauseChannel s1 ; Change this to STOPchannel to solve the bug!!!
ResumeChannel s2
a=PlaySound(sfx1)
While Not KeyDown(1)
If MouseHit(1) Then b=PlaySound(sfx1)
Wend

PauseChannel s2
ResumeChannel s3

While Not KeyDown(2)
If MouseHit(1) Then b=PlaySound(sfx1) ; sound breaks here!!!
Wend

End


TAS(Posted 2011) [#5]
Nice work, I was having the same problem switching between 17 background sounds.