The Listener3D object is created and used much like the Buffer3D object is. However, instead of manipulating the actual sound source (of which there can be many), you are dealing directly with the listener, of which there is only one per device. For this reason, you cannot use a SecondaryBuffer when creating a listener object; you can only use a Buffer object, and then only if it is a primary buffer. Before you write the code using the listener object, you should take a look at the properties and settings you can modify on it, much like you did with the 3D buffer object. You will find these properties in Table 14.3.
You should take the existing example where the sound buffer is moving, and update it to move the listener instead. You can get rid of the 3D buffer object you were using, and replace that variable with the following two: private Listener3D listener = null; private Microsoft.DirectX.DirectSound.Buffer primary = null; You need to have a primary buffer in order to create the listener object. You'll also notice that since the class name "Buffer" is also in the system namespace, you will need to fully qualify the buffer variable name. Since you don't have the "buffer" variable anymore, you'll need to update the InitializeSound method as well. Replace the code that is used to create the 3D sound buffer with this: BufferDescription primaryBufferDesc = new BufferDescription(); primaryBufferDesc.Control3D = true; primaryBufferDesc.PrimaryBuffer = true; primary = new Microsoft.DirectX.DirectSound.Buffer(primaryBufferDesc, device); listener = new Listener3D(primary); listener.Position = new Vector3(0.1f, 0.0f, 0.0f); Here similar things are done. You create a primary buffer, and use that to get the listener object, then set the listener's position to a slightly left value. Finally, you just need to update the timer code to move the listener rather than the buffer that's no longer in the code: private void timer1_Tick(object sender, System.EventArgs e) { // Adjust the position listener.Position *= mover; if ((Math.Abs(listener.Position.X) > MoverMax) && (mover == MoverUp)) { mover = MoverDown; } if ((Math.Abs(listener.Position.X) < MoverMin) && (mover == MoverDown)) { mover = MoverUp; } } As you can see, you did nothing more than replace buffer with listener. This example should sound identical to the last one, since the same basic principle is being applied.
|