diff --git a/main.go b/main.go index 8bb82a9..6a3ecb1 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,6 @@ import ( "xyosc/icons" "xyosc/media" "xyosc/particles" - "xyosc/signalprocessing" "fmt" @@ -27,7 +26,6 @@ import ( "github.com/hajimehoshi/ebiten/v2/vector" "github.com/mjibson/go-dsp/fft" - "github.com/mjibson/go-dsp/window" ) type Game struct { @@ -101,7 +99,6 @@ func (g *Game) Draw(screen *ebiten.Image) { binary.Read(audio.SampleRingBuffer, binary.NativeEndian, &AX) binary.Read(audio.SampleRingBuffer, binary.NativeEndian, &AY) } - window.Apply(FFTBuffer, signalprocessing.CachedWindowFunction) X := fft.FFTReal(FFTBuffer) r, θ := cmplx.Polar(X[1]) maxR := r @@ -167,7 +164,6 @@ func main() { audio.Init() fonts.Init() icons.Init() - signalprocessing.Init() go audio.Start() go media.Start() ebiten.SetWindowIcon([]image.Image{icons.WindowIcon48, icons.WindowIcon32, icons.WindowIcon16}) diff --git a/signalprocessing/signalprocessing.go b/signalprocessing/signalprocessing.go deleted file mode 100644 index 5f171ac..0000000 --- a/signalprocessing/signalprocessing.go +++ /dev/null @@ -1,18 +0,0 @@ -package signalprocessing - -import ( - "xyosc/audio" - "xyosc/config" - - "github.com/mjibson/go-dsp/window" -) - -var HannWindow []float64 - -func Init() { - HannWindow = window.Hann(int(config.Config.ReadBufferSize / audio.SampleSizeInBytes / 2)) -} - -func CachedWindowFunction(u int) []float64 { - return HannWindow -} diff --git a/vendor/github.com/mjibson/go-dsp/window/window.go b/vendor/github.com/mjibson/go-dsp/window/window.go deleted file mode 100644 index 25632d9..0000000 --- a/vendor/github.com/mjibson/go-dsp/window/window.go +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (c) 2012 Matt Jibson - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -// Package window provides window functions for digital signal processing. -package window - -import ( - "math" -) - -// Apply applies the window windowFunction to x. -func Apply(x []float64, windowFunction func(int) []float64) { - for i, w := range windowFunction(len(x)) { - x[i] *= w - } -} - -// Rectangular returns an L-point rectangular window (all values are 1). -func Rectangular(L int) []float64 { - r := make([]float64, L) - - for i := range r { - r[i] = 1 - } - - return r -} - -// Hamming returns an L-point symmetric Hamming window. -// Reference: http://www.mathworks.com/help/signal/ref/hamming.html -func Hamming(L int) []float64 { - r := make([]float64, L) - - if L == 1 { - r[0] = 1 - } else { - N := L - 1 - coef := math.Pi * 2 / float64(N) - for n := 0; n <= N; n++ { - r[n] = 0.54 - 0.46*math.Cos(coef*float64(n)) - } - } - - return r -} - -// Hann returns an L-point Hann window. -// Reference: http://www.mathworks.com/help/signal/ref/hann.html -func Hann(L int) []float64 { - r := make([]float64, L) - - if L == 1 { - r[0] = 1 - } else { - N := L - 1 - coef := 2 * math.Pi / float64(N) - for n := 0; n <= N; n++ { - r[n] = 0.5 * (1 - math.Cos(coef*float64(n))) - } - } - - return r -} - -// Bartlett returns an L-point Bartlett window. -// Reference: http://www.mathworks.com/help/signal/ref/bartlett.html -func Bartlett(L int) []float64 { - r := make([]float64, L) - - if L == 1 { - r[0] = 1 - } else { - N := L - 1 - coef := 2 / float64(N) - n := 0 - for ; n <= N/2; n++ { - r[n] = coef * float64(n) - } - for ; n <= N; n++ { - r[n] = 2 - coef*float64(n) - } - } - - return r -} - -// FlatTop returns an L-point flat top window. -// Reference: http://www.mathworks.com/help/signal/ref/flattopwin.html -func FlatTop(L int) []float64 { - const ( - alpha0 = float64(0.21557895) - alpha1 = float64(0.41663158) - alpha2 = float64(0.277263158) - alpha3 = float64(0.083578947) - alpha4 = float64(0.006947368) - ) - - r := make([]float64, L) - - if L == 1 { - r[0] = 1 - return r - } - - N := L - 1 - coef := 2 * math.Pi / float64(N) - - for n := 0; n <= N; n++ { - factor := float64(n) * coef - - term0 := alpha0 - term1 := alpha1 * math.Cos(factor) - term2 := alpha2 * math.Cos(2*factor) - term3 := alpha3 * math.Cos(3*factor) - term4 := alpha4 * math.Cos(4*factor) - - r[n] = term0 - term1 + term2 - term3 + term4 - } - - return r -} - -// Blackman returns an L-point Blackman window -// Reference: http://www.mathworks.com/help/signal/ref/blackman.html -func Blackman(L int) []float64 { - r := make([]float64, L) - if L == 1 { - r[0] = 1 - } else { - N := L - 1 - for n := 0; n <= N; n++ { - const term0 = 0.42 - term1 := -0.5 * math.Cos(2*math.Pi*float64(n)/float64(N)) - term2 := 0.08 * math.Cos(4*math.Pi*float64(n)/float64(N)) - r[n] = term0 + term1 + term2 - } - } - return r -} diff --git a/vendor/modules.txt b/vendor/modules.txt index f3531bc..13df1c0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -108,7 +108,6 @@ github.com/leberKleber/go-mpris ## explicit github.com/mjibson/go-dsp/dsputils github.com/mjibson/go-dsp/fft -github.com/mjibson/go-dsp/window # github.com/smallnest/ringbuffer v0.0.0-20241129171057-356c688ba81d ## explicit; go 1.19 github.com/smallnest/ringbuffer