improve engine sound

This commit is contained in:
interfisch 2024-12-29 21:48:08 +01:00
parent 7e3cfdf5db
commit 9cd4857171

View file

@ -29,6 +29,7 @@ func setCarAcceleration(a,delta):
var maxchange=2.0*delta
caraccel+=min(maxchange,max(a-caraccel,-maxchange))
func _fill_buffer():
var increment_motorrotation = carspeed*increment_motorrotation / sample_hz
@ -42,8 +43,8 @@ func _fill_buffer():
vol_basefrequency_sample+=clamp(vol_basefrequency-vol_basefrequency_sample,-maxsamplevolumechange,maxsamplevolumechange)
vol_overtones_sample+=clamp(vol_overtones-vol_overtones_sample,-maxsamplevolumechange,maxsamplevolumechange)
sample+=noise.get_noise_2d(cos(phase_rotation*TAU)*2,sin(phase_rotation*TAU)*2)*vol_basefrequency_sample
sample+=noise.get_noise_2d(cos(phase_rotation*6*TAU)*0.5,sin(phase_rotation*3*TAU)*0.5)*vol_overtones_sample/2
sample+=noise.get_noise_2d(cos(phase_rotation*TAU)*0.2,sin(phase_rotation*TAU)*0.2)*vol_basefrequency_sample
sample+=noise.get_noise_2d(cos((phase_rotation+0.1)*3*TAU)*0.5,sin(phase_rotation*1*TAU)*0.5)*vol_overtones_sample/2
sample+=noise.get_noise_2d(cos(phase_rotation*3*TAU)*1,sin(phase_rotation*2*TAU)*1)*vol_overtones_sample
@ -57,10 +58,11 @@ func _fill_buffer():
func _process(_delta):
vol_basefrequency=caraccel*clamp(remap(carspeed,20.0,100.0,0.0,1.0),0,1)*clamp(remap(carspeed,200.0,500.0,1.0,0.5),0,1)
vol_basefrequency=clamp(remap(carspeed,20.0,100.0,0.0,1.0),0,1)*clamp(remap(carspeed,200.0,500.0,1.0,0.5),0,1)
vol_basefrequency*=caraccel
vol_overtones=clamp(remap(carspeed,20.0,100.0,0.0,1.0),0,1)*clamp(remap(carspeed,200.0,500.0,1.0,0.5),0,1)
vol_overtones*=(0.5+caraccel*0.5)
_fill_buffer()