# Can anyone please explain the flow of this code. (Beginner)

I’m learning how to make this music visualisation work. I understood the idea but I’m not able to understand how the rectangle falls down in this case. Will be great if someone could explain how the process happens.

This is a visualization of the frequency composing the sound example.
Before to understand this code and start to make visualization for music in OF, you need some basic theory.

http://www.webarchive.org.uk/wayback/archive/20160101151542/http://www.jiscdigitalmedia.ac.uk/guide/an-introduction-to-digital-audio

http://openframeworks.cc/ofBook/chapters/sound.html

If you are more into online courses, this is pretty good in my opinion https://www.kadenze.com/courses/creative-programming-for-audiovisual-art/info. The examples are in javascript but the teacher is also the creator of Maximilian, and you can traduce most of the examples to cpp using ofxMaxim.

Hi I went through the tutorials. Thanks a lot.
My problem is still with couple of codes out there like “spectrum = sprectrum[i]*0.97”
I’m not able to understand how the rectangle in the video is falling down slowly.
Anyway thanks a lot for the suggestion, will try more

Hi, there are actually two important things happening.
you have

``````spectrum[i] *= 0.97;
spectrum[i] = max(spectrum[i], val[i]);
``````

so, the spectrum array, because declared in ofApp.h, keeps it’s data after every update/draw cycle, so at the next cycle you still have whatever you had put into before.

So the first line will slightly decrease the value that you stored on it. This means that cycle after cycle it will diminish. As the rectangles are drawn based on this number, it looks like it is falling very slowly.
If you change the 0.97 for 1, it will never decrease and it will remain just as the highest value that you handed to it. on the other hand, if it was 0, there will be no smoothing at all. Try using the mouse or a GUI to modify this value and see what happens.

The second line in this code is also super important.
This will update the value on spectrum only if this new value is larger that what is stored in spectrum.

hope it helps

1 Like

Thanks a lot Roy. Now it makes perfect sense to me