Skip to content

Commit

Permalink
Fix EQ crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
GuglioIsStupid committed May 6, 2024
1 parent 2ced6bd commit 294be57
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/love/data/songs/2hot/2hot-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"t": 8901.0989010989,
"e": "FocusCamera",
"v": { "char": 2, "x": 100, "y": 105 }
"v": { "char": 2, "x": 0, "y": 0 }
},
{
"t": 10549.4505494506,
Expand All @@ -33,7 +33,7 @@
{
"t": 40549.0989010989,
"e": "FocusCamera",
"v": { "char": 2, "x": 100, "y": 105 }
"v": { "char": 2, "x": 0, "y": 0 }
},
{
"t": 42197.4505494506,
Expand All @@ -52,7 +52,7 @@
{
"t": 51098.0989010989,
"e": "FocusCamera",
"v": { "char": 2, "x": 100, "y": 105 }
"v": { "char": 2, "x": 0, "y": 0 }
},
{
"t": 52746.4505494506,
Expand All @@ -79,7 +79,7 @@
{
"t": 80109.8901098901,
"e": "FocusCamera",
"v": { "char": 2, "x": 100, "y": 105 }
"v": { "char": 2, "x": 0, "y": 0 }
},
{
"t": 81758.2417582417,
Expand All @@ -96,7 +96,7 @@
{
"t": 85384.0989010989,
"e": "FocusCamera",
"v": { "char": 2, "x": 100, "y": 105 }
"v": { "char": 2, "x": 0, "y": 0 }
},
{
"t": 87032.4505494505,
Expand All @@ -123,7 +123,7 @@
{
"t": 117032.098901099,
"e": "FocusCamera",
"v": { "char": 2, "x": 100, "y": 105 }
"v": { "char": 2, "x": 0, "y": 0 }
},
{
"t": 118680.450549451,
Expand Down
26 changes: 18 additions & 8 deletions src/love/lib/fft/ffthread.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local fftSize = ...
local fft = require("lib.fft.luafft")
local inChannel = love.thread.getChannel("toFFT")
local util = require("modules.util")

local fftSizeInv = 1 / fftSize -- Because multiplication is slightly faster
local function postprocess(x)
Expand All @@ -12,13 +13,22 @@ while true do
-- Get input
local toFFT = inChannel:pop()
-- Perform FFT
local res = fft.fft(toFFT, false)
-- Process the results to build an intuitive FFT result
local fftArray = {}
for i = 1, fftSize / 2 do
fftArray[i] = postprocess(res[i]:abs() + res[#res-i+1]:abs())
end
-- Send the result to the main thread
love.thread.getChannel("fft"):push(fftArray)
local res = {}
util.tryExcept(
function()
res = fft.fft(toFFT, false)

-- Process the results to build an intuitive FFT result
local fftArray = {}
for i = 1, fftSize / 2 do
fftArray[i] = postprocess(res[i]:abs() + res[#res-i+1]:abs())
end
-- Send the result to the main thread
love.thread.getChannel("fft"):push(fftArray)
end,
function(err)
love.thread.getChannel("fft"):push({})
end
)
end
end
2 changes: 1 addition & 1 deletion src/love/lib/fft/lovefft.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function loveFFT:push() -- Launch a new FFT computation in a separate thread usi
for i = 1, self.fftSize do
toFFT[i] = 0
for j = 1, self.channelCount do
toFFT[i] = toFFT[i] + self.soundData:getSample(sample + i - 1, j)
util.tryExcept(function() toFFT[i] = toFFT[i] + self.soundData:getSample(sample + i - 1, j) end)
end
end
-- Send to thread
Expand Down
7 changes: 7 additions & 0 deletions src/love/modules/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ function table.mergeValues(t1, t2)
return t1
end

function util.tryExcept(try, except)
local status, err = pcall(try)
if not status and except then
except(err)
end
end

-- God like coding
--[[
function util.🍰(🥰, 🥵)
Expand Down

0 comments on commit 294be57

Please sign in to comment.