CPU usage of sound and image

Hi everyone
I’m working on some code where thousands of soundfiles (using the sounde library) and images are loaded, one at a time. To be precise, one image and one soundfile are loaded, then played simultaneously. The images are regular size ones and the soudfiles are not very long.
It works quite well, but after ten minutes (not always at the same time), the sounds start to glitch a little - then it’s back to normal. The CPU seems very busy while the problem occurs.
I guess it would be interesting to unload the sound file for good after using it: is there a hint ?
jn

1 Like

Sounds like (pun intended!) garbage collection kicking in. What is a “regular size” image, in pixels not filesize? How long are the soundfiles?

1 Like

You should also check what else you have running in the background. Having more data loaded shouldn’t do much more than occupy ram in general. And while I agree that garbage collection is definitely something to look at here, a modern multitasking OS is potentially doing any number of other things in the background that could be taking CPU away from your program.

1 Like

Sure, but it seems obvious there that something in processing gets worse…

“regulat image size” means a size that’s smaller than the screen…

After a lot of tryouts, I switched from the Sound library to Minim.
It wasn’t the issue an maybe I could have solved my problems with Sound, but I eventually observed what was wrong : for each new reading of a sound, Processing was launching a new thread, filling both the memory and the CPU load. It seams that the problem was the high-frequency loading of sounds that were never properly dumped.
To end, I decided to use two players (in an array), alternating : open one sound, pay it, open the second sound, play it and close the first, open a third sound, play it and close the second, etc.
It now can play for hours (with thousands of sound samples).

The code used is a little too specific and long so I won’t post it here, but conclusion is that when a sound is launched before a previous one is not flushed from the memory, the useless sound will stay there for ever. Something of that kind.
(sorry for my quite clumsy english)

1 Like