Sign in to follow this  
Followers 0
NiteLordz

Sync audio with animation

4 posts in this topic

How can I sync an audio clip to a frame of animation. Simple example is a robot walking. I want the metal clank audio clip to play when the foot hits the ground
0

Share this post


Link to post
Share on other sites
You are going to want to blit the audio manually. Use an audio decoding engine/library, port audio or pulseaudio are great for linux. For windows you might want to go with a closed library and pay royalties.

The blit can be activated when you feed the audio into the audio player sample buffer. You are in control of when the sound starts and ends with this buffer. Keeping this in mind your next step is to set up a game wide event system, which can start/stop audio at a moments notice. Finally you will set the robots foot to have a collision event triggered when it comes in contact with ground. This event starts the sound and it halts when either audio sample buffer is empty or another event overrides it. Edited by kd7tck
0

Share this post


Link to post
Share on other sites
[quote name='kd7tck' timestamp='1352431315' post='4999126']
For windows you might want to go with a closed library and pay royalties.
[/quote]

This is silly, you don't need to pay anything to play audio on Windows machines; SFML, fmod, OpenAL, SDL, DirectX, are all available for free.

[quote]
The blit can be activated when you feed the audio into the audio player sample buffer. You are in control of when the sound starts and ends with this buffer. Keeping this in mind your next step is to set up a game wide event system, which can start/stop audio at a moments notice. Finally you will set the robots foot to have a collision event triggered when it comes in contact with ground. This event starts the sound and it halts when either audio sample buffer is empty or another event overrides it.
[/quote]

When you're robot's animation starts, you can include in the animation script a point at which to play a sound. So, when your robot's animation has reach the point of the foot hitting the ground, you would know to play a sound. Here's a simple example with xml
[code]
<Animation type="robot">
<Frame image="robotstepup.png" time=100 />
<Frame image="robotstepdown.png" time=100 audio="clank.ogg" />
<Frame image="robotstepmid.png" time=100 />
</Animation>
[/code]

Where the image is the image to display during those frames, the time is in millisecond for the image to stay on the screen, and the audio is what to play when beginning the frame. In code, you could have a structure to store this, and use a std::vector to house all the data. SOmething like this:
[code]
struct TFrameData {
Image FrameImage;
uint32_t FrameTime;
std::string AudioToPlay;
}

std::vector<TFrameData> AnimationData;
[/code]

Just a idea for you to think about.
1

Share this post


Link to post
Share on other sites
[quote name='BeerNutts' timestamp='1352493338' post='4999412']
This is silly, you don't need to pay anything to play audio on Windows machines; SFML, fmod, OpenAL, SDL, DirectX, are all available for free.
[/quote]

The link here [url="http://www.fmod.org/fmod-sales.html"]http://www.fmod.org/fmod-sales.html[/url] shows a license cost for commercial use. When I said royalties I meant for commercial use, I assumed they wanted to use it in a game. Most high end windows audio libraries have licensing costs, atleast the good ones do.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0