mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-18 01:35:47 -04:00
System: Reset throttler when audio buffers underflow
Should hopefully reduce the chances of the audio source ending up out of phase from the emulation when vsync is disabled.
This commit is contained in:
@ -170,12 +170,14 @@ void AudioStream::ReadFrames(SampleType* samples, u32 num_frames, bool apply_vol
|
||||
}
|
||||
|
||||
Log_DevPrintf("Audio buffer underflow, resampled %u frames to %u", samples_copied / m_channels, num_frames);
|
||||
m_underflow_flag.store(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// read nothing, so zero-fill
|
||||
std::memset(samples, 0, sizeof(SampleType) * total_samples);
|
||||
Log_DevPrintf("Audio buffer underflow with no samples, added %u frames silence", num_frames);
|
||||
m_underflow_flag.store(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,4 +220,5 @@ void AudioStream::EmptyBuffers()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_buffer_mutex);
|
||||
m_buffer.Clear();
|
||||
m_underflow_flag.store(false);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "fifo_queue.h"
|
||||
#include "types.h"
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@ -45,6 +46,12 @@ public:
|
||||
void WriteFrames(const SampleType* frames, u32 num_frames);
|
||||
void EndWrite(u32 num_frames);
|
||||
|
||||
bool DidUnderflow()
|
||||
{
|
||||
bool expected = true;
|
||||
return m_underflow_flag.compare_exchange_strong(expected, false);
|
||||
}
|
||||
|
||||
static std::unique_ptr<AudioStream> CreateNullAudioStream();
|
||||
|
||||
// Latency computation - returns values in seconds
|
||||
@ -84,6 +91,7 @@ private:
|
||||
mutable std::mutex m_buffer_mutex;
|
||||
std::condition_variable m_buffer_draining_cv;
|
||||
std::vector<SampleType> m_resample_buffer;
|
||||
std::atomic_bool m_underflow_flag{false};
|
||||
u32 m_max_samples = 0;
|
||||
|
||||
bool m_output_paused = true;
|
||||
|
Reference in New Issue
Block a user