mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
minor sound refactoring
This commit is contained in:
34
DynObj.cpp
34
DynObj.cpp
@@ -3623,34 +3623,22 @@ void TDynamicObject::RenderSounds() {
|
||||
|
||||
// frequency calculation
|
||||
auto normalizer { 1.f };
|
||||
// for combined sounds normalize frequency to 0-1 range
|
||||
// for combined sound engine we calculate sound point in rpm, to make .mmd files setup easier
|
||||
switch( MoverParameters->EngineType ) {
|
||||
case DieselElectric: {
|
||||
if( true == sConverter.is_combined() ) {
|
||||
normalizer = MoverParameters->DElist[ MoverParameters->MainCtrlPosNo ].RPM / 60;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DieselEngine: {
|
||||
if( true == rsSilnik.is_combined() ) {
|
||||
normalizer = MoverParameters->dizel_nmax;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ElectricInductionMotor: {
|
||||
if( true == rsSilnik.is_combined() ) {
|
||||
// TODO: implement normalization/a way to calculate max expected engine rpm
|
||||
normalizer = 60.f * 0.01f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if( true == rsSilnik.is_combined() ) {
|
||||
normalizer = MoverParameters->nmax;
|
||||
normalizer = 60.f * 0.01f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
frequency = rsSilnik.m_frequencyfactor * std::abs( MoverParameters->enrot ) / std::max( 1.f, normalizer ) + rsSilnik.m_frequencyoffset;
|
||||
frequency = rsSilnik.m_frequencyfactor * std::abs( MoverParameters->enrot ) * normalizer + rsSilnik.m_frequencyoffset;
|
||||
if( MoverParameters->EngineType == Dumb ) {
|
||||
frequency -= 0.2 * MoverParameters->EnginePower / ( 1 + MoverParameters->Power * 1000 );
|
||||
}
|
||||
@@ -4147,10 +4135,11 @@ void TDynamicObject::RenderSounds() {
|
||||
// szum w czasie jazdy
|
||||
if( ( GetVelocity() > 0.5 )
|
||||
&& ( // compound test whether the vehicle belongs to user-driven consist (as these don't emit outer noise in cab view)
|
||||
true == FreeFlyModeFlag ? true : // in external view all vehicles emit outer noise
|
||||
FreeFlyModeFlag ? true : // in external view all vehicles emit outer noise
|
||||
// Global::pWorld->train() == nullptr ? true : // (can skip this check, with no player train the external view is a given)
|
||||
ctOwner == nullptr ? true : // standalone vehicle, can't be part of user-driven train
|
||||
ctOwner != Global::pWorld->train()->Dynamic()->ctOwner ? true : // confirmed isn't a part of the user-driven train
|
||||
Global::CabWindowOpen ? true : // sticking head out we get to hear outer noise
|
||||
false ) ) {
|
||||
|
||||
volume = rsOuterNoise.m_amplitudefactor * MoverParameters->Vel + rsOuterNoise.m_amplitudeoffset;
|
||||
@@ -5076,15 +5065,16 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
|
||||
rsSilnik.m_amplitudefactor /= amplitudedivisor;
|
||||
}
|
||||
|
||||
else if( ( token == "ventilator:" )
|
||||
&& ( ( MoverParameters->EngineType == ElectricSeriesMotor )
|
||||
|| ( MoverParameters->EngineType == ElectricInductionMotor ) ) ) {
|
||||
else if( token == "ventilator:" ) {
|
||||
// plik z dzwiekiem wentylatora, mnozniki i ofsety amp. i czest.
|
||||
rsWentylator.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency );
|
||||
rsWentylator.owner( this );
|
||||
|
||||
rsWentylator.m_amplitudefactor /= MoverParameters->RVentnmax;
|
||||
rsWentylator.m_frequencyfactor /= MoverParameters->RVentnmax;
|
||||
if( ( MoverParameters->EngineType == ElectricSeriesMotor )
|
||||
|| ( MoverParameters->EngineType == ElectricInductionMotor ) ) {
|
||||
rsWentylator.m_amplitudefactor /= MoverParameters->RVentnmax;
|
||||
rsWentylator.m_frequencyfactor /= MoverParameters->RVentnmax;
|
||||
}
|
||||
}
|
||||
|
||||
else if( ( token == "transmission:" )
|
||||
|
||||
@@ -4197,7 +4197,7 @@ double TMoverParameters::CouplerForce(int CouplerN, double dt)
|
||||
// *************************************************************************************************
|
||||
double TMoverParameters::TractionForce(double dt)
|
||||
{
|
||||
double PosRatio, dmoment, dtrans, tmp, tmpV;
|
||||
double PosRatio, dmoment, dtrans, tmp;// , tmpV;
|
||||
int i;
|
||||
|
||||
Ft = 0;
|
||||
@@ -4244,38 +4244,82 @@ double TMoverParameters::TractionForce(double dt)
|
||||
// eAngle = Pirazy2 - eAngle; <- ABu: a nie czasem tak, jak nizej?
|
||||
eAngle -= M_PI * 2.0;
|
||||
*/
|
||||
// hunter-091012: przeniesione z if ActiveDir<>0 (zeby po zejsciu z kierunku dalej spadala
|
||||
// predkosc wentylatorow)
|
||||
if (EngineType == ElectricSeriesMotor)
|
||||
{
|
||||
switch (RVentType) // wentylatory rozruchowe}
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if ((ActiveDir != 0) && (RList[MainCtrlActualPos].R > RVentCutOff))
|
||||
RventRot += (RVentnmax - RventRot) * RVentSpeed * dt;
|
||||
else
|
||||
RventRot *= (1.0 - RVentSpeed * dt);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if ((abs(Itot) > RVentMinI) && (RList[MainCtrlActualPos].R > RVentCutOff))
|
||||
RventRot +=
|
||||
(RVentnmax * abs(Itot) / (ImaxLo * RList[MainCtrlActualPos].Bn) - RventRot) *
|
||||
RVentSpeed * dt;
|
||||
else if ((DynamicBrakeType == dbrake_automatic) && (DynamicBrakeFlag))
|
||||
RventRot += (RVentnmax * Im / ImaxLo - RventRot) * RVentSpeed * dt;
|
||||
else
|
||||
{
|
||||
RventRot *= (1.0 - RVentSpeed * dt);
|
||||
if (RventRot < 0.1)
|
||||
RventRot = 0;
|
||||
// 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 ) {
|
||||
|
||||
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 ) ) ) {
|
||||
|
||||
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;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ElectricSeriesMotor: {
|
||||
switch( RVentType ) {
|
||||
case 1: { // manual
|
||||
if( ( ActiveDir != 0 )
|
||||
&& ( RList[ MainCtrlActualPos ].R > RVentCutOff ) ) {
|
||||
RventRot += ( RVentnmax - RventRot ) * RVentSpeed * dt;
|
||||
}
|
||||
else {
|
||||
RventRot *= std::max( 0.0, 1.0 - RVentSpeed * dt );
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: { // automatic
|
||||
if( ( std::abs( Itot ) > RVentMinI )
|
||||
&& ( RList[ MainCtrlActualPos ].R > RVentCutOff ) ) {
|
||||
RventRot += ( RVentnmax * abs( Itot ) / ( ImaxLo * RList[ MainCtrlActualPos ].Bn ) - RventRot ) * RVentSpeed * dt;
|
||||
}
|
||||
else if( ( DynamicBrakeType == dbrake_automatic )
|
||||
&& ( true == DynamicBrakeFlag ) ) {
|
||||
RventRot += ( RVentnmax * Im / ImaxLo - RventRot ) * RVentSpeed * dt;
|
||||
}
|
||||
else {
|
||||
RventRot *= std::max( 0.0, 1.0 - RVentSpeed * dt );
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
} // rventtype
|
||||
}
|
||||
case DieselElectric: {
|
||||
// TBD, TODO: currently ignores RVentType, fix this?
|
||||
RventRot += clamp( DElist[ MainCtrlPos ].RPM - RventRot, -100.0, 50.0 ) * dt;
|
||||
break;
|
||||
}
|
||||
case DieselEngine:
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
} // enginetype
|
||||
}
|
||||
else {
|
||||
RventRot *= std::max( 0.0, 1.0 - RVentSpeed * dt );
|
||||
}
|
||||
RventRot = std::max( 0.0, RventRot );
|
||||
|
||||
if (ActiveDir != 0)
|
||||
switch (EngineType)
|
||||
@@ -4397,7 +4441,7 @@ double TMoverParameters::TractionForce(double dt)
|
||||
case DieselElectric: // youBy
|
||||
{
|
||||
// tmpV:=V*CabNo*ActiveDir;
|
||||
tmpV = nrot * Pirazy2 * 0.5 * WheelDiameter * DirAbsolute; //*CabNo*ActiveDir;
|
||||
auto const tmpV { nrot * Pirazy2 * 0.5 * WheelDiameter * DirAbsolute }; //*CabNo*ActiveDir;
|
||||
// jazda manewrowa
|
||||
if (ShuntMode)
|
||||
{
|
||||
@@ -4665,7 +4709,6 @@ double TMoverParameters::TractionForce(double dt)
|
||||
MainSwitch( false, ( TrainType == dt_EZT ? range::unit : range::local ) ); // TODO: check whether we need to send this EMU-wide
|
||||
}
|
||||
}
|
||||
tmpV = abs(nrot) * (PI * WheelDiameter) * 3.6; //*DirAbsolute*eimc[eimc_s_p]; - do przemyslenia dzialanie pp
|
||||
if ((Mains))
|
||||
{
|
||||
|
||||
@@ -4835,20 +4878,6 @@ 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;
|
||||
tmpV = eimv[eimv_fp];
|
||||
if (((abs(eimv[eimv_If]) > 1) || (abs(tmpV) > 0.1)) && (RlistSize > 0))
|
||||
{
|
||||
i = 0;
|
||||
while ((i < RlistSize - 1) && (DElist[i + 1].RPM < abs(tmpV)))
|
||||
i++;
|
||||
RventRot =
|
||||
( std::abs( 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 = 0;
|
||||
|
||||
Mm = eimv[eimv_M] * DirAbsolute;
|
||||
Mw = Mm * Transmision.Ratio;
|
||||
|
||||
@@ -5285,6 +5285,7 @@ TTrain::update_sounds( double const Deltatime ) {
|
||||
|
||||
// szum w czasie jazdy
|
||||
if( ( false == FreeFlyModeFlag )
|
||||
&& ( false == Global::CabWindowOpen )
|
||||
&& ( DynamicObject->GetVelocity() > 0.5 ) ) {
|
||||
|
||||
volume = rsRunningNoise.m_amplitudefactor * mvOccupied->Vel + rsRunningNoise.m_amplitudeoffset;
|
||||
|
||||
18
sound.cpp
18
sound.cpp
@@ -331,7 +331,7 @@ void
|
||||
sound_source::play_combined() {
|
||||
// combined sound consists of table od samples, each sample associated with certain range of values of controlling variable
|
||||
// current value of the controlling variable is passed to the source with pitch() call
|
||||
auto const soundpoint { clamp( m_properties.pitch * 100.f, 0.f, 99.f ) };
|
||||
auto const soundpoint { compute_combined_point() };
|
||||
for( std::uint32_t idx = 0; idx < m_soundchunks.size(); ++idx ) {
|
||||
|
||||
auto const &soundchunk { m_soundchunks[ idx ] };
|
||||
@@ -376,6 +376,18 @@ sound_source::play_combined() {
|
||||
}
|
||||
}
|
||||
|
||||
// calculates requested sound point, used to select specific sample from the sample table
|
||||
float
|
||||
sound_source::compute_combined_point() const {
|
||||
|
||||
return (
|
||||
m_properties.pitch < 1.1f ?
|
||||
// most sounds use 0-1 value range, we clamp these to 0-99 to allow more intuitive sound definition in .mmd files
|
||||
clamp( m_properties.pitch, 0.f, 0.99f ) :
|
||||
std::max( 0.f, m_properties.pitch )
|
||||
) * 100.f;
|
||||
}
|
||||
|
||||
// stops currently active play commands controlled by this emitter
|
||||
void
|
||||
sound_source::stop( bool const Skipend ) {
|
||||
@@ -520,7 +532,7 @@ sound_source::update_combined( audio::openal_source &Source ) {
|
||||
|
||||
if( ( soundhandle & sound_id::chunk ) != 0 ) {
|
||||
// for sound chunks, test whether the chunk should still be active given current value of the controlling variable
|
||||
auto const soundpoint { clamp( m_properties.pitch * 100.f, 0.f, 99.f ) };
|
||||
auto const soundpoint { compute_combined_point() };
|
||||
auto const &soundchunk { m_soundchunks[ soundhandle ^ sound_id::chunk ] };
|
||||
if( ( soundpoint < soundchunk.second.fadein )
|
||||
|| ( soundpoint > soundchunk.second.fadeout ) ) {
|
||||
@@ -598,7 +610,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto const soundpoint { clamp( m_properties.pitch * 100.f, 0.f, 99.f ) };
|
||||
auto const soundpoint { compute_combined_point() };
|
||||
|
||||
// NOTE: direct access to implementation details ahead, kinda fugly
|
||||
auto const chunkindex { Chunk ^ sound_id::chunk };
|
||||
|
||||
Reference in New Issue
Block a user