Render file playback through the OpenAL owner
This commit is contained in:
committed by
Brandon McGinty
parent
8c0887d562
commit
db31ba33de
@@ -82,6 +82,8 @@ type Stream struct {
|
||||
micAGC *audio.AGC
|
||||
micAGCRight *audio.AGC
|
||||
filePlayer FilePlayer
|
||||
localSource *openal.Source
|
||||
localBuffers openal.Buffers
|
||||
recorderMu sync.RWMutex
|
||||
errorFunc func(error) // called on capture errors
|
||||
recorder Recorder
|
||||
@@ -200,6 +202,54 @@ func (s *Stream) SetNoiseProcessor(np NoiseProcessor) {
|
||||
|
||||
func (s *Stream) SetFilePlayer(fp FilePlayer) {
|
||||
s.filePlayer = fp
|
||||
if player, ok := fp.(interface{ SetLocalPlayback(func([]byte)) }); ok {
|
||||
player.SetLocalPlayback(s.playLocalAudio)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Stream) playLocalAudio(data []byte) {
|
||||
s.render(func() {
|
||||
if data == nil {
|
||||
if s.localSource != nil {
|
||||
s.localSource.Stop()
|
||||
queued := s.localSource.BuffersQueued()
|
||||
if queued > 0 {
|
||||
buffers := make(openal.Buffers, queued)
|
||||
s.localSource.UnqueueBuffers(buffers)
|
||||
s.localBuffers = append(s.localBuffers, buffers...)
|
||||
}
|
||||
s.localSource.Delete()
|
||||
s.localSource = nil
|
||||
}
|
||||
if len(s.localBuffers) > 0 {
|
||||
s.localBuffers.Delete()
|
||||
s.localBuffers = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
if s.localSource == nil {
|
||||
source := openal.NewSource()
|
||||
source.SetGain(1)
|
||||
s.localSource = &source
|
||||
s.localBuffers = openal.NewBuffers(64)
|
||||
}
|
||||
if n := s.localSource.BuffersProcessed(); n > 0 {
|
||||
buffers := make(openal.Buffers, n)
|
||||
s.localSource.UnqueueBuffers(buffers)
|
||||
s.localBuffers = append(s.localBuffers, buffers...)
|
||||
}
|
||||
if len(s.localBuffers) == 0 {
|
||||
return
|
||||
}
|
||||
last := len(s.localBuffers) - 1
|
||||
buffer := s.localBuffers[last]
|
||||
s.localBuffers = s.localBuffers[:last]
|
||||
buffer.SetData(openal.FormatStereo16, data, gumble.AudioSampleRate)
|
||||
s.localSource.QueueBuffer(buffer)
|
||||
if s.localSource.State() != openal.Playing {
|
||||
s.localSource.Play()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Stream) GetFilePlayer() FilePlayer {
|
||||
|
||||
Reference in New Issue
Block a user