mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
audio: Remove returning value from startPlaying
This commit is contained in:
parent
4492c0dad0
commit
54f0e30fe6
@ -105,11 +105,10 @@ func (s *mixedPlayersStream) Read(b []byte) (int, error) {
|
||||
// TODO: Enable to specify the format like Mono8?
|
||||
|
||||
type Context struct {
|
||||
sampleRate int
|
||||
stream *mixedPlayersStream
|
||||
players map[*Player]struct{}
|
||||
innerPlayer *player
|
||||
frames int
|
||||
sampleRate int
|
||||
stream *mixedPlayersStream
|
||||
players map[*Player]struct{}
|
||||
frames int
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
@ -122,11 +121,9 @@ func NewContext(sampleRate int) *Context {
|
||||
c.stream = &mixedPlayersStream{
|
||||
context: c,
|
||||
}
|
||||
p, err := startPlaying(c.stream, c.sampleRate)
|
||||
if err != nil {
|
||||
if err := startPlaying(c.stream, c.sampleRate); err != nil {
|
||||
panic(fmt.Sprintf("audio: NewContext error: %v", err))
|
||||
}
|
||||
c.innerPlayer = p
|
||||
return c
|
||||
}
|
||||
|
||||
|
@ -40,13 +40,13 @@ type player struct {
|
||||
isClosed bool
|
||||
}
|
||||
|
||||
func startPlaying(src io.Reader, sampleRate int) (*player, error) {
|
||||
func startPlaying(src io.Reader, sampleRate int) error {
|
||||
if e := al.OpenDevice(); e != nil {
|
||||
return nil, fmt.Errorf("audio: OpenAL initialization failed: %v", e)
|
||||
return fmt.Errorf("audio: OpenAL initialization failed: %v", e)
|
||||
}
|
||||
s := al.GenSources(1)
|
||||
if err := al.Error(); err != 0 {
|
||||
panic(fmt.Sprintf("audio: al.GenSources error: %d", err))
|
||||
return fmt.Errorf("audio: al.GenSources error: %d", err)
|
||||
}
|
||||
p := &player{
|
||||
alSource: s[0],
|
||||
@ -55,10 +55,7 @@ func startPlaying(src io.Reader, sampleRate int) (*player, error) {
|
||||
sampleRate: sampleRate,
|
||||
}
|
||||
runtime.SetFinalizer(p, (*player).close)
|
||||
if err := p.start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return p, nil
|
||||
return p.start()
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -37,6 +37,8 @@ type header struct {
|
||||
waveHdr C.WAVEHDR
|
||||
}
|
||||
|
||||
// TODO: Reduce panics and use errors instead
|
||||
|
||||
func newHeader(waveOut C.HWAVEOUT, bufferSize int) header {
|
||||
// NOTE: This is never freed so far.
|
||||
buf := C.malloc(C.size_t(bufferSize))
|
||||
@ -74,10 +76,7 @@ func releaseSemaphore() {
|
||||
<-sem
|
||||
}
|
||||
|
||||
type player struct {
|
||||
}
|
||||
|
||||
func startPlaying(src io.Reader, sampleRate int) (*player, error) {
|
||||
func startPlaying(src io.Reader, sampleRate int) error {
|
||||
const numBlockAlign = channelNum * bitsPerSample / 8
|
||||
f := C.WAVEFORMATEX{
|
||||
wFormatTag: C.WAVE_FORMAT_PCM,
|
||||
@ -89,7 +88,7 @@ func startPlaying(src io.Reader, sampleRate int) (*player, error) {
|
||||
}
|
||||
var w C.HWAVEOUT
|
||||
if err := C.waveOutOpen2(&w, &f); err != C.MMSYSERR_NOERROR {
|
||||
panic(fmt.Sprintf("audio: waveOutOpen error: %d", err))
|
||||
return fmt.Errorf("audio: waveOutOpen error: %d", err)
|
||||
}
|
||||
go func() {
|
||||
const bufferSize = 1024
|
||||
@ -123,5 +122,5 @@ func startPlaying(src io.Reader, sampleRate int) (*player, error) {
|
||||
}
|
||||
// TODO: Finalize the wave handler
|
||||
}()
|
||||
return &player{}, nil
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user