Sync audio with animation

Started by
3 comments, last by kd7tck 11 years, 5 months ago
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
Code makes the man
Advertisement
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.

For windows you might want to go with a closed library and pay royalties.


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.


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

<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>


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:

struct TFrameData {
Image FrameImage;
uint32_t FrameTime;
std::string AudioToPlay;
}

std::vector<TFrameData> AnimationData;


Just a idea for you to think about.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

oops, let me rephrase.

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.


The link here http://www.fmod.org/fmod-sales.html 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.

This topic is closed to new replies.

Advertisement