53 for (
int i=0; i<4; i++) {
54 for (
int j=0; j<3; j++) {
62 sgVec3 zeroes = {0.0f, 0.0f, 0.0f};
95 if (turbo_lag > 0.0f) {
98 fprintf (stderr,
"warning: turbo lag %f <= 0\n", turbo_lag);
126 for (
int i=0; i<3; i++) {
149 float gear_ratio = car->_gearRatio[car->_gear + car->_gearOffset];
155 float turbo_target = 0.1f;
156 float turbo_target_vol = 0.0f;
163 float turbo_target_pitch = turbo_target * car->_enginerpm / 600.0f;
175 float rev_cor = car->_enginerpm/car->_enginerpmRedLine;
176 float rev_cor2 = rev_cor * rev_cor;
210 for (wheelIndex = 0; wheelIndex < 4; wheelIndex++) {
221 bool wheelSpinning =
false;
222 for (wheelIndex = 0; wheelIndex < 4; wheelIndex++) {
223 if (car->_wheelSpinVel(wheelIndex) > 0.1f) {
224 wheelSpinning =
true;
230 if ((car->
pub.
speed < 0.3f) && !wheelSpinning) {
234 for (wheelIndex = 0; wheelIndex<4; wheelIndex++) {
238 tdble ride = 0.001f * car->_reaction[wheelIndex];
241 tdble otherSurfaceContribution = 0.0f;
242 tdble otherRoughnessFreq = 1.0f;
245 if (onOtherSurface) {
257 otherRoughnessFreq, tmpvol, ride, wheelIndex, car->_reaction[wheelIndex]);
262 bool onOtherDifferentSurface =
265 tdble roadContribution = 0.0f;
266 tdble dirtContribution = 0.0f;
268 if (onOtherDifferentSurface) {
270 if (mainSurfaceIsOffroad) {
271 dirtContribution = 1.0f - otherSurfaceContribution;
272 roadContribution = otherSurfaceContribution;
274 roadContribution = 1.0f - otherSurfaceContribution;
275 dirtContribution = otherSurfaceContribution;
279 if (mainSurfaceIsOffroad) {
280 dirtContribution = 1.0f;
282 roadContribution = 1.0f;
287 if (roadContribution > 0.0f) {
289 otherRoughnessFreq, tmpvol, ride, wheelIndex, car->_skid[wheelIndex],
290 car->_wheelSlipAccel(wheelIndex), car->_reaction[wheelIndex]);
294 if (dirtContribution > 0.0f) {
295 tdble dirtRoughnessFreq = 0.0f;
296 tdble dirtRoughness = 0.0f;
298 getDirtRoughnessParams(car, wheelIndex, mainSurfaceIsOffroad, roughnessFreq, otherRoughnessFreq, dirtRoughnessFreq, dirtRoughness);
299 handleDirtContribution(dirtContribution, dirtRoughnessFreq, dirtRoughness, car->_skid[wheelIndex], tmpvol, ride);
303 for (wheelIndex = 0; wheelIndex<4; wheelIndex++) {
304 tdble az = car->_yaw;
305 tdble Sinz = sin(az);
306 tdble Cosz = cos(az);
311 tdble dx = x * Cosz -
y * Sinz;
312 tdble dy = x * Sinz +
y * Cosz;
314 tdble dux_initial = -car->_yaw_rate *
y;
315 tdble duy_initial = car->_yaw_rate * x;
317 tdble dux = dux_initial * Cosz - duy_initial * Sinz;
318 tdble duy = dux_initial * Sinz + duy_initial * Cosz;
331 return materialName &&
335 || strstr(materialName,
"gravel")
336 || strstr(materialName,
"mud")
344 if (roughnessFreq>2.0f) {
345 roughnessFreq = 2.0f + tanh(roughnessFreq-2.0f);
347 return roughnessFreq;
354 bool mainSurfaceIsOffroad,
356 tdble otherRoughnessFreq,
357 tdble& dirtRoughnessFreq,
360 if (mainSurfaceIsOffroad) {
361 dirtRoughnessFreq = roughnessFreq;
364 dirtRoughnessFreq = otherRoughnessFreq;
371 tdble dirtContribution,
372 tdble dirtRoughnessFreq,
378 if (dirtContribution > 0.0f) {
379 tdble dirtpitch = tmpvol * (0.5f + 0.5f*dirtRoughnessFreq);
380 tdble dirtvol = (0.5f + 0.2f*tanh(0.5f*dirtRoughness))*tmpvol*ride*dirtContribution;
387 tdble grassvol = wheelSkid*dirtContribution;
397 bool mainSurfaceIsOffroad,
398 tdble roadContribution,
400 tdble otherRoughnessFreq,
405 tdble wheelSlipAccel,
408 if (roadContribution > 0.0f) {
409 tdble roadRoughnessFreq;
410 if (!mainSurfaceIsOffroad) {
411 roadRoughnessFreq = roughnessFreq;
413 roadRoughnessFreq = otherRoughnessFreq;
416 tdble roadpitch = tmpvol*(0.75f+0.25f*roadRoughnessFreq);
417 tdble wind_noise = 1.0f;
418 tdble road_noise = 0.25f;
419 tdble roadvol = tmpvol*(wind_noise + ride*road_noise)*roadContribution;
420 if (
road.
a < roadvol) {
425 if (wheelSkid > 0.05f) {
426 wheel[wheelIndex].
skid.
a = (float)(wheelSkid-0.05f)*roadContribution;
427 float wsa = tanh((wheelSlipAccel+10.0f)*0.01f);
428 wheel[wheelIndex].
skid.
f = (0.3f - 0.3f*wsa + 0.3f*roadRoughnessFreq)/(1.0f+0.5f*tanh(wheelReaction*0.0001f));
437 tdble otherSurfaceContribution,
438 tdble curbRoughnessFreq,
439 tdble otherRoughnessFreq,
445 if (wheelReaction > 0.0f) {
446 tdble curbContribution = 0.0f;
448 curbContribution = 1.0f - otherSurfaceContribution;
450 curbContribution = otherSurfaceContribution;
451 curbRoughnessFreq = otherRoughnessFreq;
454 if (curbContribution > 0.0f) {
456 float curbpitch = tmpvol*(0.75f+0.25f*curbRoughnessFreq);
457 float curbvol = tmpvol*(5.0f + ride/3.0f)*curbContribution;
459 if (
curb.
a < curbvol) {
501 if ((collision & 16 )) {
505 if ((collision & 8 )) {
509 if (((collision & 1) ==0) ||
tdble kRoughness
Roughtness in m of the surface (wave height)
void setListenerPosition(sgVec3 p)
QSoundChar engine_backfire
CarSoundData(int id, SoundInterface *sound_interface)
void handleDirtContribution(tdble dirtContribution, tdble dirtRoughnessFreq, tdble dirtRoughness, tdble wheelSkid, tdble tmpvol, tdble ride)
float turbo_rpm
when turbo comes in
tdble otherSurfaceContribution[4]
void setEngineSound(TorcsSound *engine_sound, float rpm_scale)
void setCarPosition(sgVec3 p)
#define RM_CAR_STATE_NO_SIMU
Do not simulate the car.
TorcsSound * engine_sound
bool turbo_on
use turbo sound
void setCarSpeed(sgVec3 u)
float base_frequency
engine base frequency for ~ 6000 rpm
void calculateBackfireSound(tCarElt *car)
Calculate the frequency and amplitude of a looped backfiring sound.
void calculateCollisionSound(tCarElt *car)
void calculateEngineSound(tCarElt *car)
Calculate characteristics of the engine sound.
const char * material
Type of material used.
void calculateTyreSound(tCarElt *car)
tPosd relPos
position relative to GC
tTrackSeg * otherSurfaceSeg[4]
float attenuation
global distance attenuation
float tdble
Floating point type used in TORCS.
bool isOffRoadSurface(const tTrackSeg *const seg)
#define TR_CURB
Curb (border only)
QSoundChar drag_collision
tdble calculateRoughnessFreqency(const tTrackSeg *const seg)
void handleRoadContribution(bool mainSurfaceIsOffroad, tdble roadContribution, tdble roughnessFreq, tdble otherRoughnessFreq, tdble tmpvol, tdble ride, int wheelIndex, tdble wheelSkid, tdble wheelSlipAccel, tdble wheelReaction)
static SoundInterface * sound_interface
tdble accelCmd
Accelerator command [0.0, 1.0].
int collision
Collision value for graphics and sound, clearing is managed by consumers.
void setTurboParameters(bool turbo_on, float turbo_rpm, float turbo_lag)
Track segment (tTrackSeg) The segments can be straights (type TR_STR): (the track goes from the right...
tTrackSeg * seg
Track segment where the wheel is.
void calculateGearChangeSound(tCarElt *car)
void handleCurbContribution(tPrivCar *car, bool onOtherSurface, tdble otherSurfaceContribution, tdble curbRoughnessFreq, tdble otherRoughnessFreq, tdble tmpvol, tdble ride, int wheelIndex, tdble wheelReaction)
float smooth_accel
smoothed acceleration input
tTrackSurface * surface
Segment surface.
void update(tCarElt *car)
Data known only by the driver.
void getDirtRoughnessParams(tCarElt *car, int wheelIndex, bool mainSurfaceIsOffroad, tdble roughnessFreq, tdble otherRoughnessFreq, tdble &dirtRoughnessFreq, tdble &dirtRoughness)
int style
Border and barrier segments style:
float pre_axle
axle related
tdble kRoughWaveLen
Wave length in m of the surface.
void calculateAttenuation(tCarElt *car)
Use inverse distance to calculate attenuation of sounds originating from this car. Useful for prioritisation of sounds.
SoundInterface * sound_interface
float turbo_ilag
how fast turbo catches up with engine
tDynPt DynGCg
GC data (world axis)