From 98dcc095be7a24e02b704f47cdcfd1b8ac34a38e Mon Sep 17 00:00:00 2001 From: Louis Dalibard Date: Fri, 17 Jan 2025 14:45:54 +0100 Subject: [PATCH] yes --- config/config.go | 6 ++++++ main.go | 23 ++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index 8d5ef99..0839506 100644 --- a/config/config.go +++ b/config/config.go @@ -39,6 +39,9 @@ type ConfigS struct { DefaultToSingleChannel bool PeakDetectSeparator int SingleChannelWindow uint32 + PeriodCrop bool + PeriodCropCount int + PeriodCropLoopOverCount uint32 } var DefaultConfig = ConfigS{ @@ -67,6 +70,9 @@ var DefaultConfig = ConfigS{ DefaultToSingleChannel: false, PeakDetectSeparator: 100, SingleChannelWindow: 1200, + PeriodCrop: true, + PeriodCropCount: 2, + PeriodCropLoopOverCount: 1, } var Config ConfigS diff --git a/main.go b/main.go index 3022d34..aa8a600 100644 --- a/main.go +++ b/main.go @@ -101,11 +101,24 @@ func (g *Game) Draw(screen *ebiten.Image) { indices := peaks.Get(FFTBuffer, config.Config.PeakDetectSeparator) sort.Ints(indices) - offset := uint32(indices[0]) - for i := uint32(0); i < numSamples-1; i++ { - fAX := float32(FFTBuffer[(i+offset)%numSamples]) * config.Config.Gain * float32(scale) - fBX := float32(FFTBuffer[(i+1+offset)%numSamples]) * config.Config.Gain * float32(scale) - vector.StrokeLine(screen, float32(config.Config.WindowWidth)*float32(i%config.Config.SingleChannelWindow)/float32(config.Config.SingleChannelWindow), float32(config.Config.WindowHeight/2)+fAX, float32(config.Config.WindowWidth)*float32(i%config.Config.SingleChannelWindow+1)/float32(config.Config.SingleChannelWindow), float32(config.Config.WindowHeight/2)+fBX, config.Config.LineThickness, config.ThirdColorAdj, true) + offset := uint32(0) + if len(indices) != 0 { + offset = uint32(indices[0]) + } + if config.Config.PeriodCrop && len(indices) > 1 { + lastPeriodOffset := uint32(indices[min(len(indices)-1, config.Config.PeriodCropCount)]) + samplesPerCrop := lastPeriodOffset - offset + for i := uint32(0); i < min(numSamples, samplesPerCrop*config.Config.PeriodCropLoopOverCount)-1; i++ { + fAX := float32(FFTBuffer[(i+offset)%samplesPerCrop]) * config.Config.Gain * float32(scale) + fBX := float32(FFTBuffer[(i+1+offset)%samplesPerCrop]) * config.Config.Gain * float32(scale) + vector.StrokeLine(screen, float32(config.Config.WindowWidth)*float32(i%samplesPerCrop)/float32(samplesPerCrop), float32(config.Config.WindowHeight/2)+fAX, float32(config.Config.WindowWidth)*float32(i%samplesPerCrop+1)/float32(samplesPerCrop), float32(config.Config.WindowHeight/2)+fBX, config.Config.LineThickness, config.ThirdColorAdj, true) + } + } else { + for i := uint32(0); i < numSamples-1; i++ { + fAX := float32(FFTBuffer[(i+offset)%numSamples]) * config.Config.Gain * float32(scale) + fBX := float32(FFTBuffer[(i+1+offset)%numSamples]) * config.Config.Gain * float32(scale) + vector.StrokeLine(screen, float32(config.Config.WindowWidth)*float32(i%config.Config.SingleChannelWindow)/float32(config.Config.SingleChannelWindow), float32(config.Config.WindowHeight/2)+fAX, float32(config.Config.WindowWidth)*float32(i%config.Config.SingleChannelWindow+1)/float32(config.Config.SingleChannelWindow), float32(config.Config.WindowHeight/2)+fBX, config.Config.LineThickness, config.ThirdColorAdj, true) + } } }