SetChannelPan with DirectSound screwy

Archives Forums/BlitzMax Bug Reports/SetChannelPan with DirectSound screwy

Tachyon(Posted 2008) [#1]
From the examples, with tiny modification....

Graphics 640, 480

SetAudioDriver("DirectSound")

channel = AllocChannel ()
sound = LoadSound ("C:\Program Files\BlitzMax\samples\digesteroids\sounds\fire.wav") ' Use a short sample...

Repeat
	If MouseHit(1) PlaySound sound,channel
	
	pan# = MouseX () / (GraphicsWidth () / 2.0) - 1
	vol# = 1 - MouseY () / 480.0
	SetChannelPan channel, pan
	SetChannelVolume channel, vol*2

	Cls
	DrawText "Click to play...", 240, 200
	DrawText "Pan   : " + pan, 240, 220
	DrawText "Volume: " + vol, 240, 240

	Flip
Until KeyHit (KEY_ESCAPE)

End


On my machine, any pan above 0.1 or below -0.1 moves the sound *all the way* to the appropriate speaker, not just a 90%/10% balance like it should.

To hear it correctly, comment out the SetAudioDriver command and use the default driver. It works fine.

[edit] I am on Vista with a Sound Blaster X-Fi card. All drivers up-to-date.


Tachyon(Posted 2009) [#2]
Sorry to bump this, but I am having some really bad sound artifacts due to this panning issue. I have updated the example above as I left off the Graphics command, causing an error.

Note, this has only been observed on Vista. It may work fine on XP for all I know. Although the Default sound driver works, it also produces a horrible delay under Vista which is why I need DirectSound to function properly.


marksibly(Posted 2009) [#3]
Hi,

Can you confirm DirectSound panning/delay are OK with other apps on your setup? Does the OpenAL driver work? Anyone else?

MS have royally stuffed up audio in Vista - DirectSound is now apparently emulated, but no one really knows with what. Yet it is the only way you can seem get delay free audio now.

There are certainly no calls I can make into DirectSound to control 'granularity' of panning or amount of delay or anything...wrong type of device is a possibility I guess, but we did mess with this pretty comprehensively.


Tachyon(Posted 2009) [#4]
Actually, OpenAL doesn't seem to be panning at all. Can anyone else with Vista/OpenAL confirm this as I want to eliminate my PC as the culprit.

I assume other DirectSound apps work under Vista- I've never known any game to exhibit odd/extreme panning issues.


plash(Posted 2009) [#5]
DirectSound and FreeAudio seem to pan as intended (is the pan supposed to be backwards though?)

OpenAL is not panning for me either.
XP2 SP3


REDi(Posted 2009) [#6]
AFAIK OpenAL will not do positioning with stereo sounds, should work okay with mono though.

Not much BRL can do about that one I'm afraid.


SLotman(Posted 2009) [#7]
I confirm that on Vista the panning does not sound right... It "sounds" like the values are only -1,0 or 1.

I took a quick look at the code and it looks right... maybe the problem lies on Vista emulation of directsound?


marksibly(Posted 2009) [#8]
Hi,

Ok, had a closer listen to this, and think I know what's up.

Volume in DirectSound is done is a slightly weird way - it's logarithmic, not linear so there's a little tweak done to the value you send SetVolume before it gets passed on to DirectSound.

I now suspect SetPan needs a similar tweak (actually kind of logical really). Anyway, it should be fixable so please stay 'tuned'!


marksibly(Posted 2009) [#9]
Ok,

Can someone try sticking this before the SetPan...

pan=Sgn(pan) * (1-(1-Abs(pan))^.1)

...does it sound right?

Bye!
Mark


plash(Posted 2009) [#10]
Volume changes all over the place, but it seems like the panning is right.

Kind of a bad example of the issue, with all the volume changing..


Tachyon(Posted 2009) [#11]
Mark: Yes! I think that is it. MUCH smoother transitioning between left/right panning.

So, is this something you'll fix under the hood, or do I need to implement your mathematical wizardry to my panning functions whenever I use DirectSound the driver?


marksibly(Posted 2009) [#12]
Hi,

I'll fix it under the hood for next release.


SLotman(Posted 2009) [#13]
Here, it does sound better, but now, when clicking all the way to the left, it sounds way lower then clicking all the way to the right... before the all-left or all-right sound had the same volume...

Was there any change in the volume function as well?


SLotman(Posted 2009) [#14]
Hmmm... I think I found a better fix!

Keep setpan as it is, but change on the last line from:

_buf._buffer.SetPan pan * 10000

to

_buf._buffer.SetPan pan * 1000

Yes, just take one zero out, and it should work ;)


marksibly(Posted 2009) [#15]
Why is this better?

Pan values are supposed to go from -10000 to 10000, so it's no longer using the whole range...