Public Group

# Implementing bicycle audio

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

## Recommended Posts

Hi All,

I have a bicycle, and a sound that's "clicking" simulation of the freewheel. How would you implement that clicking noise ?

Would you change the pitch of the sound?

##### Share on other sites

The pitch should not change, the speed of the clicks should change, according to the speed of the bike.  I think if you change the speed of the sample, the pitch would change too much, but you may want to experiment and confirm that.  Alternatively you could have several samples of a wheel spinning at different speeds?

##### Share on other sites

It depends on the platform you are running on.

In the general case you would create a new instance of the sound effect every time you want a click, but in practice this often sounds crap.

The best way I have found to do similar things is to create 3 or 4 sound effects for the click, each very slightly different.

Then randomly choose one of them and create a new instance of that when you want a click.

I honestly cannot tell you why this works better than just using one sound effect, but it does.

##### Share on other sites

I'm currently doing the following code, but I'm not sure of it

// in game loop

if (currentSate == RunnerBase.BikerStates.RUNNING)
{
if (!mRunningSound.IsPlaying)
{
mRunningSound.Play();
}
//  clickCounter++;
// if (clickCounter > 15)
//  {
mRunningSound.AudioSource.pitch =(mBiker.BikeRunner.Speed/30.0f);
//      clickCounter = 0;
// }

}

##### Share on other sites

That just won't work I'm afraid

Start off by trying this (pseudo code)

Update()

{

accumulator += mBiker.BikeRunner.Speed;

if (accumulator>CLICK_RATE)

{

PlayNewInstanceOfSOund(CLICK);

accumulator-=CLICK_RATE;

}

}

The problem is that a click from the bike doesn't stop in real life when another click starts. You get a new sound every time a click happens. So the sound overlaps, interferes with itself, sounds completely different. It doesn't go up in pitch.

You need to have a sound manager that supports instances and keep the click sound effect short so that the number of sound effects playing doesn't explode.

##### Share on other sites

would you tell me the idea in plain example ? the maths ?

I wanted to do if ( counter++>period) play, then make counter = 0;  is that wrong ?  why did you accumulate the speed then you subtract the rate from it ?

this is not linear operation correct?

##### Share on other sites

okay consider a wheel with 36 spokes.

You have a clicker on one spoke.

So every time the wheel rotates one revolution, you get one click.

Say you start off slow, you only move the wheel 10 degrees in the first pass, that is one spoke moving past the reference point. So you don't make a click sound.

The next pass you accelerate and the wheel turns 370 degrees, that's 37 spokes passing the reference point, the accumulator is now at 38 so you make a click sound.

38 - 36 means that the clicker is 20 degrees past the reference point.

Zeroing the counter would put the clicker at the reference point, so you have lost 20 degrees of rotation and delayed the next click.

If you want a really good effect you will have to do a lot more work, but this simple technique will give you a starting point.

Edited by Stainless

##### Share on other sites

That's really the idea of a basic wheel encoder, where you count the ticks of the wheel, correct?

What are your suggestions to make it better?

Edited by AhmedSaleh

##### Share on other sites

Once you get up to a speed where you are generating a lot of clicks, it will start to sound a bit weird.

It's due to the nature of sampled sound, analogue signals combine in a different way than digital signals.

Also the clicker does not return to a stable state between clicks. It doesn't have time to settle down to a stable state. So the sound it creates changes.

Think of a guitar string, pluck it when it is stationary and you get one sound, pluck it several times in a row and you get a more complex sound.

To emulate this I would have several click sound effects in memory and select one at random each time you play one.

The end result should sound a lot better than the simple case.

##### Share on other sites

How about getting the reverse ? when the bike settles or decelerating? it should clicks in reverse ?
doesn't hear nice :/

   clickCounter += mBiker.BikeRunner.Speed;

if (clickCounter < clickRate)
{
if (!mRunningSound.IsPlaying)
{
mRunningSound.Play();
}

clickCounter -= clickRate;
}


• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 18
• 12
• 9
• 9
• 25