hopefully this works on the first try

This commit is contained in:
Louis Dalibard 2025-01-16 21:25:11 +01:00
parent 5ae5cc803a
commit 2e71a38944
3 changed files with 65 additions and 43 deletions

View File

@ -72,6 +72,8 @@ var ThirdColorAdj color.RGBA
var watcher *fsnotify.Watcher var watcher *fsnotify.Watcher
var SingleChannel bool = false
func Init() { func Init() {
configPath := configdir.LocalConfig("ontake", "xyosc") configPath := configdir.LocalConfig("ontake", "xyosc")
err := configdir.MakePath(configPath) // Ensure it exists. err := configdir.MakePath(configPath) // Ensure it exists.

19
main.go
View File

@ -19,6 +19,7 @@ import (
"github.com/chewxy/math32" "github.com/chewxy/math32"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil" "github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/hajimehoshi/ebiten/v2/text/v2" "github.com/hajimehoshi/ebiten/v2/text/v2"
"github.com/hajimehoshi/ebiten/v2/vector" "github.com/hajimehoshi/ebiten/v2/vector"
) )
@ -36,6 +37,11 @@ func (g *Game) Draw(screen *ebiten.Image) {
var AY float32 var AY float32
var BX float32 var BX float32
var BY float32 var BY float32
var FFTBuffer = make([]float32, config.Config.ReadBufferSize/audio.SampleSizeInBytes/2)
if inpututil.IsKeyJustPressed(ebiten.KeyF) {
config.SingleChannel = !config.SingleChannel
}
if config.SingleChannel {
binary.Read(audio.SampleRingBuffer, binary.NativeEndian, &AX) binary.Read(audio.SampleRingBuffer, binary.NativeEndian, &AX)
binary.Read(audio.SampleRingBuffer, binary.NativeEndian, &AY) binary.Read(audio.SampleRingBuffer, binary.NativeEndian, &AY)
S := float32(0) S := float32(0)
@ -82,6 +88,18 @@ func (g *Game) Draw(screen *ebiten.Image) {
particles.Particles[i].VX += (config.Config.ParticleAcceleration*S - speed*config.Config.ParticleDrag) * particle.X / norm / float32(ebiten.ActualTPS()) particles.Particles[i].VX += (config.Config.ParticleAcceleration*S - speed*config.Config.ParticleDrag) * particle.X / norm / float32(ebiten.ActualTPS())
particles.Particles[i].VY += (config.Config.ParticleAcceleration*S - speed*config.Config.ParticleDrag) * particle.Y / norm / float32(ebiten.ActualTPS()) particles.Particles[i].VY += (config.Config.ParticleAcceleration*S - speed*config.Config.ParticleDrag) * particle.Y / norm / float32(ebiten.ActualTPS())
} }
} else {
for i := uint32(0); i < config.Config.ReadBufferSize/audio.SampleSizeInBytes/2; i++ {
FFTBuffer[i] = AX
binary.Read(audio.SampleRingBuffer, binary.NativeEndian, &AX)
binary.Read(audio.SampleRingBuffer, binary.NativeEndian, &AY)
}
for i := uint32(0); i < config.Config.ReadBufferSize/audio.SampleSizeInBytes/2-1; i++ {
fAX := float32(FFTBuffer[i]) * config.Config.Gain * float32(scale)
fBX := float32(FFTBuffer[i+1]) * config.Config.Gain * float32(scale)
vector.StrokeLine(screen, float32(config.Config.WindowWidth)*float32(i)/float32(config.Config.ReadBufferSize/audio.SampleSizeInBytes/2), float32(config.Config.WindowHeight/2)+fAX, float32(config.Config.WindowWidth)*float32(i+1)/float32(config.Config.ReadBufferSize/audio.SampleSizeInBytes/2), float32(config.Config.WindowHeight/2)+fBX, config.Config.LineThickness, config.ThirdColorAdj, true)
}
}
//audio.SampleRingBuffer.Reset() //audio.SampleRingBuffer.Reset()
if config.Config.FPSCounter { if config.Config.FPSCounter {
@ -115,6 +133,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
Size: 32, Size: 32,
}, op) }, op)
} }
} }
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) { func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {

1
vendor/modules.txt vendored
View File

@ -53,6 +53,7 @@ github.com/godbus/dbus/v5
## explicit; go 1.22.0 ## explicit; go 1.22.0
github.com/hajimehoshi/ebiten/v2 github.com/hajimehoshi/ebiten/v2
github.com/hajimehoshi/ebiten/v2/ebitenutil github.com/hajimehoshi/ebiten/v2/ebitenutil
github.com/hajimehoshi/ebiten/v2/inpututil
github.com/hajimehoshi/ebiten/v2/internal/affine github.com/hajimehoshi/ebiten/v2/internal/affine
github.com/hajimehoshi/ebiten/v2/internal/atlas github.com/hajimehoshi/ebiten/v2/internal/atlas
github.com/hajimehoshi/ebiten/v2/internal/buffered github.com/hajimehoshi/ebiten/v2/internal/buffered