mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-20 06:49:19 +02:00
dedicated power inverter sound
This commit is contained in:
71
DynObj.cpp
71
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 {
|
||||
|
||||
1
DynObj.h
1
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
|
||||
|
||||
@@ -816,6 +816,7 @@ public:
|
||||
double eimc[26];
|
||||
bool EIMCLogForce; //
|
||||
static std::vector<std::string> 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*/
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user