mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
parent
99e2d79ec8
commit
fa13b81d38
@ -42,6 +42,8 @@ type audioQueuePoolItem struct {
|
|||||||
bufs []C.AudioQueueBufferRef
|
bufs []C.AudioQueueBufferRef
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const audioQueuePoolMaxItemNum = 32 // 32 is an arbitrary number.
|
||||||
|
|
||||||
type audioQueuePool struct {
|
type audioQueuePool struct {
|
||||||
c *context
|
c *context
|
||||||
unused []audioQueuePoolItem
|
unused []audioQueuePoolItem
|
||||||
@ -49,6 +51,18 @@ type audioQueuePool struct {
|
|||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *audioQueuePool) Prepare(context *context) error {
|
||||||
|
a.c = context
|
||||||
|
for i := 0; i < audioQueuePoolMaxItemNum; i++ {
|
||||||
|
if _, _, err := a.Get(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a.unused = a.used
|
||||||
|
a.used = a.used[:0]
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *audioQueuePool) Get() (C.AudioQueueRef, []C.AudioQueueBufferRef, error) {
|
func (a *audioQueuePool) Get() (C.AudioQueueRef, []C.AudioQueueBufferRef, error) {
|
||||||
a.m.Lock()
|
a.m.Lock()
|
||||||
defer a.m.Unlock()
|
defer a.m.Unlock()
|
||||||
@ -116,8 +130,7 @@ func (a *audioQueuePool) Put(audioQueue C.AudioQueueRef) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
a.used = append(a.used[:i], a.used[i+1:]...)
|
a.used = append(a.used[:i], a.used[i+1:]...)
|
||||||
// 32 is an arbitrary number.
|
if len(a.unused)+len(a.used) < audioQueuePoolMaxItemNum {
|
||||||
if len(a.unused)+len(a.used) < 32 {
|
|
||||||
a.unused = append(a.unused, q)
|
a.unused = append(a.unused, q)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -156,7 +169,9 @@ func NewContext(sampleRate, channelNum, bitDepthInBytes int) (Context, chan stru
|
|||||||
channelNum: channelNum,
|
channelNum: channelNum,
|
||||||
bitDepthInBytes: bitDepthInBytes,
|
bitDepthInBytes: bitDepthInBytes,
|
||||||
}
|
}
|
||||||
c.audioQueuePool.c = c
|
if err := c.audioQueuePool.Prepare(c); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
C.ebiten_readerdriver_setNotificationHandler()
|
C.ebiten_readerdriver_setNotificationHandler()
|
||||||
return c, ready, nil
|
return c, ready, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user