Ok, Shakti, quick update.
I've done a lot more research and a thorough read of my DX9 audio book. Here is my current idea for your sound engine. I will need to work closely with you on some key issues but more on that in just a bit.
I'm not sure how much you know about DirectAudio programming or how it all works so I'll keep it fairly simple...but you must know some of it to use it.
First of all DirectAudio is both DirectMusic and DirectSound combined. With the advent of DirectX 8.0 they were combined into DirectMusic. What this means for us is that it is easier to get sound up and running.
Here are some key structures in the sound design:
Audiopaths
Segments
Tracks
Bands
Motifs
Styles
Groove levels
DMOs -> effects like reverb, etc.
3D sound positioning
In the design of this sound engine I separated DirectMusic and DirectSound - or succintly the music and sound effects use two different classes. The reasons for this are a bit involved so I'll leave that for later.
To get this system working you need to understand audiopaths. Audio paths are quite simply the path that any sound(s) take to get to the final PCM wave data that leaves the soundcard and goes to the speakers. This includes effects, spatial positioning, panning, etc.
In short each tank or CSoundEmitter as I called it is assigned to one of 32 different Audio paths. However this does not leave an audiopath for music which I'm sure you'll want to add later. We need to get together on how you want this thing designed. Don't get an audiopath mixed up with how many sounds can play. Any number of sounds can play on any audio path an unlimited number of times...however there are only 32 3D hardware sound buffers. This means that you and I have to figure out a way to prioritize sounds.
One solution is this:
1. Calculate the squared distance from any CSoundEmitter to the camera...or the center of the screen.
2. If distance lies outside of a certain value then that object has a very low priority and probably will not be heard and as such will not be assigned an audiopath.
3. For CSoundEmitter objects that do pass the test we then assign it an audiopath.
For special reverb effects, etc. I suggest we create 2 or 3 audio paths that have these DMOs already on them. When we want the sound effect to play with reverb effect...we simply call Play with that audiopath pointer. Note that any sound that is played on that audiopath will have the reverb effect.
The 3D sound will be taken care of simply by updating all CSoundEmitter objects that have been assigned an audiopath...and thus are audible....and then calling the CDXAudio function to set the position of the sound in 3D space. Don't worry about 2D vs 3D. If we position the camera directly above the playing field then that is the camera's Z coordinate, not its Y. Since Z increments into the screen on Direct3D and decrements in OpenGL - we simply take the absolute value of the camera height from the playing field and use it for Z. X and Y will then correspond correctly with the camera's orientation and the sound's will be correct.
What this will do is when a tank begins to move you may fire off one segment that is the sound of the tank 'starting up' or beginning to move. Then we transition to another segment that is the tank moving. I can alter the pitch of the sound to simulate the engine revving up and revving down. As the tank moves off center of the screen....it's sound slowly fades away. When the tank moves out of earshot of the camera....it is no longer heard and its audiopath is unassigned. We may wish to make the sound quad much larger than the visual quad of the camera so that offscreen gunshots, explosions, etc... can be heard....albeit barely heard.
I simply cannot go into every detail here as there are tons of them. But I can program the entire 3D sound engine for your game as well as the music portion...when we get there. We, however, need to talk much more about the design and goals of the game and the types of sounds you want as well as the memory footprint you will give for the sounds (how much RAM you'll allow for sounds).
When we get it working with quality sounds (might have to purchase these) and music (I have some composers I know that might be able to help)....it will sound like it was professonally done.
I will get teamspeak up ASAP so we can get to work on the sound engine and so that I can send it to you for testing.
I'm also working on an editor for editing maps to be used in the game.
Also, have you implemented waypoints yet and are you using DirectInput? I've got a very rudimentary DirectInput class that handles keyboard and mouse input. Your waypoint code could look something like this:
Code:
...
...
if (Mouse._mousestate.rgbButtons[1])
{
if (DIKEYDOWN(TheKeyboard.keystate,DIK_CTRL))
{
CurrentObject->AddWaypoint(Mouse._mousestate);
}
}
...
...
struct Waypoint
{
long x;
long y;
float vx;
float vy;
int eulerangle;
waypoint *next;
};
void CObject::AddWaypoint(DIMOUSESTATE &mstate)
{
long x=mstate.lx;
long y=mstate.ly;
waypoint newwaypoint;
vectorx=x-prevwaypoint.x;
vectory=y-prevwaypoint.y;
length=sqrt((vectorx*vectorx)+(vectory*vectory));
if (length>0)
{
newwaypoint.vx=vectorx/length;
newwaypoint.vy=vectory.length;
newwaypoint.eulerangle=(int)(atan2(newwaypoint.vy,newwaypoint.vx)*PI/180.0);
newwaypoint.x=lx;
newwaypoint.y=ly;
newwaypoint.next=NULL;
}
prevwaypoint.next=&newwaypoint;
prevwaypoint=&newwaypoint;
}
Pointers might be goofed up and I haven't tested it buy you get the idea.