I have a quick question about best practices with a SamplePlayer. I'm mainly working in C, but this likely applies to lua as well.
When having several audio channels, each of which will be playing arbitrary sound effects, is it better to have one SamplePlayer for each channel, and then change the sample it's playing using setSample()? Or is it better to create lots of instances of SamplePlayer, one for each combination of a channel and specific sample, and only set their sample once at creation?
It's going to be better to just change the sample using setSample() rather than creating new SamplePlayer instances each time. This approach is more memory-efficient and avoids unnecessary object creation.
I suspected as much. Though for the case where I have a SamplePlayer for each combination of a sample and channel, I would create them ahead of time so there wouldn't be object creation happening while the game was running. And right now I have quite a lot of free memory so creating extra SamplePlayer instances wouldn't be a big deal.
So I guess the question is, what kind of overhead is there to changing the sample of a SamplePlayer? Is there any at all?