feat: add transparency

This commit is contained in:
Louis Dalibard 2024-10-21 00:07:12 +02:00
parent a777d6da08
commit b687d1622e
3 changed files with 49 additions and 27 deletions

View File

@ -2,6 +2,7 @@ package audio
import ( import (
"fmt" "fmt"
"os"
"xyosc/config" "xyosc/config"
"xyosc/utils" "xyosc/utils"
@ -15,10 +16,8 @@ var SampleSizeInBytes uint32
const format = malgo.FormatF32 const format = malgo.FormatF32
func Init() { func Init() {
deviceConfig := malgo.DefaultDeviceConfig(malgo.Duplex)
SampleRingBuffer = ringbuffer.New(int(config.Config.RingBufferSize)) SampleRingBuffer = ringbuffer.New(int(config.Config.RingBufferSize))
deviceConfig.Capture.Format = format SampleSizeInBytes = uint32(malgo.SampleSizeInBytes(format))
SampleSizeInBytes = uint32(malgo.SampleSizeInBytes(deviceConfig.Capture.Format))
} }
func Start() { func Start() {
@ -31,11 +30,31 @@ func Start() {
ctx.Free() 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.Format = format
deviceConfig.Capture.Channels = 2 deviceConfig.Capture.Channels = 2
deviceConfig.Capture.DeviceID = infos[config.Config.CaptureDeviceIndex].ID.Pointer()
deviceConfig.SampleRate = config.Config.SampleRate deviceConfig.SampleRate = config.Config.SampleRate
deviceConfig.Alsa.NoMMap = 1 deviceConfig.Alsa.NoMMap = 1
onRecvFrames := func(pSample2, pSample []byte, framecount uint32) { onRecvFrames := func(pSample2, pSample []byte, framecount uint32) {
SampleRingBuffer.Write(pSample) SampleRingBuffer.Write(pSample)
} }
@ -49,7 +68,6 @@ func Start() {
err = device.Start() err = device.Start()
utils.CheckError(err) utils.CheckError(err)
for { select {}
}
//device.Uninit() //device.Uninit()
} }

View File

@ -13,29 +13,33 @@ import (
) )
type ConfigS struct { type ConfigS struct {
FPSCounter bool FPSCounter bool
TargetFPS int32 TargetFPS int32
WindowWidth int32 WindowWidth int32
WindowHeight int32 WindowHeight int32
SampleRate uint32 WindowOpacity float32
RingBufferSize uint32 CaptureDeviceIndex int
ReadBufferSize uint32 SampleRate uint32
Gain float32 RingBufferSize uint32
LineOpacity uint8 ReadBufferSize uint32
LineThickness float32 Gain float32
LineOpacity uint8
LineThickness float32
} }
var DefaultConfig = ConfigS{ var DefaultConfig = ConfigS{
FPSCounter: false, FPSCounter: false,
TargetFPS: 60, TargetFPS: 60,
WindowWidth: 800, WindowWidth: 800,
WindowHeight: 800, WindowHeight: 800,
SampleRate: 192000, WindowOpacity: 0.9,
RingBufferSize: 192000 * 4, CaptureDeviceIndex: 0,
ReadBufferSize: 192000, SampleRate: 192000,
Gain: 1, RingBufferSize: 192000,
LineOpacity: 50, ReadBufferSize: 192000,
LineThickness: 2, Gain: 1,
LineOpacity: 50,
LineThickness: 2,
} }
var Config ConfigS var Config ConfigS

View File

@ -16,7 +16,7 @@ func main() {
scale := min(config.Config.WindowWidth, config.Config.WindowHeight) / 2 scale := min(config.Config.WindowWidth, config.Config.WindowHeight) / 2
rl.InitWindow(config.Config.WindowWidth, config.Config.WindowHeight, "xyosc") rl.InitWindow(config.Config.WindowWidth, config.Config.WindowHeight, "xyosc")
defer rl.CloseWindow() defer rl.CloseWindow()
rl.SetWindowOpacity(0.5) rl.SetWindowOpacity(config.Config.WindowOpacity)
rl.SetConfigFlags(rl.FlagWindowTransparent) rl.SetConfigFlags(rl.FlagWindowTransparent)
rl.SetConfigFlags(rl.FlagMsaa4xHint) rl.SetConfigFlags(rl.FlagMsaa4xHint)
rl.SetWindowState(rl.FlagWindowUndecorated) rl.SetWindowState(rl.FlagWindowUndecorated)