mirror of
https://github.com/bloeys/wavy.git
synced 2025-12-29 09:28:19 +00:00
Use oto v2.2.0+use oto seeker+remove mutexes
This commit is contained in:
@ -3,7 +3,6 @@ package wavy
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/jfreymuth/oggvorbis"
|
||||
)
|
||||
@ -13,30 +12,19 @@ var _ io.ReadSeeker = &OggStreamer{}
|
||||
type OggStreamer struct {
|
||||
F *os.File
|
||||
Dec *oggvorbis.Reader
|
||||
|
||||
//TODO: This is currently needed because of https://github.com/hajimehoshi/oto/issues/171
|
||||
//We should be able to delete once its resolved
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
func (ws *OggStreamer) Read(outBuf []byte) (floatsRead int, err error) {
|
||||
|
||||
ws.mutex.Lock()
|
||||
|
||||
readerBuf := make([]float32, len(outBuf)/2)
|
||||
floatsRead, err = ws.Dec.Read(readerBuf)
|
||||
F32ToUnsignedPCM16(readerBuf[:floatsRead], outBuf)
|
||||
|
||||
ws.mutex.Unlock()
|
||||
|
||||
return floatsRead * 2, err
|
||||
}
|
||||
|
||||
func (ws *OggStreamer) Seek(offset int64, whence int) (int64, error) {
|
||||
|
||||
ws.mutex.Lock()
|
||||
defer ws.mutex.Unlock()
|
||||
|
||||
//This is because ogg expects position in samples not bytes
|
||||
offset /= BytesPerSample
|
||||
|
||||
@ -68,8 +56,7 @@ func (ws *OggStreamer) Size() int64 {
|
||||
|
||||
func NewOggStreamer(f *os.File, dec *oggvorbis.Reader) *OggStreamer {
|
||||
return &OggStreamer{
|
||||
F: f,
|
||||
Dec: dec,
|
||||
mutex: sync.Mutex{},
|
||||
F: f,
|
||||
Dec: dec,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user