Controling pitch of sound based on a property

Hello, once again i need help with something.
I am working on a gearbox and engine system, and so, i want the sound of the engine to vary with it’s RPM, the whole acceleration system is already done, all i need is to make the sound follow the mechanics, for example:
If i am accelerating, the RPM is rising, and so the sound of the engine should increase pitch and speed, if i release the gas, the RPM drops, and so the sound should decrease speed and pitch. I have set up a property called RPM that goes from 0.0 to 10.0, is there a way to control the pitch of the sound based on this property?

if property rpm changed--------------python-------------sound actuator

http://www.blender.org/api/blender_python_api_2_72_1/bge.types.KX_SoundActuator.html#bge.types.KX_SoundActuator


import bge




def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner


    sens = cont.sensors['Property]
    sound = cont.actuators['Sound']


    if sens.positive:
       sound.pitch=-1+(own['Rpm']*.2) 


main()



Awesome! trying it out now, thanks!
EDIT: I just had to make some adjustments, but it works like a charm, any idea on how to increase speed of the sound without altering pitch?

you may want to isolate a single “firing” of the engine,

and play it more often of less often + adjust pitch…

I would have to experiment for a while to give you the best answer.

That’s a pretty good idea actually, never thought of it, gonna try it soon.

I think made ‘one shot firing sound’ very difficult, If engine has 6000 rpm, you need 6000 hit per second (6000 hz)
Second problem is monotonic ‘machine gun effect’, you have repeatly 6000 similar spikes, and that is not natural sound.
I advice take different samples to 1000, 2000, 3000, 4000 etc rpm’s. And change them with smoothly. 1000-sample fades, and 2000 come in.

Why to tie engine sound and speed together? What is car without transmission.
Set engine speed ex. 1000-6000 rpm, then tranmission first for gear 3:1 and differential 5:1, so that is speed to tires.

I was thinking about getting the rotational velocity, or angular velocity, of the wheel and with a little math i would apply RPM based on the wheel, since it is easier and CPU cheaper than calculating torque based on RPM.
However, i am having trouble getting the angular velocity of the wheel, it just remains as Zero. Any tips on getting the angular velocity and using it to set up a property?