16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 10:29:19 +02:00

sound state tracking fixes, uart toggle input command selection fix

This commit is contained in:
tmj-fstate
2018-02-17 03:42:07 +01:00
parent 98b82636a8
commit e5967f72e0
3 changed files with 49 additions and 50 deletions

View File

@@ -453,8 +453,8 @@ sound_source::stop( bool const Skipend ) {
if( ( false == Skipend ) if( ( false == Skipend )
&& ( sound( sound_id::end ).buffer != null_handle ) && ( sound( sound_id::end ).buffer != null_handle )
&& ( sound( sound_id::end ).buffer != sound( sound_id::main ).buffer ) // end == main can happen in malformed legacy cases /* && ( sound( sound_id::end ).buffer != sound( sound_id::main ).buffer ) */ // end == main can happen in malformed legacy cases
/* && ( sound( sound_id::end ).playing == 0 ) */ ) { /* && ( sound( sound_id::end ).playing == 0 ) */ ) {
// spawn potentially defined sound end sample, if the emitter is currently active // spawn potentially defined sound end sample, if the emitter is currently active
insert( sound_id::end ); insert( sound_id::end );
} }
@@ -481,19 +481,31 @@ sound_source::update_basic( audio::openal_source &Source ) {
if( true == Source.is_playing ) { if( true == Source.is_playing ) {
if( ( true == m_stop ) auto const soundhandle { Source.sounds[ Source.sound_index ] };
&& ( Source.sounds[ Source.sound_index ] != sound_id::end ) ) {
// kill the sound if stop was requested, unless it's sound bookend sample if( sound( sound_id::begin ).buffer != null_handle ) {
Source.stop(); // potentially a multipart sound
update_counter( Source.sounds[ Source.sound_index ], -1 ); // detect the moment when the sound moves from startup sample to the main
if( false == is_playing() ) { if( ( false == Source.is_looping )
m_stop = false; && ( soundhandle == sound_id::main ) ) {
// when it happens update active sample counters, and activate the looping
update_counter( sound_id::begin, -1 );
update_counter( soundhandle, 1 );
Source.loop( TestFlag( m_flags, sound_flags::looping ) );
} }
}
if( ( true == m_stop )
&& ( soundhandle != sound_id::end ) ) {
// kill the sound if stop was requested, unless it's sound bookend sample
update_counter( soundhandle, -1 );
Source.stop();
m_stop = is_playing(); // end the stop mode when all active sounds are dead
return; return;
} }
/* /*
if( ( true == m_stopend ) if( ( true == m_stopend )
&& ( Source.sounds[ Source.sound_index ] == sound_id::end ) ) { && ( soundhandle == sound_id::end ) ) {
// kill the sound if it's the bookend sample and stopping it was requested // kill the sound if it's the bookend sample and stopping it was requested
Source.stop(); Source.stop();
update_counter( sound_id::end, -1 ); update_counter( sound_id::end, -1 );
@@ -503,25 +515,13 @@ sound_source::update_basic( audio::openal_source &Source ) {
return; return;
} }
*/ */
if( sound( sound_id::begin ).buffer != null_handle ) {
// potentially a multipart sound
// detect the moment when the sound moves from startup sample to the main
auto const soundhandle { Source.sounds[ Source.sound_index ] };
if( ( false == Source.is_looping )
&& ( soundhandle == sound_id::main ) ) {
// when it happens update active sample counters, and activate the looping
update_counter( sound_id::begin, -1 );
update_counter( soundhandle, 1 );
Source.loop( true );
}
}
// check and update if needed current sound properties // check and update if needed current sound properties
update_location(); update_location();
update_soundproofing(); update_soundproofing();
Source.sync_with( m_properties ); Source.sync_with( m_properties );
if( Source.sync != sync_state::good ) { if( Source.sync != sync_state::good ) {
// if the sync went wrong we let the renderer kill its part of the emitter, and update our playcounter(s) to match // if the sync went wrong we let the renderer kill its part of the emitter, and update our playcounter(s) to match
update_counter( Source.sounds[ Source.sound_index ], -1 ); update_counter( soundhandle, -1 );
} }
} }
@@ -532,10 +532,9 @@ sound_source::update_basic( audio::openal_source &Source ) {
// the emitter wasn't yet started // the emitter wasn't yet started
auto const soundhandle { Source.sounds[ Source.sound_index ] }; auto const soundhandle { Source.sounds[ Source.sound_index ] };
// emitter initialization // emitter initialization
if( ( soundhandle == sound_id::main ) if( soundhandle == sound_id::main ) {
&& ( true == TestFlag( m_flags, sound_flags::looping ) ) ) {
// main sample can be optionally set to loop // main sample can be optionally set to loop
Source.loop( true ); Source.loop( TestFlag( m_flags, sound_flags::looping ) );
} }
Source.range( m_range ); Source.range( m_range );
Source.pitch( m_pitchvariation ); Source.pitch( m_pitchvariation );
@@ -569,6 +568,18 @@ sound_source::update_combined( audio::openal_source &Source ) {
auto const soundhandle { Source.sounds[ Source.sound_index ] }; auto const soundhandle { Source.sounds[ Source.sound_index ] };
if( sound( sound_id::begin ).buffer != null_handle ) {
// potentially a multipart sound
// detect the moment when the sound moves from startup sample to the main
if( ( false == Source.is_looping )
&& ( soundhandle == ( sound_id::chunk | 0 ) ) ) {
// when it happens update active sample counters, and activate the looping
update_counter( sound_id::begin, -1 );
update_counter( soundhandle, 1 );
Source.loop( true );
}
}
if( ( true == m_stop ) if( ( true == m_stop )
&& ( soundhandle != sound_id::end ) ) { && ( soundhandle != sound_id::end ) ) {
// kill the sound if stop was requested, unless it's sound bookend sample // kill the sound if stop was requested, unless it's sound bookend sample
@@ -581,7 +592,7 @@ sound_source::update_combined( audio::openal_source &Source ) {
} }
/* /*
if( ( true == m_stopend ) if( ( true == m_stopend )
&& ( Source.sounds[ Source.sound_index ] == sound_id::end ) ) { && ( soundhandle == sound_id::end ) ) {
// kill the sound if it's the bookend sample and stopping it was requested // kill the sound if it's the bookend sample and stopping it was requested
Source.stop(); Source.stop();
update_counter( sound_id::end, -1 ); update_counter( sound_id::end, -1 );
@@ -591,19 +602,6 @@ sound_source::update_combined( audio::openal_source &Source ) {
return; return;
} }
*/ */
if( sound( sound_id::begin ).buffer != null_handle ) {
// potentially a multipart sound
// detect the moment when the sound moves from startup sample to the main
auto const soundhandle { Source.sounds[ Source.sound_index ] };
if( ( false == Source.is_looping )
&& ( soundhandle == ( sound_id::chunk | 0 ) ) ) {
// when it happens update active sample counters, and activate the looping
update_counter( sound_id::begin, -1 );
update_counter( soundhandle, 1 );
Source.loop( true );
}
}
if( ( soundhandle & sound_id::chunk ) != 0 ) { if( ( soundhandle & sound_id::chunk ) != 0 ) {
// for sound chunks, test whether the chunk should still be active given current value of the controlling variable // for sound chunks, test whether the chunk should still be active given current value of the controlling variable
auto const soundpoint { compute_combined_point() }; auto const soundpoint { compute_combined_point() };
@@ -628,7 +626,7 @@ sound_source::update_combined( audio::openal_source &Source ) {
Source.sync_with( m_properties ); Source.sync_with( m_properties );
if( Source.sync != sync_state::good ) { if( Source.sync != sync_state::good ) {
// if the sync went wrong we let the renderer kill its part of the emitter, and update our playcounter(s) to match // if the sync went wrong we let the renderer kill its part of the emitter, and update our playcounter(s) to match
update_counter( Source.sounds[ Source.sound_index ], -1 ); update_counter( soundhandle, -1 );
} }
// ...and restore base properties // ...and restore base properties
m_properties = baseproperties; m_properties = baseproperties;
@@ -795,7 +793,7 @@ sound_source::empty() const {
bool bool
sound_source::is_playing( bool const Includesoundends ) const { sound_source::is_playing( bool const Includesoundends ) const {
auto isplaying { ( sound( sound_id::begin ).playing + sound( sound_id::main ).playing ) > 0 }; auto isplaying { ( sound( sound_id::begin ).playing > 0 ) || ( sound( sound_id::main ).playing > 0 ) };
if( ( false == isplaying ) if( ( false == isplaying )
&& ( false == m_soundchunks.empty() ) ) { && ( false == m_soundchunks.empty() ) ) {
// for emitters with sample tables check also if any of the chunks is active // for emitters with sample tables check also if any of the chunks is active
@@ -835,8 +833,9 @@ sound_source::location() const {
void void
sound_source::update_counter( sound_handle const Sound, int const Value ) { sound_source::update_counter( sound_handle const Sound, int const Value ) {
sound( Sound ).playing = std::max( 0, sound( Sound ).playing + Value ); // sound( Sound ).playing = std::max( 0, sound( Sound ).playing + Value );
// assert( sound( Sound ).playing >= 0 ); sound( Sound ).playing += Value;
assert( sound( Sound ).playing >= 0 );
} }
void void

10
sound.h
View File

@@ -179,15 +179,15 @@ private:
template <class Iterator_> template <class Iterator_>
void void
insert( Iterator_ First, Iterator_ Last ) { insert( Iterator_ First, Iterator_ Last ) {
uint32_sequence sounds; update_counter( *First, 1 );
std::vector<audio::buffer_handle> buffers; std::vector<audio::buffer_handle> buffers;
uint32_sequence sounds;
std::for_each( std::for_each(
First, Last, First, Last,
[&]( sound_handle const &soundhandle ) { [&]( sound_handle const &soundhandle ) {
sounds.emplace_back( soundhandle ); buffers.emplace_back( sound( soundhandle ).buffer );
buffers.emplace_back( sound( soundhandle ).buffer ); } ); sounds.emplace_back( soundhandle ); } );
audio::renderer.insert( std::begin( buffers ), std::end( buffers ), this, sounds ); audio::renderer.insert( std::begin( buffers ), std::end( buffers ), this, sounds ); }
update_counter( *First, 1 ); }
sound_data & sound_data &
sound( sound_handle const Sound ); sound( sound_handle const Sound );
sound_data const & sound_data const &

View File

@@ -175,7 +175,7 @@ void uart_input::poll()
auto const command { ( auto const command { (
type != toggle ? type != toggle ?
std::get<2>( entry ) : std::get<2>( entry ) :
( action == GLFW_PRESS ? ( true == state ?
std::get<2>( entry ) : std::get<2>( entry ) :
std::get<3>( entry ) ) ) }; std::get<3>( entry ) ) ) };