Jump to content
  • Advertisement
Sign in to follow this  
vNeeki

OpenAL audio channels ?

This topic is 2587 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

Hi.

I would like to implement a generic openal driver for my little framework but there is one thing bugging me :
How do i manage the available audio channels ? Would a system like this allow me to play multiple sfx at the same time?


struct AudioChannel
{
bool used;
u32 id; //AL ID
Sample sample; //sample data/size
AudioChannel(u32 cid):used(false),id(cid)
{
}
};

vector<AudioChannel> channel;

//Allocate once 16 AL buffers and assign them to channel ids
bool init()
{
const int maxChannels = 16;
channel.clear();

for(int i = 0;i<channels;i++)
{
//Get AL ID
AudioChannel c = AudioChannel( generateId() );
//Bind AL buffer
c.sample = generateBuffer();
channel.push_back(c);
}
}

AudioChannel* next()
{
for(int i = 0;i<channels;i++)
{
if(channel.used == false)
{
channel.used = true;
return &channel;
}
}

return NULL;
}

void update()
{
for(int i = 0;i<channels;i++)
{
if(channel.used)
{
if(playing(channel.id) == false)
{
channel.used = false;
}
}
}
}

bool play(const u8* sample,const u32 size)
{
AudioChannel* c = next();

if(NULL == c)
return false;

c->sample.Set(sample,size);

//play it!

return true;
}


Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
I worked with FMODex before. They have virtual channels alongside the channels that are actually playing. The virtual channels swap in and out of actually being audible if the sound sources are close enough to the listener.

I basically created some C++ wrappers around these things in OpenAL.

Listener
SoundSource
AudioRenderer

SceneManager: Manages all of the entities in the scene and keeps them in a nice little acceleration structure so I can do collision detection, view frustum culling, and sound source culling.

The SoundSource objects all play a sound virtually. All this means is I keep track of the play time of the sound and if it's looping. If they are close enough to the listener they get sent to the AudioRenderer to be actually played through OpenAL's sound source objects and come out of the speaker.

Share this post


Link to post
Share on other sites

I worked with FMODex before. They have virtual channels alongside the channels that are actually playing. The virtual channels swap in and out of actually being audible if the sound sources are close enough to the listener.

I basically created some C++ wrappers around these things in OpenAL.

Listener
SoundSource
AudioRenderer

SceneManager: Manages all of the entities in the scene and keeps them in a nice little acceleration structure so I can do collision detection, view frustum culling, and sound source culling.

The SoundSource objects all play a sound virtually. All this means is I keep track of the play time of the sound and if it's looping. If they are close enough to the listener they get sent to the AudioRenderer to be actually played through OpenAL's sound source objects and come out of the speaker.


So if i have 16 buffer ids , could i fill them with 16 different tracks and play them at the same time ? I need to achieve the same stacking effect with sdl mixer which allows you to set different channels for each audio source.

If it wasn't clear im not facing design issues , i only need to play multiple sfx samples simultaneously.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!