From 3df1d842f31f9dec812cc77dbfdedabde8a6e89c Mon Sep 17 00:00:00 2001 From: bretello Date: Thu, 22 Oct 2020 22:51:48 +0200 Subject: [PATCH] fix dumping of raw PCM audio --- broadcast/main.go | 39 ++++++++++----------------------------- broadcast/utils.go | 6 ++++-- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/broadcast/main.go b/broadcast/main.go index cad8650..3fcceae 100644 --- a/broadcast/main.go +++ b/broadcast/main.go @@ -13,12 +13,9 @@ import ( "layeh.com/gumble/gumble" "layeh.com/gumble/gumbleutil" - _ "layeh.com/gumble/opus" // it's a good idea to load this: botamusique crashes because of a CodecNotSupportedError EXception + _ "layeh.com/gumble/opus" ) -func audiolistener(e *gumble.AudioStreamEvent) { -} - type AudioListener struct { name string } @@ -28,33 +25,16 @@ func (audiolistener AudioListener) OnAudioStream(e *gumble.AudioStreamEvent) { go ReadPacket(e.C) } -// func PcmToMp3(pcmFileName, mp3FileName string) { -// pcmFile, _ := os.OpenFile(pcmFileName, os.O_RDONLY, 0555) -// mp3File, _ := os.OpenFile(mp3FileName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755) -// defer mp3File.Close() -// wr, err := lame.NewWriter(mp3File) -// if err != nil { -// panic("cannot create lame writer, err: " + err.Error()) - -// } -// io.Copy(wr, pcmFile) -// wr.Close() - -// } - -type AudioEncoder struct { -} - -func ReadPacket(ch <-chan *gumble.AudioPacket) { // receive-only channel - pcm_out, _ := os.OpenFile("pcm_out.raw", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755) +func ReadPacket(ch <-chan *gumble.AudioPacket) { + outFile := "pcm_out.raw" + fmt.Printf("Saving out to %s", outFile) // debug + pcm_out, _ := os.OpenFile(outFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755) defer pcm_out.Close() - //func (f *File) Write(b []byte) (n int, err error) + for packet := range ch { - fmt.Println(packet.Sender.Name) - // fmt.Printf("%:+v\n", packet) - // pkt := <-ch - // buf := pkt.AudioBuffer - // pcm_out.Write(UnsafeCastInt16sToBytes(buf)) + // log.Printf("Message from %s", packet.Sender.Name) // debug + buf := packet.AudioBuffer + pcm_out.Write(UnsafeCastInt16sToBytes(buf)) } } @@ -83,6 +63,7 @@ func main() { } + // Print available channels on the server fmt.Printf("Channels:\n") for idx, channel := range client.Channels { fmt.Printf("\t%d - %s\n", idx, channel.Name) diff --git a/broadcast/utils.go b/broadcast/utils.go index 82e56e4..c8f26bf 100644 --- a/broadcast/utils.go +++ b/broadcast/utils.go @@ -1,7 +1,9 @@ package main -import "unsafe" -import "reflect" +import ( + "reflect" + "unsafe" +) const BYTES_IN_INT32 = 4 const BYTES_IN_INT16 = 2