mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-17 16:50:31 +00:00
Remove audio + fix DOcker file
This commit is contained in:
parent
81362b9d88
commit
d43ae386fe
2 changed files with 4 additions and 55 deletions
|
|
@ -8,5 +8,8 @@ RUN apt-get update
|
|||
RUN apt-get install portaudio19-dev -y
|
||||
RUN apt-get install libvpx-dev -y
|
||||
RUN go get github.com/pions/webrtc
|
||||
RUN go get github.com/gordonklaus/portaudio
|
||||
#RUN go get github.com/gordonklaus/portaudio
|
||||
RUN go get github.com/gorilla/mux
|
||||
RUN go install github.com/giongto35/game-online
|
||||
|
||||
EXPOSE 8000
|
||||
|
|
|
|||
54
ui/audio.go
54
ui/audio.go
|
|
@ -1,54 +0,0 @@
|
|||
package ui
|
||||
|
||||
import "github.com/gordonklaus/portaudio"
|
||||
|
||||
type Audio struct {
|
||||
stream *portaudio.Stream
|
||||
sampleRate float64
|
||||
outputChannels int
|
||||
channel chan float32
|
||||
}
|
||||
|
||||
func NewAudio() *Audio {
|
||||
a := Audio{}
|
||||
a.channel = make(chan float32, 44100)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a *Audio) Start() error {
|
||||
host, err := portaudio.DefaultHostApi()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
parameters := portaudio.HighLatencyParameters(nil, host.DefaultOutputDevice)
|
||||
stream, err := portaudio.OpenStream(parameters, a.Callback)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := stream.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
a.stream = stream
|
||||
a.sampleRate = parameters.SampleRate
|
||||
a.outputChannels = parameters.Output.Channels
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Audio) Stop() error {
|
||||
return a.stream.Close()
|
||||
}
|
||||
|
||||
func (a *Audio) Callback(out []float32) {
|
||||
var output float32
|
||||
for i := range out {
|
||||
if i%a.outputChannels == 0 {
|
||||
select {
|
||||
case sample := <-a.channel:
|
||||
output = sample
|
||||
default:
|
||||
output = 0
|
||||
}
|
||||
}
|
||||
out[i] = output
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue