mirror of
https://github.com/make-42/xyosc
synced 2025-01-18 18:57:10 +01:00
yes
This commit is contained in:
parent
95f09407b2
commit
b95a50dec6
@ -76,6 +76,8 @@ var watcher *fsnotify.Watcher
|
|||||||
|
|
||||||
var SingleChannel bool = false
|
var SingleChannel bool = false
|
||||||
|
|
||||||
|
var HannWindow []float64
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
configPath := configdir.LocalConfig("ontake", "xyosc")
|
configPath := configdir.LocalConfig("ontake", "xyosc")
|
||||||
err := configdir.MakePath(configPath) // Ensure it exists.
|
err := configdir.MakePath(configPath) // Ensure it exists.
|
||||||
@ -101,8 +103,9 @@ func Init() {
|
|||||||
|
|
||||||
decoder := yaml.NewDecoder(fh)
|
decoder := yaml.NewDecoder(fh)
|
||||||
decoder.Decode(&Config)
|
decoder.Decode(&Config)
|
||||||
SingleChannel = Config.DefaultToSingleChannel
|
|
||||||
}
|
}
|
||||||
|
SingleChannel = Config.DefaultToSingleChannel
|
||||||
|
|
||||||
// Get pywal accent color
|
// Get pywal accent color
|
||||||
watcher, err = fsnotify.NewWatcher()
|
watcher, err = fsnotify.NewWatcher()
|
||||||
|
3
main.go
3
main.go
@ -15,6 +15,7 @@ import (
|
|||||||
"xyosc/icons"
|
"xyosc/icons"
|
||||||
"xyosc/media"
|
"xyosc/media"
|
||||||
"xyosc/particles"
|
"xyosc/particles"
|
||||||
|
"xyosc/signalprocessing"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ 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 {
|
||||||
@ -99,6 +101,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
FFTBuffer = window.Apply(FFTBuffer, signalprocessing.HannWindow)
|
||||||
X := fft.FFTReal(FFTBuffer)
|
X := fft.FFTReal(FFTBuffer)
|
||||||
r, θ := cmplx.Polar(X[1])
|
r, θ := cmplx.Polar(X[1])
|
||||||
maxR := r
|
maxR := r
|
||||||
|
14
signalprocessing/signalprocessing.go
Normal file
14
signalprocessing/signalprocessing.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package signalprocessing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"xyosc/audio"
|
||||||
|
"xyosc/config"
|
||||||
|
|
||||||
|
"github.com/mjibson/go-dsp/window"
|
||||||
|
)
|
||||||
|
|
||||||
|
var HannWindow []float64
|
||||||
|
|
||||||
|
func Init() {
|
||||||
|
HannWindow = window.Hann(config.Config.ReadBufferSize / audio.SampleSizeInBytes / 2)
|
||||||
|
}
|
152
vendor/github.com/mjibson/go-dsp/window/window.go
generated
vendored
Normal file
152
vendor/github.com/mjibson/go-dsp/window/window.go
generated
vendored
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
/*
|
||||||
|
* 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
1
vendor/modules.txt
vendored
@ -108,6 +108,7 @@ 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
|
||||||
|
Loading…
Reference in New Issue
Block a user