Jump to content
  • Advertisement
Sign in to follow this  

Audio classes.

This topic is 2754 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm rewriting the audio class for my game engine right now and I'm using XAudio2 but I never had a good system for playing audio.

This is the current class structure:


class AxAudioBuffer;
class AxAudioEmitter;
class AxAudioInstance;

class AxAudioBuffer
{
public:
std::vector<char> data;
WAVEFORMATEX format;
AxAudioInstance* CreateInstance( AxAudioEmitter* emitter );
};

class AxAudioInstance
{
public:
AxAudioEmitter* emitter;
IXAudio2SourceVoice* voice;
bool paused;
void Play();
void Stop();
void Pause();
void Set();
};

class E_AUDIO_EMITTER
{
public:
//...
void set_pose( XMMATRIX* matrix );
XMMATRIX* get_pose();
};



Basically one would call the CreateAudioBuffer function which would return a pointer to an instance of AxAudioBuffer then you would call the CreateInstance function from there which would return AxAudioInstance that is positioned at the AxAudioEmitter that you passed to the function.

The AxAudioEmitter is a physical object in the 3D scene which acts as an emission point for the audio instance. In the CreateInstance function you can also set this to NULL which will just play the audio without 3D effects.

I just think there should be a simpler way to do it but I'm not sure how?...

Share this post


Link to post
Share on other sites
Advertisement
I can't think of a simpler way, that looks just about right to me. Don't forget 3D positional sounds need a 'listener' too for calculating the speaker coefficients and falloff - make sure to pass that to your AxAudioInstance along with the emitter.

Also, you should derive your AxAudioInstance from IXAudio2VoiceCallback, and override OnStreamEnd() and OnBufferEnd(), so your instance knows when the voice has finished playing the data - you can't poll for an IXAudio2SourceVoice's state.

Share this post


Link to post
Share on other sites
Quote:
Original post by deadstar
I can't think of a simpler way, that looks just about right to me. Don't forget 3D positional sounds need a 'listener' too for calculating the speaker coefficients and falloff - make sure to pass that to your AxAudioInstance along with the emitter.

Also, you should derive your AxAudioInstance from IXAudio2VoiceCallback, and override OnStreamEnd() and OnBufferEnd(), so your instance knows when the voice has finished playing the data - you can't poll for an IXAudio2SourceVoice's state.


I don't want to bump such an old post but I've not worked on this for awhile and I'm just now getting back to it. The listener positions are taken from the cameras in the scene.

I can't think of any reason I would want to make a listener that was not also connected to a camera.

Share this post


Link to post
Share on other sites
Quote:
Original post by SteveDeFacto
Quote:
Original post by deadstar
I can't think of a simpler way, that looks just about right to me. Don't forget 3D positional sounds need a 'listener' too for calculating the speaker coefficients and falloff - make sure to pass that to your AxAudioInstance along with the emitter.

Also, you should derive your AxAudioInstance from IXAudio2VoiceCallback, and override OnStreamEnd() and OnBufferEnd(), so your instance knows when the voice has finished playing the data - you can't poll for an IXAudio2SourceVoice's state.


I don't want to bump such an old post but I've not worked on this for awhile and I'm just now getting back to it. The listener positions are taken from the cameras in the scene.

I can't think of any reason I would want to make a listener that was not also connected to a camera.


If you just have the one camera, and it's accessible from within the AxAudioInstance, then there's no problem. If you wanted to support multiplayer, then you'll have pass in multiple listeners...

It also depends on the view. For a first-person camera, a single listener would be just fine, but if you start dabbling in third-person then it gets a little more complex.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!