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

@ -17,6 +17,8 @@ type ConfigS struct {
TargetFPS int32 TargetFPS int32
WindowWidth int32 WindowWidth int32
WindowHeight int32 WindowHeight int32
WindowOpacity float32
CaptureDeviceIndex int
SampleRate uint32 SampleRate uint32
RingBufferSize uint32 RingBufferSize uint32
ReadBufferSize uint32 ReadBufferSize uint32
@ -30,8 +32,10 @@ var DefaultConfig = ConfigS{
TargetFPS: 60, TargetFPS: 60,
WindowWidth: 800, WindowWidth: 800,
WindowHeight: 800, WindowHeight: 800,
WindowOpacity: 0.9,
CaptureDeviceIndex: 0,
SampleRate: 192000, SampleRate: 192000,
RingBufferSize: 192000 * 4, RingBufferSize: 192000,
ReadBufferSize: 192000, ReadBufferSize: 192000,
Gain: 1, Gain: 1,
LineOpacity: 50, LineOpacity: 50,

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)