1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-10-04 16:17:17 +02:00

Restructure sbs and fix hanging of new test

This commit is contained in:
Filip Gawin 2019-05-12 15:03:05 +02:00
parent 88b1c9e509
commit 9b07e0492f
2 changed files with 54 additions and 43 deletions

View File

@ -58,16 +58,23 @@ void SoundBufferStreamed::play() {
std::lock_guard<std::mutex> lock(soundSource->mutex);
alSourcePlay(source);
running = true;
// Maybe another thread is running, we should tell him to stop
if (running) {
running = false;
}
}
// Use preloaded data (and give another thread time to stop)
std::this_thread::sleep_for(kTickFreqMs);
// Not we should be able start thread
loadingThread = std::async(std::launch::async,
&SoundBufferStreamed::updateBuffers, this);
}
void SoundBufferStreamed::updateBuffers() {
running = true;
while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
{
std::lock_guard<std::mutex> lock(soundSource->mutex);
if (!running) {
return;
@ -86,8 +93,8 @@ void SoundBufferStreamed::updateBuffers() {
streamedData * kSizeOfChunk < soundSource->data.size()) {
bufferedData = true;
ALuint bufid{};
auto sizeOfNextChunk =
std::min(static_cast<size_t>(kSizeOfChunk),
auto sizeOfNextChunk = std::min(
static_cast<size_t>(kSizeOfChunk),
soundSource->data.size() -
static_cast<size_t>(kSizeOfChunk) * streamedData);
@ -118,6 +125,8 @@ void SoundBufferStreamed::updateBuffers() {
alCheck(alSourcePlay(source));
}
}
std::this_thread::sleep_for(kTickFreqMs);
}
}
void SoundBufferStreamed::pause() {

View File

@ -9,6 +9,8 @@
struct SoundBufferStreamed : public SoundBuffer {
static constexpr unsigned int kNrBuffersStreaming = 4;
static constexpr unsigned int kSizeOfChunk = 4096;
static constexpr std::chrono::milliseconds kTickFreqMs =
std::chrono::milliseconds(100);
SoundBufferStreamed();
~SoundBufferStreamed() override;