audio/internal/readerdriver: Change the returning type of UnplayedBufferSize int64 -> int

This commit is contained in:
Hajime Hoshi 2021-05-10 03:22:19 +09:00
parent 7a6bdc8388
commit 52c609459c
7 changed files with 16 additions and 16 deletions

View File

@ -127,7 +127,7 @@ func (p *Player) Play() {
// TODO: Get the appropriate buffer size from the C++ side. // TODO: Get the appropriate buffer size from the C++ side.
if p.buf == nil { if p.buf == nil {
n := p.context.oneBufferSize() n := p.context.oneBufferSize()
if max := p.context.MaxBufferSize() - int(p.UnplayedBufferSize()); n > max { if max := p.context.MaxBufferSize() - p.UnplayedBufferSize(); n > max {
n = max n = max
} }
p.buf = make([]byte, n) p.buf = make([]byte, n)
@ -195,11 +195,11 @@ func (p *Player) SetVolume(volume float64) {
p.v.Set("volume", volume) p.v.Set("volume", volume)
} }
func (p *Player) UnplayedBufferSize() int64 { func (p *Player) UnplayedBufferSize() int {
if !p.v.Truthy() { if !p.v.Truthy() {
return 0 return 0
} }
return int64(p.v.Get("unplayedBufferSize").Int()) return p.v.Get("unplayedBufferSize").Int()
} }
func (p *Player) Err() error { func (p *Player) Err() error {
@ -303,7 +303,7 @@ func (p *Player) loop() {
} }
n := readChunkSize n := readChunkSize
if max := p.context.MaxBufferSize() - int(p.UnplayedBufferSize()); n > max { if max := p.context.MaxBufferSize() - p.UnplayedBufferSize(); n > max {
n = max n = max
} }
n2, err := p.src.Read(buf[:n]) n2, err := p.src.Read(buf[:n])

View File

@ -101,6 +101,6 @@ func (p *Player) Close() error {
return nil return nil
} }
func (p *Player) UnplayedBufferSize() int64 { func (p *Player) UnplayedBufferSize() int {
return int64(C.Player_UnplayedBufferSize(p.player)) return int(C.Player_UnplayedBufferSize(p.player))
} }

View File

@ -31,7 +31,7 @@ type Player interface {
Reset() Reset()
Volume() float64 Volume() float64
SetVolume(volume float64) SetVolume(volume float64)
UnplayedBufferSize() int64 UnplayedBufferSize() int
Err() error Err() error
io.Closer io.Closer
} }

View File

@ -114,7 +114,7 @@ func (p *player) Play() {
} }
buf := make([]byte, p.context.maxBufferSize()) buf := make([]byte, p.context.maxBufferSize())
for p.p.UnplayedBufferSize() < int64(p.context.maxBufferSize()) { for p.p.UnplayedBufferSize() < p.context.maxBufferSize() {
n, err := p.src.Read(buf) n, err := p.src.Read(buf)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
p.setErrorImpl(err) p.setErrorImpl(err)
@ -183,7 +183,7 @@ func (p *player) SetVolume(volume float64) {
p.p.SetVolume(volume) p.p.SetVolume(volume)
} }
func (p *player) UnplayedBufferSize() int64 { func (p *player) UnplayedBufferSize() int {
p.cond.L.Lock() p.cond.L.Lock()
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
if p.p == nil { if p.p == nil {
@ -240,7 +240,7 @@ func (p *player) shouldWait() bool {
return false return false
} }
if p.p.IsPlaying() { if p.p.IsPlaying() {
return p.p.UnplayedBufferSize() >= int64(p.context.maxBufferSize()) return p.p.UnplayedBufferSize() >= p.context.maxBufferSize()
} }
return true return true
} }

View File

@ -525,14 +525,14 @@ func (p *playerImpl) SetVolume(volume float64) {
C.AudioQueueSetParameter(p.audioQueue, C.kAudioQueueParam_Volume, C.AudioQueueParameterValue(volume)) C.AudioQueueSetParameter(p.audioQueue, C.kAudioQueueParam_Volume, C.AudioQueueParameterValue(volume))
} }
func (p *player) UnplayedBufferSize() int64 { func (p *player) UnplayedBufferSize() int {
return p.p.UnplayedBufferSize() return p.p.UnplayedBufferSize()
} }
func (p *playerImpl) UnplayedBufferSize() int64 { func (p *playerImpl) UnplayedBufferSize() int {
p.cond.L.Lock() p.cond.L.Lock()
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
return int64(len(p.buf)) return len(p.buf)
} }
func (p *player) Close() error { func (p *player) Close() error {

View File

@ -296,7 +296,7 @@ func (p *player) SetVolume(volume float64) {
p.gain.Get("gain").Set("value", volume) p.gain.Get("gain").Set("value", volume)
} }
func (p *player) UnplayedBufferSize() int64 { func (p *player) UnplayedBufferSize() int {
p.cond.L.Lock() p.cond.L.Lock()
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
@ -305,7 +305,7 @@ func (p *player) UnplayedBufferSize() int64 {
for _, n := range p.bufferSourceNodes { for _, n := range p.bufferSourceNodes {
sec += n.Get("buffer").Get("duration").Float() sec += n.Get("buffer").Get("duration").Float()
} }
return int64(len(p.buf)) + int64(sec*float64(p.context.sampleRate*p.context.channelNum*p.context.bitDepthInBytes)) return len(p.buf) + int(sec*float64(p.context.sampleRate*p.context.channelNum*p.context.bitDepthInBytes))
} }
func (p *player) Err() error { func (p *player) Err() error {

View File

@ -189,7 +189,7 @@ func (p *readerPlayer) Current() time.Duration {
return 0 return 0
} }
sample := (p.stream.Current() - p.player.UnplayedBufferSize()) / bytesPerSample sample := (p.stream.Current() - int64(p.player.UnplayedBufferSize())) / bytesPerSample
return time.Duration(sample) * time.Second / time.Duration(p.factory.sampleRate) return time.Duration(sample) * time.Second / time.Duration(p.factory.sampleRate)
} }