From ccff0eb51fa2ae2b94d2a6297f45519a12e07def Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Sun, 24 May 2026 21:56:18 -0400 Subject: fix issue slavek reported with peak lagging due to buffer and some other stuff. fixed --- src/model/pulsedevice.cpp | 16 ++++++++++++++-- src/ui/levelmeter.cpp | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/model/pulsedevice.cpp b/src/model/pulsedevice.cpp index f91ace6..616cf23 100644 --- a/src/model/pulsedevice.cpp +++ b/src/model/pulsedevice.cpp @@ -82,7 +82,15 @@ void PulseDevice::update( const TQString &name, int volume, bool muted, m_channels = channels ? channels : 2; m_pan = pan; - if ( m_monitorName.isEmpty() && !monitorName.isEmpty() ) { + if ( !monitorName.isEmpty() && monitorName != m_monitorName ) { + if ( m_monitorStream && m_mainloop ) { + pa_threaded_mainloop_lock( m_mainloop ); + pa_stream_set_read_callback( m_monitorStream, 0, 0 ); + pa_stream_disconnect( m_monitorStream ); + pa_stream_unref( m_monitorStream ); + pa_threaded_mainloop_unlock( m_mainloop ); + m_monitorStream = 0; + } m_monitorName = monitorName; if ( m_context ) startMonitoring(); } @@ -107,6 +115,9 @@ void PulseDevice::resumeMonitoring() { if ( !m_monitorStream || !m_mainloop ) return; pa_threaded_mainloop_lock( m_mainloop ); + const void *data; size_t nbytes; + while ( pa_stream_peek( m_monitorStream, &data, &nbytes ) == 0 && nbytes > 0 ) + pa_stream_drop( m_monitorStream ); pa_stream_set_read_callback( m_monitorStream, monitorReadCb, this ); pa_threaded_mainloop_unlock( m_mainloop ); } @@ -138,7 +149,8 @@ void PulseDevice::startMonitoring() pa_buffer_attr attr; memset( &attr, 0xff, sizeof(attr) ); - attr.fragsize = sizeof(float); + attr.fragsize = sizeof(float); + attr.maxlength = sizeof(float) * 8; pa_stream_connect_record( m_monitorStream, m_monitorName.utf8().data(), &attr, diff --git a/src/ui/levelmeter.cpp b/src/ui/levelmeter.cpp index 906ef20..f0512c7 100644 --- a/src/ui/levelmeter.cpp +++ b/src/ui/levelmeter.cpp @@ -29,7 +29,7 @@ void LevelMeter::setLevel( float level ) if ( display > m_level ) m_level = m_level * 0.3f + display * 0.7f; // fast attack, not instant else { - m_level *= 0.925f; // slow decay ~1.5s to floor at 20Hz + m_level *= 0.85f; // decay ~0.7s to floor at 20Hz if ( m_level < 0.001f ) m_level = 0.0f; } update(); -- cgit v1.2.3