This commit is contained in:
Louis Dalibard 2025-01-17 14:45:54 +01:00
parent 71dfba131f
commit 98dcc095be
2 changed files with 24 additions and 5 deletions

View File

@ -39,6 +39,9 @@ type ConfigS struct {
DefaultToSingleChannel bool DefaultToSingleChannel bool
PeakDetectSeparator int PeakDetectSeparator int
SingleChannelWindow uint32 SingleChannelWindow uint32
PeriodCrop bool
PeriodCropCount int
PeriodCropLoopOverCount uint32
} }
var DefaultConfig = ConfigS{ var DefaultConfig = ConfigS{
@ -67,6 +70,9 @@ var DefaultConfig = ConfigS{
DefaultToSingleChannel: false, DefaultToSingleChannel: false,
PeakDetectSeparator: 100, PeakDetectSeparator: 100,
SingleChannelWindow: 1200, SingleChannelWindow: 1200,
PeriodCrop: true,
PeriodCropCount: 2,
PeriodCropLoopOverCount: 1,
} }
var Config ConfigS var Config ConfigS

15
main.go
View File

@ -101,13 +101,26 @@ func (g *Game) Draw(screen *ebiten.Image) {
indices := peaks.Get(FFTBuffer, config.Config.PeakDetectSeparator) indices := peaks.Get(FFTBuffer, config.Config.PeakDetectSeparator)
sort.Ints(indices) sort.Ints(indices)
offset := uint32(indices[0]) 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++ { for i := uint32(0); i < numSamples-1; i++ {
fAX := float32(FFTBuffer[(i+offset)%numSamples]) * config.Config.Gain * float32(scale) fAX := float32(FFTBuffer[(i+offset)%numSamples]) * config.Config.Gain * float32(scale)
fBX := float32(FFTBuffer[(i+1+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) 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)
} }
} }
}
//audio.SampleRingBuffer.Reset() //audio.SampleRingBuffer.Reset()
if config.Config.FPSCounter { if config.Config.FPSCounter {