mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-23 15:39:19 +02:00
build 200108. sound start offset support, default coupler sound naming cleanup, minor bug fixes
This commit is contained in:
55
DynObj.cpp
55
DynObj.cpp
@@ -4206,8 +4206,9 @@ void TDynamicObject::RenderSounds() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// youBy: dzwiek ostrych lukow i ciasnych zwrotek
|
// youBy: dzwiek ostrych lukow i ciasnych zwrotek
|
||||||
if( ( ts.R * ts.R > 1 )
|
if( ( MoverParameters->Vel > 5.0 )
|
||||||
&& ( MoverParameters->Vel > 5.0 ) ) {
|
&& ( ts.R * ts.R > 1.0 )
|
||||||
|
&& ( std::abs( ts.R ) < 15000.0 ) ) {
|
||||||
// scale volume with curve radius and vehicle speed
|
// scale volume with curve radius and vehicle speed
|
||||||
volume =
|
volume =
|
||||||
std::abs( MoverParameters->AccN ) // * MoverParameters->AccN
|
std::abs( MoverParameters->AccN ) // * MoverParameters->AccN
|
||||||
@@ -5440,16 +5441,13 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
|
|||||||
|
|
||||||
else if( token == "outernoise:" ) {
|
else if( token == "outernoise:" ) {
|
||||||
// szum podczas jazdy:
|
// szum podczas jazdy:
|
||||||
sound_source noisetemplate { sound_placement::external, EU07_SOUND_RUNNINGNOISECUTOFFRANGE };
|
sound_source noisetemplate{ sound_placement::external, EU07_SOUND_RUNNINGNOISECUTOFFRANGE };
|
||||||
noisetemplate.deserialize( parser, sound_type::single, sound_parameters::amplitude | sound_parameters::frequency, MoverParameters->Vmax );
|
noisetemplate.deserialize( parser, sound_type::single, sound_parameters::amplitude | sound_parameters::frequency, MoverParameters->Vmax );
|
||||||
noisetemplate.owner( this );
|
noisetemplate.owner( this );
|
||||||
|
|
||||||
noisetemplate.m_amplitudefactor /= ( 1 + MoverParameters->Vmax );
|
noisetemplate.m_amplitudefactor /= ( 1 + MoverParameters->Vmax );
|
||||||
noisetemplate.m_frequencyfactor /= ( 1 + MoverParameters->Vmax );
|
noisetemplate.m_frequencyfactor /= ( 1 + MoverParameters->Vmax );
|
||||||
|
#ifdef EU07_SOUND_BOGIESOUNDS
|
||||||
m_outernoise = noisetemplate;
|
|
||||||
/*
|
|
||||||
// disabled until we can resolve sound interferences
|
|
||||||
if( true == m_bogiesounds.empty() ) {
|
if( true == m_bogiesounds.empty() ) {
|
||||||
// fallback for cases without specified noise locations, convert sound template to a single sound source
|
// fallback for cases without specified noise locations, convert sound template to a single sound source
|
||||||
m_bogiesounds.emplace_back( noisetemplate );
|
m_bogiesounds.emplace_back( noisetemplate );
|
||||||
@@ -5458,13 +5456,27 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
|
|||||||
// apply configuration to all defined bogies
|
// apply configuration to all defined bogies
|
||||||
for( auto &bogie : m_bogiesounds ) {
|
for( auto &bogie : m_bogiesounds ) {
|
||||||
// combine potential x- and y-axis offsets of the sound template with z-axis offsets of individual motors
|
// combine potential x- and y-axis offsets of the sound template with z-axis offsets of individual motors
|
||||||
auto bogieoffset { noisetemplate.offset() };
|
auto bogieoffset{ noisetemplate.offset() };
|
||||||
bogieoffset.z = bogie.offset().z;
|
bogieoffset.z = bogie.offset().z;
|
||||||
bogie = noisetemplate;
|
bogie = noisetemplate;
|
||||||
bogie.offset( bogieoffset );
|
bogie.offset( bogieoffset );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
// apply randomized playback start offset for each bogie, to reduce potential reverb with identical nearby sources
|
||||||
|
auto bogieidx( 0 );
|
||||||
|
for( auto &bogie : m_bogiesounds ) {
|
||||||
|
bogie.start( (
|
||||||
|
bogieidx % 2 ?
|
||||||
|
Random( 0.0, 30.0 ) :
|
||||||
|
Random( 50.0, 80.0 ) )
|
||||||
|
* 0.01 );
|
||||||
|
++bogieidx;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
m_outernoise = noisetemplate;
|
||||||
|
// apply randomized playback start offset, to reduce potential reverb with identical nearby sources
|
||||||
|
m_outernoise.start( Random( 0.0, 80.0 ) * 0.01 );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
else if( token == "wheelflat:" ) {
|
else if( token == "wheelflat:" ) {
|
||||||
@@ -5791,46 +5803,46 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
|
|||||||
if( MoverParameters->Power > 0 ) {
|
if( MoverParameters->Power > 0 ) {
|
||||||
if( true == m_powertrainsounds.dsbWejscie_na_bezoporow.empty() ) {
|
if( true == m_powertrainsounds.dsbWejscie_na_bezoporow.empty() ) {
|
||||||
// hunter-111211: domyslne, gdy brak
|
// hunter-111211: domyslne, gdy brak
|
||||||
m_powertrainsounds.dsbWejscie_na_bezoporow.deserialize( "wejscie_na_bezoporow.wav", sound_type::single );
|
m_powertrainsounds.dsbWejscie_na_bezoporow.deserialize( "wejscie_na_bezoporow", sound_type::single );
|
||||||
m_powertrainsounds.dsbWejscie_na_bezoporow.owner( this );
|
m_powertrainsounds.dsbWejscie_na_bezoporow.owner( this );
|
||||||
}
|
}
|
||||||
if( true == m_powertrainsounds.motor_parallel.empty() ) {
|
if( true == m_powertrainsounds.motor_parallel.empty() ) {
|
||||||
m_powertrainsounds.motor_parallel.deserialize( "wescie_na_drugi_uklad.wav", sound_type::single );
|
m_powertrainsounds.motor_parallel.deserialize( "wescie_na_drugi_uklad", sound_type::single );
|
||||||
m_powertrainsounds.motor_parallel.owner( this );
|
m_powertrainsounds.motor_parallel.owner( this );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// braking sounds
|
// braking sounds
|
||||||
if( true == rsUnbrake.empty() ) {
|
if( true == rsUnbrake.empty() ) {
|
||||||
rsUnbrake.deserialize( "[1007]estluz.wav", sound_type::single );
|
rsUnbrake.deserialize( "[1007]estluz", sound_type::single );
|
||||||
rsUnbrake.owner( this );
|
rsUnbrake.owner( this );
|
||||||
}
|
}
|
||||||
// couplers
|
// couplers
|
||||||
for( auto &couplersounds : m_couplersounds ) {
|
for( auto &couplersounds : m_couplersounds ) {
|
||||||
if( true == couplersounds.dsbCouplerAttach.empty() ) {
|
if( true == couplersounds.dsbCouplerAttach.empty() ) {
|
||||||
couplersounds.dsbCouplerAttach.deserialize( "couplerattach.wav", sound_type::single );
|
couplersounds.dsbCouplerAttach.deserialize( "couplerattach_default", sound_type::single );
|
||||||
couplersounds.dsbCouplerAttach.owner( this );
|
couplersounds.dsbCouplerAttach.owner( this );
|
||||||
}
|
}
|
||||||
if( true == couplersounds.dsbCouplerDetach.empty() ) {
|
if( true == couplersounds.dsbCouplerDetach.empty() ) {
|
||||||
couplersounds.dsbCouplerDetach.deserialize( "couplerdetach.wav", sound_type::single );
|
couplersounds.dsbCouplerDetach.deserialize( "couplerdetach_default", sound_type::single );
|
||||||
couplersounds.dsbCouplerDetach.owner( this );
|
couplersounds.dsbCouplerDetach.owner( this );
|
||||||
}
|
}
|
||||||
if( true == couplersounds.dsbCouplerStretch.empty() ) {
|
if( true == couplersounds.dsbCouplerStretch.empty() ) {
|
||||||
couplersounds.dsbCouplerStretch.deserialize( "en57_couplerstretch.wav", sound_type::single );
|
couplersounds.dsbCouplerStretch.deserialize( "couplerstretch_default", sound_type::single );
|
||||||
couplersounds.dsbCouplerStretch.owner( this );
|
couplersounds.dsbCouplerStretch.owner( this );
|
||||||
}
|
}
|
||||||
if( true == couplersounds.dsbBufferClamp.empty() ) {
|
if( true == couplersounds.dsbBufferClamp.empty() ) {
|
||||||
couplersounds.dsbBufferClamp.deserialize( "en57_bufferclamp.wav", sound_type::single );
|
couplersounds.dsbBufferClamp.deserialize( "bufferclamp_default", sound_type::single );
|
||||||
couplersounds.dsbBufferClamp.owner( this );
|
couplersounds.dsbBufferClamp.owner( this );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// other sounds
|
// other sounds
|
||||||
if( true == m_wheelflat.empty() ) {
|
if( true == m_wheelflat.empty() ) {
|
||||||
m_wheelflat.deserialize( "lomotpodkucia.wav 0.23 0.0", sound_type::single, sound_parameters::frequency );
|
m_wheelflat.deserialize( "lomotpodkucia 0.23 0.0", sound_type::single, sound_parameters::frequency );
|
||||||
m_wheelflat.owner( this );
|
m_wheelflat.owner( this );
|
||||||
}
|
}
|
||||||
if( true == rscurve.empty() ) {
|
if( true == rscurve.empty() ) {
|
||||||
// hunter-111211: domyslne, gdy brak
|
// hunter-111211: domyslne, gdy brak
|
||||||
rscurve.deserialize( "curve.wav", sound_type::single );
|
rscurve.deserialize( "curve", sound_type::single );
|
||||||
rscurve.owner( this );
|
rscurve.owner( this );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6402,15 +6414,16 @@ void TDynamicObject::DestinationSet(std::string to, std::string numer) {
|
|||||||
|
|
||||||
std::string signrequest {
|
std::string signrequest {
|
||||||
"make:"
|
"make:"
|
||||||
+ DestinationSign.script + "?"
|
+ DestinationSign.script
|
||||||
|
+ "?"
|
||||||
// timetable include
|
// timetable include
|
||||||
+ "$timetable=" + (
|
+ "$timetable=" + (
|
||||||
ctOwner == nullptr ?
|
ctOwner == nullptr ?
|
||||||
MoverParameters->Name : // leading vehicle, can point to it directly
|
MoverParameters->Name : // leading vehicle, can point to it directly
|
||||||
ctOwner->Vehicle()->MoverParameters->Name ) + "&" // owned vehicle, safer to point to owner as carriages can have identical names
|
ctOwner->Vehicle()->MoverParameters->Name ) // owned vehicle, safer to point to owner as carriages can have identical names
|
||||||
// basic instancing string
|
// basic instancing string
|
||||||
// NOTE: underscore doesn't have any magic meaning for the time being, it's just less likely to conflict with regular dictionary keys
|
// NOTE: underscore doesn't have any magic meaning for the time being, it's just less likely to conflict with regular dictionary keys
|
||||||
+ "_id1=" + (
|
+ "&_id1=" + (
|
||||||
ctOwner != nullptr ? ctOwner->TrainName() :
|
ctOwner != nullptr ? ctOwner->TrainName() :
|
||||||
Mechanik != nullptr ? Mechanik->TrainName() :
|
Mechanik != nullptr ? Mechanik->TrainName() :
|
||||||
"none" ) }; // shouldn't get here but, eh
|
"none" ) }; // shouldn't get here but, eh
|
||||||
|
|||||||
2
DynObj.h
2
DynObj.h
@@ -21,6 +21,8 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
#include "Spring.h"
|
#include "Spring.h"
|
||||||
|
|
||||||
|
#define EU07_SOUND_BOGIESOUNDS
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -4704,7 +4704,7 @@ double TMoverParameters::CouplerForce( int const End, double dt ) {
|
|||||||
// potentially generate sounds on clash or stretch
|
// potentially generate sounds on clash or stretch
|
||||||
if( ( newdistance < 0.0 )
|
if( ( newdistance < 0.0 )
|
||||||
&& ( coupler.Dist > newdistance )
|
&& ( coupler.Dist > newdistance )
|
||||||
&& ( dV < -0.5 ) ) {
|
&& ( dV < -0.1 ) ) {
|
||||||
// 090503: dzwieki pracy zderzakow
|
// 090503: dzwieki pracy zderzakow
|
||||||
SetFlag(
|
SetFlag(
|
||||||
coupler.sounds,
|
coupler.sounds,
|
||||||
|
|||||||
@@ -180,11 +180,26 @@ openal_source::bind( sound_source *Controller, uint32_sequence Sounds, Iterator_
|
|||||||
auto const &buffer { audio::renderer.buffer( bufferhandle ) };
|
auto const &buffer { audio::renderer.buffer( bufferhandle ) };
|
||||||
buffers.emplace_back( buffer.id ); } );
|
buffers.emplace_back( buffer.id ); } );
|
||||||
|
|
||||||
|
is_multipart = ( buffers.size() > 1 );
|
||||||
|
|
||||||
if( id != audio::null_resource ) {
|
if( id != audio::null_resource ) {
|
||||||
::alSourceQueueBuffers( id, static_cast<ALsizei>( buffers.size() ), buffers.data() );
|
::alSourceQueueBuffers( id, static_cast<ALsizei>( buffers.size() ), buffers.data() );
|
||||||
::alSourceRewind( id );
|
::alSourceRewind( id );
|
||||||
|
// sound controller can potentially request playback to start from certain buffer point
|
||||||
|
if( controller->start() == 0.f ) {
|
||||||
|
// regular case with no offset, reset bound source just in case
|
||||||
|
::alSourcei( id, AL_SAMPLE_OFFSET, 0 );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// move playback start to specified point in 0-1 range
|
||||||
|
ALint buffersize;
|
||||||
|
::alGetBufferi( buffers.front(), AL_SIZE, &buffersize );
|
||||||
|
::alSourcei(
|
||||||
|
id,
|
||||||
|
AL_SAMPLE_OFFSET,
|
||||||
|
static_cast<ALint>( controller->start() * ( buffersize / sizeof( std::int16_t ) ) ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
is_multipart = ( buffers.size() > 1 );
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -743,6 +743,14 @@ driver_mode::OnKeyDown(int cKey) {
|
|||||||
// jeśli mielismy pojazd
|
// jeśli mielismy pojazd
|
||||||
if( simulation::Train->Dynamic()->Mechanik ) { // na skutek jakiegoś błędu może czasem zniknąć
|
if( simulation::Train->Dynamic()->Mechanik ) { // na skutek jakiegoś błędu może czasem zniknąć
|
||||||
auto const *currentvehicle { simulation::Train->Dynamic() };
|
auto const *currentvehicle { simulation::Train->Dynamic() };
|
||||||
|
auto const samevehicle { currentvehicle == targetvehicle };
|
||||||
|
|
||||||
|
if( samevehicle ) {
|
||||||
|
// we already control desired vehicle so don't overcomplicate things
|
||||||
|
InOutKey(); // do kabiny
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
auto const sameconsist {
|
auto const sameconsist {
|
||||||
( targetvehicle->ctOwner == currentvehicle->Mechanik )
|
( targetvehicle->ctOwner == currentvehicle->Mechanik )
|
||||||
|| ( targetvehicle->ctOwner == currentvehicle->ctOwner ) };
|
|| ( targetvehicle->ctOwner == currentvehicle->ctOwner ) };
|
||||||
|
|||||||
@@ -696,7 +696,7 @@ debug_panel::update_section_vehicle( std::vector<text_line> &Output ) {
|
|||||||
// acceleration
|
// acceleration
|
||||||
Acc,
|
Acc,
|
||||||
mover.AccN + 0.001f,
|
mover.AccN + 0.001f,
|
||||||
std::string( std::abs( mover.RunningShape.R ) > 10000.0 ? "~0" : to_string( mover.RunningShape.R, 0 ) ).c_str(),
|
std::string( std::abs( mover.RunningShape.R ) > 15000.0 ? "~0" : to_string( mover.RunningShape.R, 0 ) ).c_str(),
|
||||||
// velocity
|
// velocity
|
||||||
vehicle.GetVelocity(),
|
vehicle.GetVelocity(),
|
||||||
mover.DistCounter,
|
mover.DistCounter,
|
||||||
|
|||||||
@@ -193,6 +193,12 @@ sound_source::deserialize_mapping( cParser &Input ) {
|
|||||||
1.0f :
|
1.0f :
|
||||||
0.01f * static_cast<float>( Random( 100.0 - variation, 100.0 + variation ) ) );
|
0.01f * static_cast<float>( Random( 100.0 - variation, 100.0 + variation ) ) );
|
||||||
}
|
}
|
||||||
|
else if( key == "startoffset:" ) {
|
||||||
|
m_startoffset =
|
||||||
|
clamp(
|
||||||
|
Input.getToken<float>( false, "\n\r\t ,;" ),
|
||||||
|
0.0f, 1.0f );
|
||||||
|
}
|
||||||
else if( key.compare( 0, std::min<std::size_t>( key.size(), 5 ), "pitch" ) == 0 ) {
|
else if( key.compare( 0, std::min<std::size_t>( key.size(), 5 ), "pitch" ) == 0 ) {
|
||||||
// sound chunk pitch, defined with key pitchX where X = activation threshold
|
// sound chunk pitch, defined with key pitchX where X = activation threshold
|
||||||
auto const indexstart { key.find_first_of( "1234567890" ) };
|
auto const indexstart { key.find_first_of( "1234567890" ) };
|
||||||
|
|||||||
11
sound.h
11
sound.h
@@ -102,6 +102,11 @@ public:
|
|||||||
name( std::string Name );
|
name( std::string Name );
|
||||||
std::string const &
|
std::string const &
|
||||||
name() const;
|
name() const;
|
||||||
|
// playback starting point shift setter/getter
|
||||||
|
void
|
||||||
|
start( float const Offset );
|
||||||
|
float const &
|
||||||
|
start() const;
|
||||||
// returns true if there isn't any sound buffer associated with the object, false otherwise
|
// returns true if there isn't any sound buffer associated with the object, false otherwise
|
||||||
bool
|
bool
|
||||||
empty() const;
|
empty() const;
|
||||||
@@ -204,7 +209,8 @@ private:
|
|||||||
std::string m_name;
|
std::string m_name;
|
||||||
int m_flags {}; // requested playback parameters
|
int m_flags {}; // requested playback parameters
|
||||||
sound_properties m_properties; // current properties of the emitted sounds
|
sound_properties m_properties; // current properties of the emitted sounds
|
||||||
float m_pitchvariation {}; // emitter-specific shift in base pitch
|
float m_pitchvariation {}; // emitter-specific shift for base pitch
|
||||||
|
float m_startoffset {}; // emitter-specific shift for playback starting point
|
||||||
bool m_stop { false }; // indicates active sample instances should be terminated
|
bool m_stop { false }; // indicates active sample instances should be terminated
|
||||||
/*
|
/*
|
||||||
bool m_stopend { false }; // indicates active instances of optional ending sound should be terminated
|
bool m_stopend { false }; // indicates active instances of optional ending sound should be terminated
|
||||||
@@ -225,6 +231,9 @@ inline glm::vec3 const & sound_source::offset() const { return m_offset; }
|
|||||||
// sound source name setter/getter
|
// sound source name setter/getter
|
||||||
inline void sound_source::name( std::string Name ) { m_name = Name; }
|
inline void sound_source::name( std::string Name ) { m_name = Name; }
|
||||||
inline std::string const & sound_source::name() const { return m_name; }
|
inline std::string const & sound_source::name() const { return m_name; }
|
||||||
|
// playback starting point shift setter/getter
|
||||||
|
inline void sound_source::start( float const Offset ) { m_startoffset = Offset; }
|
||||||
|
inline float const & sound_source::start() const { return m_startoffset; }
|
||||||
|
|
||||||
// collection of sound sources present in the scene
|
// collection of sound sources present in the scene
|
||||||
class sound_table : public basic_table<sound_source> {
|
class sound_table : public basic_table<sound_source> {
|
||||||
|
|||||||
Reference in New Issue
Block a user