diff --git a/audio/audio.go b/audio/audio.go index fbee8d9..50b794f 100644 --- a/audio/audio.go +++ b/audio/audio.go @@ -2,6 +2,7 @@ package audio import ( "fmt" + "os" "xyosc/config" "xyosc/utils" @@ -15,10 +16,8 @@ var SampleSizeInBytes uint32 const format = malgo.FormatF32 func Init() { - deviceConfig := malgo.DefaultDeviceConfig(malgo.Duplex) SampleRingBuffer = ringbuffer.New(int(config.Config.RingBufferSize)) - deviceConfig.Capture.Format = format - SampleSizeInBytes = uint32(malgo.SampleSizeInBytes(deviceConfig.Capture.Format)) + SampleSizeInBytes = uint32(malgo.SampleSizeInBytes(format)) } func Start() { @@ -31,11 +30,31 @@ func Start() { ctx.Free() }() - deviceConfig := malgo.DefaultDeviceConfig(malgo.Duplex) + // Capture devices. + infos, err := ctx.Devices(malgo.Capture) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + fmt.Println("Capture Devices") + for i, info := range infos { + e := "ok" + full, err := ctx.DeviceInfo(malgo.Capture, info.ID, malgo.Shared) + if err != nil { + e = err.Error() + } + fmt.Printf(" %d: %v, %s, [%s], formats: %+v\n", + i, info.ID, info.Name(), e, full.Formats) + } + + deviceConfig := malgo.DefaultDeviceConfig(malgo.Capture) deviceConfig.Capture.Format = format deviceConfig.Capture.Channels = 2 + deviceConfig.Capture.DeviceID = infos[config.Config.CaptureDeviceIndex].ID.Pointer() deviceConfig.SampleRate = config.Config.SampleRate deviceConfig.Alsa.NoMMap = 1 + onRecvFrames := func(pSample2, pSample []byte, framecount uint32) { SampleRingBuffer.Write(pSample) } @@ -49,7 +68,6 @@ func Start() { err = device.Start() utils.CheckError(err) - for { - } + select {} //device.Uninit() } diff --git a/config/config.go b/config/config.go index 72dec39..ac9a3d3 100644 --- a/config/config.go +++ b/config/config.go @@ -13,29 +13,33 @@ import ( ) type ConfigS struct { - FPSCounter bool - TargetFPS int32 - WindowWidth int32 - WindowHeight int32 - SampleRate uint32 - RingBufferSize uint32 - ReadBufferSize uint32 - Gain float32 - LineOpacity uint8 - LineThickness float32 + FPSCounter bool + TargetFPS int32 + WindowWidth int32 + WindowHeight int32 + WindowOpacity float32 + CaptureDeviceIndex int + SampleRate uint32 + RingBufferSize uint32 + ReadBufferSize uint32 + Gain float32 + LineOpacity uint8 + LineThickness float32 } var DefaultConfig = ConfigS{ - FPSCounter: false, - TargetFPS: 60, - WindowWidth: 800, - WindowHeight: 800, - SampleRate: 192000, - RingBufferSize: 192000 * 4, - ReadBufferSize: 192000, - Gain: 1, - LineOpacity: 50, - LineThickness: 2, + FPSCounter: false, + TargetFPS: 60, + WindowWidth: 800, + WindowHeight: 800, + WindowOpacity: 0.9, + CaptureDeviceIndex: 0, + SampleRate: 192000, + RingBufferSize: 192000, + ReadBufferSize: 192000, + Gain: 1, + LineOpacity: 50, + LineThickness: 2, } var Config ConfigS diff --git a/main.go b/main.go index 12b59c2..cd8c26b 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,7 @@ func main() { scale := min(config.Config.WindowWidth, config.Config.WindowHeight) / 2 rl.InitWindow(config.Config.WindowWidth, config.Config.WindowHeight, "xyosc") defer rl.CloseWindow() - rl.SetWindowOpacity(0.5) + rl.SetWindowOpacity(config.Config.WindowOpacity) rl.SetConfigFlags(rl.FlagWindowTransparent) rl.SetConfigFlags(rl.FlagMsaa4xHint) rl.SetWindowState(rl.FlagWindowUndecorated)