How do I get the average volume of the incoming sound of the last second?
in
Core Library Questions
•
2 years ago
Hi there,
I'm quite new to processing, so I would be very glad if anyone can help me with my problem…
I've already searched a lot in this forum but couldn't get the solution.
I'm working on something like a clock which represents and records the volume of the surrounding area. so the sketch has 60 rects per row, 60 rows. so each rect stands for one seconds, the whole sketch represents an hour.
the saturation of the filling depends of the incoming sound (in.mix.level()).
my problem is:
how do I get the average volume of the second? at the moment, processing overwrites the rect every frame, so in the end, after the second, when the position of the next rect changes, you can see only the last value.
at the moment, I have following solution:
- levelColl is my array which should collect the last 60 values
- levelAvg is the average of all values
but now, the values for levelColl[1] up to levelColl[59] are similar and not shifting as it should do, I think…
has anyone an idea, what the problem is??
and the second problem is, just to draw the rect every (current time(!))second. using millis() % 1000 == 0 doesn't work because the millis start when the program is running and I need the real time seconds…
so I tried this but as I realized, it doesn't work (quite clear, because all seconds are integers and % 0 == 0………):
best regards,
stephan
PS: please tell me, if you need to see the whole code!
I'm quite new to processing, so I would be very glad if anyone can help me with my problem…
I've already searched a lot in this forum but couldn't get the solution.
I'm working on something like a clock which represents and records the volume of the surrounding area. so the sketch has 60 rects per row, 60 rows. so each rect stands for one seconds, the whole sketch represents an hour.
the saturation of the filling depends of the incoming sound (in.mix.level()).
my problem is:
how do I get the average volume of the second? at the moment, processing overwrites the rect every frame, so in the end, after the second, when the position of the next rect changes, you can see only the last value.
at the moment, I have following solution:
levelGesamt = 0;
for(int j=1; j < 60; j++)
{
levelColl[j] = levelColl[j-1];
levelGesamt += levelColl[j];
}
levelColl[0] = in.mix.level();
levelGesamt += levelColl[0];
levelAvg = levelGesamt/60.0;
- levelColl is my array which should collect the last 60 values
- levelAvg is the average of all values
but now, the values for levelColl[1] up to levelColl[59] are similar and not shifting as it should do, I think…
has anyone an idea, what the problem is??
and the second problem is, just to draw the rect every (current time(!))second. using millis() % 1000 == 0 doesn't work because the millis start when the program is running and I need the real time seconds…
so I tried this but as I realized, it doesn't work (quite clear, because all seconds are integers and % 0 == 0………):
- if(second() % 1 == 0) {
- ……………
- }
best regards,
stephan
PS: please tell me, if you need to see the whole code!
1