View Full Version : FMOD question

02-06-2002, 12:10 AM
hi all! I know its not an FMOD forum but you guys must use this sound system in your demos so you may be able to help me! http://www.opengl.org/discussion_boards/ubb/smile.gif

In my game I added the FMOD sound to one of my racing cars engine.
At the moment when driving the car you can hear the cars engine sound which is looped.
I still want to play the same sound by looping it but whenever I increase the accelerator I want to hear a heigher tone of the sound and whenever I decrease the accelerator in the car then the sound should go to some lower tone. Just like it happens in a real car engine ie. if you accelerate then the engine increases its rotation/per minute which makes the engine to work louder and also it changes the tone to some higher tone. I don't want to just increase the volume. I already know how to do it. I want to increase the sound tone. Just like in music you have a tone eg. Tone "C" and then "Cis" and the next tone would be "D". How Can I achieve this effect. Some code examples or a tutorial on this would be a huge help! or anything!!

02-06-2002, 12:21 AM
I don't have the FMOD documentation here, so can only give a generic answer. As I understand it, you should change the sample frequency. If you want to hear the engine in a higher tone, as when you drive fast, you should increase the sample rate. When driving slower, and want to hear a lower tone, decrease the sample rate.

I don't know how much you need to increase/decrease, you have to try it out and see what's best.

02-06-2002, 12:26 AM
Dunno if this is the right way, but the best solution IMHO is to write your hown softsynth.

This way you will fill the buffer for the sound realtime, so u can raise the tone, lower it, and optionally simulate engine wrecks, gear shifts and so, on. Just do some tests and find a good noise generation routine related to the actual engine params.

EngineData -> SampleGenerator -> SamplePlayer

rIO.sK http://www.spinningkids.org/rio

02-06-2002, 12:27 AM
Ah, found the documentation online.

When playing the sample, the function, FSOUND_PlaySound, returns the channel number on which the sample in playing. Call FSOUND_SetFrequency to change the playback frequency of the sample, and pass it the channel number and the frequency.

02-07-2002, 04:35 AM
Thx Bob!! it works!! http://www.opengl.org/discussion_boards/ubb/smile.gif

02-07-2002, 05:07 AM
Just changing the playback frequency of a looping sound is the simplest way to do it. The playback frequency should be proportional to the engine RPM, so:

samplerate = RPM * (f0 / RPM0)

where f0 is the original samplerate of the sound (e.g. 11 KHz), and RPM0 is the RPM the engine was running at when it was sampled.

For additional realism the volume of the sound can be made proportional to the "engine load" (high when accelerating or climbing hills, or driving at high speeds because of wind resistance, low when engine is idle or driving at constant low speeds). A realistic "engine load" should be possible to calculate from the sum of "deacceleration forces" (wind, friction, road slope etc).

To have a better sounding engine, you would probably want to sample the engine sound at different RPMs and loads, and then "interpolate" between the different sounds (using e.g. two channels with different volumes).