keijiro / Lasp

Low-latency Audio Signal Processing plugin for Unity
The Unlicense
1.57k stars 121 forks source link

Modifying FftBuffer to output the magnitude and phase #45

Closed robclouth closed 3 years ago

robclouth commented 3 years ago

In the Postprocess Job you do this:

 public void Execute(int i)
      {
        var x = X[i];
        var l = math.float2(math.length(x.xy), math.length(x.zw));
        O[i] = (MathUtils.dBFS(l * DivN) - F) * DivR;
      }

I assume you're calculating the magnitude with math.length(x.xy) but what is math.length(x.zw)? Why is each element of x float4? And why O is float2 if it's just magnitudes?

keijiro commented 3 years ago

I can't remember it correctly (I wrote it 1.5 years ago), but I think it's just a SIMD optimization. I mean, calculating float4 = float4 + float4 is faster than calculating float = float + float 4 times.

Originally, X was implemented as as a float2 array, and O was just a float array. I reinterpret them as float4 and float2 to utilize SIMD.

keijiro commented 3 years ago

I'm closing this issue now. Please feel free to reopen it for further problems.

robclouth commented 3 years ago

So it's just an optimization thing. Thanks :-)

On Thu, 30 Sep 2021, 15:58 Keijiro Takahashi, @.***> wrote:

Closed #45 https://github.com/keijiro/Lasp/issues/45.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/keijiro/Lasp/issues/45#event-5387941357, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJP3IR2MNVL5AVLAK6ZHTLUERUJBANCNFSM5FCHJ5UA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.