WAC icon indicating copy to clipboard operation
WAC copied to clipboard

Signal has a Highly Volatile Noise Pattern

Open ansonphong opened this issue 6 years ago • 18 comments

Hi @kwstasg, Great plugin by the way, I really like this a lot and am very happy that it exists. Overall the implementation of the plugin was smooth and seamless and integrated as expected.

I'm having an issue with the incoming data from the Get Frequency Array node, which is sometimes, and sporadically for sometimes short and sometimes long periods of time, returning very uncharacteristically high values, sometimes, creating like a static noise pattern.

This is how I'm getting the values:

image

The resulting noise is coming on and off like this, sometimes on, sometimes off. The noise is marked with X, and the normal operation is marked with a check mark.

image

To visualize on the spectrum analyzer what it looks like is this when the noise is happening:

image

Behavior is very random like this, usually within the first few seconds or so of playing it's not an issue, then it creeps in. It seems to happen almost every time after a track switches, and it goes from empty sound back to a song playing.

Any help fixing this or ideas so I can fix it would be very helpful. Thanks!

ansonphong avatar Dec 21 '18 02:12 ansonphong

Is it possible that this could be caused by the buffer not being cleared between long tick times? It seems as though the issue is made worse with lower frame rates / longer frame deltas.

ansonphong avatar Dec 22 '18 09:12 ansonphong

@kwstasg Any ideas about this?

ansonphong avatar Jan 03 '19 08:01 ansonphong

do you ever find a fix? I tried editing a few things in the plugin but i'm not good with audio/c++. So I was just guessing when editing the source files.

The only thing I found was calling the get freq node every other tick in blueprint seemed to help. As well as changing my audio device (outside of ue4) to 96k instead of 48/44.1.

I think the plugin's output freq might be improved if the plugin was ticked at a set rate outside of ue4's actor ticking, or maybe substepped. But I only know a little c++ right now.

gallonmate avatar Jan 28 '19 04:01 gallonmate

@gallonmate To your point, we managed to get the volatile breakouts under control by setting a timer to collect the data at a consistent 90hz on the audio thread, and then on tick in the engine collect an average of the last X values in the buffer. Once it's more refined we plan to share a fork, will let you know when that's available.

ansonphong avatar Feb 12 '19 21:02 ansonphong

@gallonmate To your point, we managed to get the volatile breakouts under control by setting a timer to collect the data at a consistent 90hz on the audio thread, and then on tick in the engine collect an average of the last X values in the buffer. Once it's more refined we plan to share a fork, will let you know when that's available.

Did you end up having any luck with getting this to a shareable state? I'd love at least some pointers as I am having the same issue with my little personal project. I tried implementing a rolling average of the past N ticks which helps smooth things out, but the spikes and erratic/unexpected behavior completely drown out the correct sound information.

It is especially strange as randomly, it will work perfectly in the viewport. Then it will go back to chaos when I re launch or make and edit and run it in the viewport again. I changed my output audio device to 96k instead of 48k and that seems to have helped in the viewport at least some, however I still have had no luck with packaging this. It completely breaks, reacting very strangely to any audio and not breaking up according to the frequency bands I defined.

Any help would be extremely appreciated!

NoviceInDisguise avatar Aug 02 '19 05:08 NoviceInDisguise

I have also since fixed/solved the noise in the project as it is, basically one line of code to edit. The real problem was the sample pointer in the audio capture worker and the actually audio buffer index's aren't always in sync, which is what we see as "noise". The fix/workaround is to reset the "SamplePtr" to 0 instead of incrementing it.

I'd still like to see @ansonphong verison. In fact I would like someone to really improve the plugin altogether. The resolution is a little limited if you want to get smaller chunk/bins for analysis.

It's been many months since I've even looked at the plugin code. So I'd have to dig into it again to post the exact working code. If you can't fix it yourself from this info, I can post the exact info or entire working plugin. Just Tag me after like a few days or a week in here or you can find me online in the Unreal Discord, same username.

gallonmate avatar Aug 02 '19 22:08 gallonmate

I have also since fixed/solved the noise in the project as it is, basically one line of code to edit. The real problem was the sample pointer in the audio capture worker and the actually audio buffer index's aren't always in sync, which is what we see as "noise". The fix/workaround is to reset the "SamplePtr" to 0 instead of incrementing it.

Do you still have a working version of the fix? If you do I'm interested in a copy, compiled if possible, i can't comiple my copy, it keeps throwing out random errors now that i have upgraded from VS2017 to VS2019 and updated my unreal project to unreal 4.23

MaxPowerz avatar Oct 01 '19 19:10 MaxPowerz

Also is the fix you mentioned line 224 in AudioCaptureWorker.cpp
SamplePtr++; And your suggesting change it to SamplePtr=0;

MaxPowerz avatar Oct 01 '19 19:10 MaxPowerz

Do you still have a working version of the fix? If you do I'm interested in a copy, compiled if possible, i can't comiple my copy, it keeps throwing out random errors now that i have upgraded from VS2017 to VS2019 and updated my unreal project to unreal 4.23

4.22 and 4.23 had major updates to the engine, so there are probably required changes to the entire plugin in order to compile at all. I'm still using 4.20. My fix would only work for 4.20 (maybe 4.21 if you're lucky). As for setting Sample Ptr to 0, yes line 224 is where the fix first worked. I had also changed a bunch of things after fixing it, but I don't really remember anymore since it's been many months since I touched the project. I can post the code/working plugin for 4.20 if someone keeps reminding me.

gallonmate avatar Oct 01 '19 20:10 gallonmate

It works well in 4.21.2 in the editor https://www.youtube.com/watch?v=UJql0Y0mHSw

MaxPowerz avatar Oct 01 '19 23:10 MaxPowerz

I can post the code/working plugin for 4.20 if someone keeps reminding me.

No need, I fixed it using your fix and finally found the right Toolchain and SDK combo to get it to compile with 4.21.2 and 4.20.3 Thank-you for the advice and the solution to fixing the noise issue.

I added this at line 226 in AudioCaptureWorker.cpp and it solved the desync/noise issue.

else
{
SamplePtr=0;
}

WAC 4.21.2 Fixed.zip 10.1MB https://mega.nz/#!VhFDUITD!XT3nvPEX2b_PbJpXydOIRP8zFuI8NJ0QpxVhGejVgvY

MaxPowerz avatar Oct 02 '19 12:10 MaxPowerz

It will load in the editor in 4.21.2 but it won't build due to it being made for 4.20. So I added a compiled version for 4.20.3 for anyone else who wants it, it builds fine in 4.20.3

Here's a link to a fixed version for 4.20.3 WAC 4.20.3 Fixed.zip 8.4MB https://mega.nz/#!48txDQZA!s0ypH8a0bJz8W2Vvefeff0viAOZWD_at581Ey9TsOfI

MaxPowerz avatar Oct 02 '19 15:10 MaxPowerz

It looks incredible without the noise. I have to rebuild everything from scratch because nothing will import from 4.21 backward to 4.20

Here's a video without the noise in the signal :) https://www.youtube.com/watch?v=eXnlNefeHWc&feature=youtu.be&fbclid=IwAR0H70LnK4MCOCBdLF37AFwtKfLfXy4iZD0tyX7cWdJRjHgJB19SJEBQivc

MaxPowerz avatar Oct 04 '19 20:10 MaxPowerz

Thank you all guys for your interest in this plugin and for your contribution in fixing this bug, i want to apologise for my absense, but everything is in order again plugin updated to latest ue release and fixed what you suggested, Thank you all again!

kwstasg avatar Sep 20 '20 13:09 kwstasg

Great, glad you addressed this. I'm not running on 4.25 yet, though when I upgrade the project I'll test this out. Appreciate it.

The local fix I had to make to get it to work on the previous version is to manually detect and suppress these outbreaks.

The second thing I had to do to get it work properly was to normalize the values added by the frame delta, so that it could have a consistent value range even with a changing framerate.

ansonphong avatar Sep 21 '20 23:09 ansonphong

@kwstasg - Recalling the details now, how I ended up implementing it was by creating a consistent 90Hz tick / timer which re-evaluated the FFT analysis on a regular interval and left the value in a buffer, which was then read at runtime on the game thread in Unreal engine. Have you done anything to address the regularity / normalization of the timing mechanism?

ansonphong avatar Sep 22 '20 06:09 ansonphong

@kwstasg - Recalling the details now, how I ended up implementing it was by creating a consistent 90Hz tick / timer which re-evaluated the FFT analysis on a regular interval and left the value in a buffer, which was then read at runtime on the game thread in Unreal engine. Have you done anything to address the regularity / normalization of the timing mechanism?

you did this through BP or in C++?I mean the tick rate

kwstasg avatar Sep 22 '20 14:09 kwstasg

you did this through BP or in C++?I mean the tick rate

I had done this inside C++, all the source is here:

WAC-Source.zip

The solution ended up working nicely. Feel free to pick any pieces from there if it happens to be useful. If it's too annoying to deal with a ZIP, let me know and I can do a proper fork and make a pull request, though at this point it's likely out of sync with your updates.

ansonphong avatar Sep 24 '20 23:09 ansonphong