Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Sync audio with animation


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 NiteLordz   Members   -  Reputation: 459

Like
0Likes
Like

Posted 08 November 2012 - 07:37 PM

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

Sponsor:

#2 kd7tck   Members   -  Reputation: 719

Like
0Likes
Like

Posted 08 November 2012 - 09:21 PM

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, 08 November 2012 - 09:22 PM.


#3 BeerNutts   Crossbones+   -  Reputation: 2998

Like
1Likes
Like

Posted 09 November 2012 - 02:35 PM

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.


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)

#4 kd7tck   Members   -  Reputation: 719

Like
0Likes
Like

Posted 09 November 2012 - 02:40 PM

oops, let me rephrase.

Edited by kd7tck, 09 November 2012 - 02:43 PM.


#5 kd7tck   Members   -  Reputation: 719

Like
0Likes
Like

Posted 09 November 2012 - 02:41 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS