audio/internal/readdriver: Bug fix: Wait for a while after finishing to write

Closes #1632
This commit is contained in:
Hajime Hoshi 2021-05-05 16:49:02 +09:00
parent ded3cd1433
commit 1fecaa0a90
2 changed files with 4 additions and 5 deletions

View File

@ -57,11 +57,6 @@ public:
std::lock_guard<std::mutex> lock(GetPlayersMutex());
GetPlayers().insert(this);
}
// Fill zeros with 1/60[s] as the first part to avoid noises (#1632).
// 1/60[s] is an arbitrary duration and might need to be adjusted.
size_t mul = channel_num_ * bit_depth_in_bytes_;
size_t size = (sample_rate_ * channel_num_ * bit_depth_in_bytes_) / 60 / mul * mul;
buf_.resize(size);
}
void SetVolume(double volume) {

View File

@ -18,6 +18,7 @@ import (
"io"
"runtime"
"sync"
"time"
"github.com/hajimehoshi/ebiten/v2/audio/internal/oboe"
)
@ -268,6 +269,9 @@ func (p *player) loop() {
// Now p.p.Reset() doesn't close the stream gracefully. Then buffer size check is necessary here.
if err == io.EOF && p.UnplayedBufferSize() == 0 {
// Even when the unplayed buffer size is 0, the audio data in the hardware might not be played yet (#1632).
// Just wait for a while.
time.Sleep(100 * time.Millisecond)
p.Reset()
return
}