mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 19:22:49 +01:00
audio: Refactoring: Remove newPlayerFromCache
This commit is contained in:
parent
62af947368
commit
9c097c73f5
@ -42,8 +42,14 @@ type player struct {
|
|||||||
|
|
||||||
var m sync.Mutex
|
var m sync.Mutex
|
||||||
|
|
||||||
// TODO: Unify this to newPlayer
|
func newPlayer(src io.Reader, sampleRate int) (*player, error) {
|
||||||
func newPlayerFromCache(src io.Reader, sampleRate int) (*player, error) {
|
m.Lock()
|
||||||
|
defer m.Unlock()
|
||||||
|
|
||||||
|
if e := al.OpenDevice(); e != nil {
|
||||||
|
m.Unlock()
|
||||||
|
return nil, fmt.Errorf("audio: OpenAL initialization failed: %v", e)
|
||||||
|
}
|
||||||
s := al.GenSources(1)
|
s := al.GenSources(1)
|
||||||
if err := al.Error(); err != 0 {
|
if err := al.Error(); err != 0 {
|
||||||
panic(fmt.Sprintf("audio: al.GenSources error: %d", err))
|
panic(fmt.Sprintf("audio: al.GenSources error: %d", err))
|
||||||
@ -58,21 +64,6 @@ func newPlayerFromCache(src io.Reader, sampleRate int) (*player, error) {
|
|||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPlayer(src io.Reader, sampleRate int) (*player, error) {
|
|
||||||
m.Lock()
|
|
||||||
defer m.Unlock()
|
|
||||||
|
|
||||||
if e := al.OpenDevice(); e != nil {
|
|
||||||
m.Unlock()
|
|
||||||
return nil, fmt.Errorf("audio: OpenAL initialization failed: %v", e)
|
|
||||||
}
|
|
||||||
p, err := newPlayerFromCache(src, sampleRate)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return p, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const bufferSize = 1024
|
const bufferSize = 1024
|
||||||
|
|
||||||
func (p *player) proceed() error {
|
func (p *player) proceed() error {
|
||||||
|
Loading…
Reference in New Issue
Block a user