We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all, so I've made a real-time music visualizer that works very well. Except that it is very slow due to the large number of operations it does on the pixels and objects in the program. Any pointers or suggestions as to how I can speed this up?
Cheers
Answers
http://forum.Processing.org/two/discussions/tagged?Tag=thread()
Without seeing the code? Not really.
Try opengl mode?
Hi thanks for the reply. The code is too long to post here, but I have somewhere around 50000 pvector objects moving at all times plus an FFT object. I have my main functions which calculate object movement running on separate threads, but the output is still laggy at 30 fps. Not sure if there is a good way to use multi-threading for such a high volume of calculations.
synchronized ()
their access.Again, without the code we are guessing. Screenshot? Video?
And threading is all very well but the processor has a maximum and it doesn't matter how you share the work out it won't go beyond that.
Alright, so here is the part off the code that is giving me the most trouble. It is supposed to be a simulation of a river and it will react to the bass frequencies of a minim audio input.
The code is a bit messy, let me know if a part of it doesnt make sense and I'll add comments
Yikes, just did a quick glance there! :-&
1 thing I noticed you're relying on point(), which is very slow! ~:>
You should replace it w/ pixels[] instead: https://Processing.org/reference/pixels.html
Hey, I will add more comments and try to clean up the code. How do I use pixel[] for a 3D simulation?
You should definitely test the different renderers. I also wrote a programme for visualising music (https://vimeo.com/136952485) and even all my objects are basic 2D graphics I use the P3D renderer because it’s way faster for me.
Could you benchmark something for me.
Make your own vector with only a x, y and z. (methods and constructors are also ok) Processing has an array in it that is never used. This makes the object larger in memory. I'm wondering how much benefit you will gain.
Indeed, removing that NEVER used array field, each PVector object would drop from the current implementation of 32 bytes down to 24 bytes! It's 8 bytes saved for each 1! 8->
All those years I'm here, never seen any1 calling the unknown method array()!
For larger containers like IntList, Table, JSONArray, etc., it is indeed somewhat beneficial to cache the array the 1st time it's requested and keep returning it for future later on requests.
However, PVector is a very light container which are regularly instantiated several times.
It is so in total contrast to the heavier 1s, where most sketches merely instantiate a couple of them.
So it's not a big deal whether they happen to have some extra cache fields. ^#(^
I'm curious, if the JVM detects the array of a PVector is never accessed in code, will it remove it?
null
.I tried P3D which made very little difference. As far as making my own 3D vector class I don't think that will make a big difference either; I tried converting one of my 2D visualizers into a real-time application and it has the same behavior. In this sketch, I use PShape objects which are rendered during setup and only scaled in realtime so I'm wondering if there is a problem with how I'm analyzing the audio and calculating fft values that's slowing things down?
Is this for live visuals?
I think you're going to have to chose between real time rendering and video exporting - if it's live you'll have to skip the recording, if it's not live them you can preprocess the fft data and use that as input - not real time but the resulting video will look as though it is
Yes its for live visuals. I have a separate template for offline visuals and the video export object is from there; never bothered to take it out lol. I'll try it without that tonight to see if it makes a difference [-O<
On my five year old laptop the above sketch runs at 30 fps with video export disabled. I'd say that is decent.
Maybe you need to get into shaders and related magic so you can use the GPU instead of the CPU?
Thanks for trying it! Yes, 30 fps is decent. I've looked at some tutorials for shaders and OpenGL; its still a bit confusing but its on my list. Any tutorial suggestions?