This commit is contained in:
Louis Dalibard 2025-01-16 22:33:22 +01:00
parent 812323bc09
commit 61c3e9ab53
4 changed files with 0 additions and 175 deletions

View File

@ -15,7 +15,6 @@ import (
"xyosc/icons" "xyosc/icons"
"xyosc/media" "xyosc/media"
"xyosc/particles" "xyosc/particles"
"xyosc/signalprocessing"
"fmt" "fmt"
@ -27,7 +26,6 @@ import (
"github.com/hajimehoshi/ebiten/v2/vector" "github.com/hajimehoshi/ebiten/v2/vector"
"github.com/mjibson/go-dsp/fft" "github.com/mjibson/go-dsp/fft"
"github.com/mjibson/go-dsp/window"
) )
type Game struct { 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, &AX)
binary.Read(audio.SampleRingBuffer, binary.NativeEndian, &AY) binary.Read(audio.SampleRingBuffer, binary.NativeEndian, &AY)
} }
window.Apply(FFTBuffer, signalprocessing.CachedWindowFunction)
X := fft.FFTReal(FFTBuffer) X := fft.FFTReal(FFTBuffer)
r, θ := cmplx.Polar(X[1]) r, θ := cmplx.Polar(X[1])
maxR := r maxR := r
@ -167,7 +164,6 @@ func main() {
audio.Init() audio.Init()
fonts.Init() fonts.Init()
icons.Init() icons.Init()
signalprocessing.Init()
go audio.Start() go audio.Start()
go media.Start() go media.Start()
ebiten.SetWindowIcon([]image.Image{icons.WindowIcon48, icons.WindowIcon32, icons.WindowIcon16}) ebiten.SetWindowIcon([]image.Image{icons.WindowIcon48, icons.WindowIcon32, icons.WindowIcon16})

View File

@ -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
}

View File

@ -1,152 +0,0 @@
/*
* Copyright (c) 2012 Matt Jibson <matt.jibson@gmail.com>
*
* 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
}

1
vendor/modules.txt vendored
View File

@ -108,7 +108,6 @@ github.com/leberKleber/go-mpris
## explicit ## explicit
github.com/mjibson/go-dsp/dsputils github.com/mjibson/go-dsp/dsputils
github.com/mjibson/go-dsp/fft github.com/mjibson/go-dsp/fft
github.com/mjibson/go-dsp/window
# github.com/smallnest/ringbuffer v0.0.0-20241129171057-356c688ba81d # github.com/smallnest/ringbuffer v0.0.0-20241129171057-356c688ba81d
## explicit; go 1.19 ## explicit; go 1.19
github.com/smallnest/ringbuffer github.com/smallnest/ringbuffer