1
0

context.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2021 The Ebiten Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package audio
  15. import (
  16. "io"
  17. "github.com/ebitengine/oto/v3"
  18. )
  19. func newContext(sampleRate int) (context, chan struct{}, error) {
  20. ctx, ready, err := oto.NewContext(&oto.NewContextOptions{
  21. SampleRate: sampleRate,
  22. ChannelCount: channelCount,
  23. Format: oto.FormatFloat32LE,
  24. })
  25. err = addErrorInfo(err)
  26. return &contextProxy{ctx}, ready, err
  27. }
  28. // contextProxy is a proxy between otoContext and context.
  29. type contextProxy struct {
  30. *oto.Context
  31. }
  32. // NewPlayer implements context.
  33. func (c *contextProxy) NewPlayer(r io.Reader) player {
  34. return c.Context.NewPlayer(r)
  35. }