mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +01:00
audio/internal/readerderiver: Bug fix: Reduce noises on Android
Closes #1632
This commit is contained in:
parent
83c9015468
commit
c954dfa8fb
5
audio/internal/oboe/binding_android.cpp
vendored
5
audio/internal/oboe/binding_android.cpp
vendored
@ -57,6 +57,11 @@ 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) {
|
||||
|
@ -93,17 +93,30 @@ func (p *player) Play() {
|
||||
return
|
||||
}
|
||||
defer p.cond.Signal()
|
||||
var runLoop bool
|
||||
if p.p == nil {
|
||||
p.p = oboe.NewPlayer(p.context.sampleRate, p.context.channelNum, p.context.bitDepthInBytes, p.volume, func() {
|
||||
p.cond.Signal()
|
||||
})
|
||||
go p.loop()
|
||||
runLoop = true
|
||||
|
||||
// Fill the first part before playing to reduce noises (#1632).
|
||||
buf := make([]byte, p.context.oneBufferSize())
|
||||
n, err := p.src.Read(buf)
|
||||
if err != nil && err != io.EOF {
|
||||
p.setErrorImpl(err)
|
||||
return
|
||||
}
|
||||
p.p.AppendBuffer(buf[:n])
|
||||
}
|
||||
if err := p.p.Play(); err != nil {
|
||||
p.setErrorImpl(err)
|
||||
return
|
||||
}
|
||||
p.state = playerPlay
|
||||
if runLoop {
|
||||
go p.loop()
|
||||
}
|
||||
}
|
||||
|
||||
func (p *player) IsPlaying() bool {
|
||||
|
Loading…
Reference in New Issue
Block a user