might be more efficient

This commit is contained in:
Louis Dalibard 2025-01-16 22:56:00 +01:00
parent bc5597c436
commit 5d3a570c29

15
main.go
View File

@ -23,7 +23,7 @@ import (
"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"
"github.com/MicahParks/peakdetect" "github.com/goccmack/godsp/peaks"
) )
type Game struct { type Game struct {
@ -97,15 +97,10 @@ func (g *Game) Draw(screen *ebiten.Image) {
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)
} }
const (
lag = 200 separator := 1000
threshold = 5 indices := peaks.Get(FFTBuffer, int(separator))
influence = 0 offset := uint32(indices[0])
)
detector := peakdetect.NewPeakDetector()
detector.Initialize(influence, threshold, FFTBuffer[:lag])
nextDataPoints := FFTBuffer[lag:]
offset := uint32(0)
for i, newPoint := range nextDataPoints { for i, newPoint := range nextDataPoints {
signal := detector.Next(newPoint) signal := detector.Next(newPoint)
switch signal { switch signal {