fix dumping of raw PCM audio

This commit is contained in:
bretello 2020-10-22 22:51:48 +02:00
parent 8fa584775f
commit 3df1d842f3
2 changed files with 14 additions and 31 deletions

View File

@ -13,12 +13,9 @@ import (
"layeh.com/gumble/gumble" "layeh.com/gumble/gumble"
"layeh.com/gumble/gumbleutil" "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 { type AudioListener struct {
name string name string
} }
@ -28,33 +25,16 @@ func (audiolistener AudioListener) OnAudioStream(e *gumble.AudioStreamEvent) {
go ReadPacket(e.C) go ReadPacket(e.C)
} }
// func PcmToMp3(pcmFileName, mp3FileName string) { func ReadPacket(ch <-chan *gumble.AudioPacket) {
// pcmFile, _ := os.OpenFile(pcmFileName, os.O_RDONLY, 0555) outFile := "pcm_out.raw"
// mp3File, _ := os.OpenFile(mp3FileName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755) fmt.Printf("Saving out to %s", outFile) // debug
// defer mp3File.Close() pcm_out, _ := os.OpenFile(outFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755)
// 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)
defer pcm_out.Close() defer pcm_out.Close()
//func (f *File) Write(b []byte) (n int, err error)
for packet := range ch { for packet := range ch {
fmt.Println(packet.Sender.Name) // log.Printf("Message from %s", packet.Sender.Name) // debug
// fmt.Printf("%:+v\n", packet) buf := packet.AudioBuffer
// pkt := <-ch pcm_out.Write(UnsafeCastInt16sToBytes(buf))
// buf := pkt.AudioBuffer
// pcm_out.Write(UnsafeCastInt16sToBytes(buf))
} }
} }
@ -83,6 +63,7 @@ func main() {
} }
// Print available channels on the server
fmt.Printf("Channels:\n") fmt.Printf("Channels:\n")
for idx, channel := range client.Channels { for idx, channel := range client.Channels {
fmt.Printf("\t%d - %s\n", idx, channel.Name) fmt.Printf("\t%d - %s\n", idx, channel.Name)

View File

@ -1,7 +1,9 @@
package main package main
import "unsafe" import (
import "reflect" "reflect"
"unsafe"
)
const BYTES_IN_INT32 = 4 const BYTES_IN_INT32 = 4
const BYTES_IN_INT16 = 2 const BYTES_IN_INT16 = 2