Hi there. I was following a tutorial (http://msdn.microsoft.com/coding4fun/gamedevelopment/beginning8/default.aspx) but when I put it together and my unit stays stop and I shoot, the sound is fine. However when I start moving from my initial position, everything gets weird.
I am workin on a 2D game and I have in my renderer SoundDevice and SoundListener. So when I create the effect, I do this:
SoundEffect3d s = new SoundEffect3d(_renderer.GetSoundDevice, "sound\\shot.wav");
s.Volume = -1000;
_player.ShootingSound = s;
Then on each FrameEnter after moving the player unit and such, I do this:
_renderer.UpdateListener(new Vector3(_player.GetAbsolutePosition().X, _player.GetAbsolutePosition().Y, 0));
Then if the player is going to shoot, then this is the code for that:
_soundShoot.Stop();
_soundShoot.Update(new Vector3(this.GetAbsolutePosition().X, this.GetAbsolutePosition().Y, 0));
_soundShoot.Play();
But this results a weird sound. When the player stay's on the starting spot, everything is fine, the sound of the shooting is perfect. If I move everything gets weird. The sound gets buggy (usually maybe fading out and in the meantime strong glitches inbetween) and so on.
Can anyone tell me what is wrong
These are the sound objects:
public class SoundListener : IDisposable
{
public SoundListener(SoundDevice device)
{
BufferDescription bd = new BufferDescription();
bd.PrimaryBuffer = true;
bd.Control3D = true;
Microsoft.DirectX.DirectSound.Buffer buffer = new Microsoft.DirectX.DirectSound.Buffer(bd, device.GetDevice);
_listener3d = new Listener3D(buffer);
_listenerSettings = new Listener3DSettings();
_listenerSettings = _listener3d.AllParameters;
}
public void Update(Vector3 position)
{
_listenerSettings.Position = position; //Testing
_listener3d.Position = position;
_listener3d.CommitDeferredSettings();
}
public void Dispose()
{ _listener3d.Dispose(); }
private Listener3D _listener3d;
private Listener3DSettings _listenerSettings;
}
public class SoundEffect3d
{
public SoundEffect3d( SoundDevice device, string filename)
{
BufferDescription bd = new BufferDescription();
bd.Control3D = true;
bd.ControlVolume = true;
//bd.ControlFrequency = true;
bd.Mute3DAtMaximumDistance = true;
bd.Flags = BufferDescriptionFlags.Control3D | BufferDescriptionFlags.ControlVolume;
try
{
_sb = new SecondaryBuffer(filename, bd, device.GetDevice);
_3dBuffer = new Buffer3D(_sb);
_3dBuffer.MaxDistance = 1000;
}
catch { }
}
public void Update(Vector3 position)
{ _3dBuffer.Position = position; }
public void Play()
{
if (_loop == true)
_sb.Play(0, BufferPlayFlags.Looping);
else
_sb.Play(0, BufferPlayFlags.Default);
}
public void Stop()
{
_sb.Stop();
_sb.SetCurrentPosition(0);
}
public bool Loop
{ get { return _loop; } set { _loop = value; } }
public int Volume
{ set { _sb.Volume = value; } }
private SecondaryBuffer _sb;
private Buffer3D _3dBuffer;
private bool _loop;
}
And then there is the SoundDevice object but I dont think that should be the problem.
Can anyone point me to the problem

Sound is very weird with Listener3D
wien
I have the same problem, in my case is that the Listener3D.position and Listener3D.orientation althought I change it(and show me the change), both still conserve the original values. Now Im trying to update DirectX to August2006 and see what happend.
In Conclusion I have the same problem.
Sorry for my Bad English!!!
Pierre Couzy
i have a similar problem. Have you found a solution