From b96f2546795b3520a6eb1beac00d5d0a6fc1efe7 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Wed, 17 Jan 2018 16:29:48 +0100 Subject: [PATCH] dedicated power inverter sound --- DynObj.cpp | 71 +++++++++++++++------------- DynObj.h | 1 + McZapkie/MOVER.h | 1 + McZapkie/Mover.cpp | 112 +++++++++++++++++++++++---------------------- Train.cpp | 2 +- 5 files changed, 101 insertions(+), 86 deletions(-) diff --git a/DynObj.cpp b/DynObj.cpp index 4dc5c35e..8ce3b99e 100644 --- a/DynObj.cpp +++ b/DynObj.cpp @@ -4597,16 +4597,19 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName, m_powertrainsounds.motor.m_amplitudefactor /= amplitudedivisor; } - else if( token == "ventilator:" ) { + else if( token == "inverter:" ) { + // plik z dzwiekiem wentylatora, mnozniki i ofsety amp. i czest. + m_powertrainsounds.inverter.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency ); + m_powertrainsounds.inverter.owner( this ); + } + + else if( token == "ventilator:" ) { // plik z dzwiekiem wentylatora, mnozniki i ofsety amp. i czest. m_powertrainsounds.rsWentylator.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency ); m_powertrainsounds.rsWentylator.owner( this ); - if( ( MoverParameters->EngineType == ElectricSeriesMotor ) - || ( MoverParameters->EngineType == ElectricInductionMotor ) ) { - m_powertrainsounds.rsWentylator.m_amplitudefactor /= MoverParameters->RVentnmax; - m_powertrainsounds.rsWentylator.m_frequencyfactor /= MoverParameters->RVentnmax; - } + m_powertrainsounds.rsWentylator.m_amplitudefactor /= MoverParameters->RVentnmax; + m_powertrainsounds.rsWentylator.m_frequencyfactor /= MoverParameters->RVentnmax; } else if( ( token == "transmission:" ) @@ -5779,7 +5782,34 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub if( motor_volume < 0.05 ) { motor.stop(); } + // inverter sounds + if( Vehicle.EngineType == ElectricInductionMotor ) { + if( Vehicle.InverterFrequency > 0.1 ) { + volume = inverter.m_amplitudeoffset + inverter.m_amplitudefactor * std::sqrt( std::fabs( Vehicle.dizel_fill ) ); + + inverter + .pitch( inverter.m_frequencyoffset + inverter.m_frequencyfactor * Vehicle.InverterFrequency ) + .gain( volume ) + .play( sound_flags::exclusive | sound_flags::looping ); + } + else { + inverter.stop(); + } + } + // ventillator sounds + if( Vehicle.RventRot > 0.1 ) { + + rsWentylator + .pitch( rsWentylator.m_frequencyoffset + rsWentylator.m_frequencyfactor * Vehicle.RventRot ) + .gain( rsWentylator.m_amplitudeoffset + rsWentylator.m_amplitudefactor * Vehicle.RventRot ) + .play( sound_flags::exclusive | sound_flags::looping ); + } + else { + // ...otherwise shut down the sound + rsWentylator.stop(); + } + // relay sounds auto const soundflags { Vehicle.SoundFlag }; if( TestFlag( soundflags, sound::relay ) ) { // przekaznik - gdy bezpiecznik, automatyczny rozruch itp @@ -5789,7 +5819,7 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub .pitch( true == motor_shuntfield.is_combined() ? Vehicle.ScndCtrlActualPos * 0.01f : - motor_shuntfield.m_frequencyoffset + 1.f * motor_shuntfield.m_frequencyfactor ) + motor_shuntfield.m_frequencyoffset + motor_shuntfield.m_frequencyfactor * 1.f ) .gain( motor_shuntfield.m_amplitudeoffset + ( true == TestFlag( soundflags, sound::loud ) ? @@ -5813,7 +5843,7 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub .pitch( true == motor_relay.is_combined() ? Vehicle.MainCtrlActualPos * 0.01f : - motor_relay.m_frequencyoffset + 1.f * motor_relay.m_frequencyfactor ) + motor_relay.m_frequencyoffset + motor_relay.m_frequencyfactor * 1.f ) .gain( motor_relay.m_amplitudeoffset + ( true == TestFlag( soundflags, sound::loud ) ? @@ -5824,32 +5854,11 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub } } - if( ( Vehicle.EngineType == ElectricSeriesMotor ) - || ( Vehicle.EngineType == ElectricInductionMotor ) ) { - - if( Vehicle.RventRot > 0.1 ) { - // play ventilator sound if the ventilators are rotating fast enough... - volume = ( - Vehicle.EngineType == ElectricInductionMotor ? - rsWentylator.m_amplitudefactor * std::sqrt( std::fabs( Vehicle.dizel_fill ) ) + rsWentylator.m_amplitudeoffset : - rsWentylator.m_amplitudefactor * Vehicle.RventRot + rsWentylator.m_amplitudeoffset ); - - rsWentylator - .pitch( rsWentylator.m_frequencyfactor * Vehicle.RventRot + rsWentylator.m_frequencyoffset ) - .gain( volume ) - .play( sound_flags::exclusive | sound_flags::looping ); - } - else { - // ...otherwise shut down the sound - rsWentylator.stop(); - } - } - if( Vehicle.TrainType == dt_ET40 ) { if( Vehicle.Vel > 0.1 ) { transmission - .pitch( transmission.m_frequencyfactor * ( Vehicle.Vel ) + transmission.m_frequencyoffset ) - .gain( transmission.m_amplitudefactor * ( Vehicle.Vel ) + transmission.m_amplitudeoffset ) + .pitch( transmission.m_frequencyoffset + transmission.m_frequencyfactor * Vehicle.Vel ) + .gain( transmission.m_amplitudeoffset + transmission.m_amplitudefactor * Vehicle.Vel ) .play( sound_flags::exclusive | sound_flags::looping ); } else { diff --git a/DynObj.h b/DynObj.h index 16c644c2..9a3305bd 100644 --- a/DynObj.h +++ b/DynObj.h @@ -284,6 +284,7 @@ private: }; struct powertrain_sounds { + sound_source inverter { sound_placement::engine }; sound_source motor { sound_placement::external }; // generally traction motor double motor_volume { 0.0 }; // MC: pomocnicze zeby gladziej silnik buczal float motor_momentum { 0.f }; // recent change in motor revolutions diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 7a29e8bf..00cbef41 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -816,6 +816,7 @@ public: double eimc[26]; bool EIMCLogForce; // static std::vector const eimc_labels; + double InverterFrequency { 0.0 }; // current frequency of power inverters /*-dla wagonow*/ double MaxLoad = 0.0; /*masa w T lub ilosc w sztukach - ladownosc*/ std::string LoadAccepted; std::string LoadQuantity; /*co moze byc zaladowane, jednostki miary*/ diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 21a44af8..9869a246 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -4239,36 +4239,13 @@ double TMoverParameters::TractionForce(double dt) */ // hunter-091012: przeniesione z if ActiveDir<>0 (zeby po zejsciu z kierunku dalej spadala predkosc wentylatorow) // wentylatory rozruchowe - // TODO: move this to update, it doesn't exactly have much to do with traction - if( true == Mains ) { + // TBD, TODO: move this to update, it doesn't exactly have much to do with traction + switch( EngineType ) { - switch( EngineType ) { - case ElectricInductionMotor: { - // TBD, TODO: currently ignores RVentType, fix this? - auto const tmpV { std::abs( eimv[ eimv_fp ] ) }; - - if( ( RlistSize > 0 ) - && ( ( std::abs( eimv[ eimv_If ] ) > 1.0 ) - || ( tmpV > 0.1 ) ) ) { - - int i = 0; - while( ( i < RlistSize - 1 ) - && ( DElist[ i + 1 ].RPM < tmpV ) ) { - ++i; - } - RventRot = - ( tmpV - DElist[ i ].RPM ) - / std::max( 1.0, ( DElist[ i + 1 ].RPM - DElist[ i ].RPM ) ) - * ( DElist[ i + 1 ].GenPower - DElist[ i ].GenPower ) - + DElist[ i ].GenPower; - } - else { - RventRot *= std::max( 0.0, 1.0 - RVentSpeed * dt ); - } - break; - } - case ElectricSeriesMotor: { + case ElectricSeriesMotor: { + if( true == Mains ) { switch( RVentType ) { + case 1: { // manual if( ( ActiveDir != 0 ) && ( RList[ MainCtrlActualPos ].R > RVentCutOff ) ) { @@ -4279,6 +4256,7 @@ double TMoverParameters::TractionForce(double dt) } break; } + case 2: { // automatic if( ( std::abs( Itot ) > RVentMinI ) && ( RList[ MainCtrlActualPos ].R > RVentCutOff ) ) { @@ -4293,26 +4271,32 @@ double TMoverParameters::TractionForce(double dt) } break; } + default: { break; } } // rventtype + } // mains + else { + RventRot *= std::max( 0.0, 1.0 - RVentSpeed * dt ); } - case DieselElectric: { + } + + case DieselElectric: { + if( true == Mains ) { // TBD, TODO: currently ignores RVentType, fix this? RventRot += clamp( DElist[ MainCtrlPos ].RPM - RventRot, -100.0, 50.0 ) * dt; - break; } - case DieselEngine: - default: { - break; + else { + RventRot *= std::max( 0.0, 1.0 - RVentSpeed * dt ); } - } // enginetype + break; + } + + default: { + break; + } } - else { - RventRot *= std::max( 0.0, 1.0 - RVentSpeed * dt ); - } - RventRot = std::max( 0.0, RventRot ); if (ActiveDir != 0) switch (EngineType) @@ -4715,8 +4699,7 @@ double TMoverParameters::TractionForce(double dt) MainSwitch( false, ( TrainType == dt_EZT ? range::unit : range::local ) ); // TODO: check whether we need to send this EMU-wide } } - if ((Mains)) - { + if( true == Mains ) { dtrans = Hamulec->GetEDBCP(); if (((DoorLeftOpened) || (DoorRightOpened))) @@ -4884,35 +4867,56 @@ double TMoverParameters::TractionForce(double dt) Itot = eimv[eimv_Ipoj] * (0.01 + Min0R(0.99, 0.99 - Vadd)); EnginePower = abs(eimv[eimv_Ic] * eimv[eimv_U] * NPoweredAxles) / 1000; + // power inverters + auto const tmpV { std::abs( eimv[ eimv_fp ] ) }; + + if( ( RlistSize > 0 ) + && ( ( std::abs( eimv[ eimv_If ] ) > 1.0 ) + || ( tmpV > 0.1 ) ) ) { + + int i = 0; + while( ( i < RlistSize - 1 ) + && ( DElist[ i + 1 ].RPM < tmpV ) ) { + ++i; + } + InverterFrequency = + ( tmpV - DElist[ i ].RPM ) + / std::max( 1.0, ( DElist[ i + 1 ].RPM - DElist[ i ].RPM ) ) + * ( DElist[ i + 1 ].GenPower - DElist[ i ].GenPower ) + + DElist[ i ].GenPower; + } + else { + InverterFrequency = 0.0; + } Mm = eimv[eimv_M] * DirAbsolute; Mw = Mm * Transmision.Ratio; Fw = Mw * 2.0 / WheelDiameter; Ft = Fw * NPoweredAxles; eimv[eimv_Fr] = DirAbsolute * Ft / 1000; - // RventRot; - } + } // mains else { - Im = 0; - Mm = 0; - Mw = 0; - Fw = 0; - Ft = 0; - Itot = 0; - dizel_fill = 0; - EnginePower = 0; + Im = 0.0; + Mm = 0.0; + Mw = 0.0; + Fw = 0.0; + Ft = 0.0; + Itot = 0.0; + dizel_fill = 0.0; + EnginePower = 0.0; { for (int i = 0; i < 21; ++i) - eimv[i] = 0; + eimv[i] = 0.0; } - Hamulec->SetED(0); - RventRot = 0.0; //(Hamulec as TLSt).SetLBP(LocBrakePress); + Hamulec->SetED(0.0); + InverterFrequency = 0.0; //(Hamulec as TLSt).SetLBP(LocBrakePress); } break; } // ElectricInductionMotor + case None: - { + default: { break; } } // case EngineType diff --git a/Train.cpp b/Train.cpp index 4b9fb212..3a164ca9 100644 --- a/Train.cpp +++ b/Train.cpp @@ -4136,7 +4136,7 @@ bool TTrain::Update( double const Deltatime ) else // wylaczone { btLampkaCzuwaka.Turn( false ); - btLampkaSHP.Turn( true ); + btLampkaSHP.Turn( false ); } // przelaczniki // ABu030405 obsluga lampki uniwersalnej: