snd_tune query

Posted By: tex

snd_tune query - 04/26/16 08:09

I've nearly got everything working for a car racing game.

My only problem now is I am trying to get a revving sound from the engine when it is accelerating - otherwise using the same sound as just a rumble.

As a test, I am using the LMB. But, when I run the below I get "Script Crash Main", I press OK, it finishes loading and then the sound plays but does not adjust frequency to mimic acceleration.

Any ideas?

#include <acknex.h>
#include <default.c>
#include <ackphysx.h>
#include <particles.c>

SOUND* engine_sound = "engine.ogg";

function mouse_leftsound()
{
snd_loop(engine_sound,100,0);
}

.............other code here


function main()
{

.............other code here

while (1)
{

.............other code here

if(mouse_left){
on_mouse_left = mouse_leftsound;
var freq = ++300;
snd_tune(mouse_leftsound,100,freq,0);
}

.............other code here

wait(1);
}
}
Posted By: Reconnoiter

Re: snd_tune query - 04/26/16 11:21

Hi,

I dont know if this is the cause but this part looks suspicious:

Code:
while (1)
{
.............other code here
if(mouse_left){
on_mouse_left = mouse_leftsound;
var freq = ++300;
snd_tune(mouse_leftsound,100,freq,0);
}
.............other code here
wait(1);
}



Placing in a while loop on_mouse_left = mouse_leftsound; looks a bit weird I think. Second shouldn't var freq = ++300; be var freq += 300; ? (dont know if that really matters though)
Finally, snd_loop(engine_sound,100,0); has no handle, which you need for snd_tune I think. This last one is why I think you get the crash and your bug.
Posted By: tex

Re: snd_tune query - 04/26/16 11:42

Thanks for the speedy feedback Reconnoiter.

I have progressed to the script below - which almost works.

It is already inside the main while loop - so should be ok.

Yes - I didn't need the "on_mouse_left = mouse_leftsound;" to trigger the snd

Yes, I needed a handle - now that is 'rev'.

What happens now is the sound starts on load - good - the LMB triggers a change in pitch - good - but on release of LMB the pitch stays the same - it should go back to the original!

Because I am using 'speed' to also drive the wheels of the car I don't really want to change that although I think I need an 'else' to set 'speed' back to zero...

SOUND* engine_sound = "engine.ogg";

var rev;
var freq;

function mouse_leftsound()
{
rev = snd_loop(engine_sound,100,0);
}

.............other code here


function main()
{

.............other code here


mouse_leftsound();

while (1)
{

var speed=0;

if(mouse_left)
{
speed+=1; //forward speed
}

.............other code here

freq = 200*speed;
snd_tune(rev,100,freq,0);

.............other code here

wait(1);
}
}
Posted By: Reconnoiter

Re: snd_tune query - 04/26/16 13:31

No problem, glad to help.

As for your current problem, try to store the original frequency in e.g. a global variable, than put an else after if(mouse_left) to restore the original frequency. So something like this:

var original_freq = whateverNumberYouWantHere;
....
....
if(mouse_left) //left mouse button pressed?
{
speed+=1; //forward speed
freq = 200*speed;
}
else freq = original_freq; //left mouse button NOT pressed
....
....

Could be I misinterpreted your question.
Posted By: tex

Re: snd_tune query - 04/26/16 14:03

that totally worked!

not sure what you are like with PhysX but I have a post over there that hasn't got a response - re concave objects... You might have some ideas?

thanks laugh
© 2024 lite-C Forums