Skip to content

Commit

Permalink
merge audio_outgoing.go with audio.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Cooper committed Nov 21, 2014
1 parent 17bcd3b commit fe90185
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
29 changes: 28 additions & 1 deletion gumble/audio.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package gumble

import (
"github.com/bontibon/gopus"
)

type AudioFlag int

const (
Expand Down Expand Up @@ -32,7 +36,9 @@ func (a *Audio) Detach() {
}
a.client.audio = nil
a.stream.OnDetach()
close(a.outgoing)
if a.IsSource() {
close(a.outgoing)
}
}

func (a *Audio) IsSource() bool {
Expand All @@ -43,6 +49,27 @@ func (a *Audio) IsSink() bool {
return (a.flags & AudioSink) != 0
}

func (a *Audio) outgoingRoutine() {
message := audioMessage{
Format: audioOpus,
Target: audioNormal,
}
encoder, _ := gopus.NewEncoder(SampleRate, 1, gopus.Voip)
encoder.SetVbr(false)
encoder.SetBitrate(40000)
for {
if buf, ok := <-a.outgoing; !ok {
return
} else {
if opusBuf, err := encoder.Encode(buf.Pcm, SampleRate/100, 1024); err == nil {
a.client.Send(&message)
message.sequence = (message.sequence + 1) % 10000
message.opus = opusBuf
}
}
}
}

type AudioPacket struct {
Sender *User
Sequence int
Expand Down
27 changes: 0 additions & 27 deletions gumble/audio_outgoing.go

This file was deleted.

2 changes: 1 addition & 1 deletion gumble/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (c *Client) AttachAudio(stream AudioStream, flags AudioFlag) (*Audio, error
}
if audio.IsSource() {
audio.outgoing = make(chan AudioPacket)
go audioOutgoing(audio)
go audio.outgoingRoutine()
if err := stream.OnAttachSource(audio.outgoing); err != nil {
close(audio.outgoing)
return nil, err
Expand Down

0 comments on commit fe90185

Please sign in to comment.