A: Consider a compromise between the previous and your current techniques. Allocate three or four instruments, keep track of which ones are in use at any given moment, and when you want to play a sound attach the sample to the instrument and mark that instrument as in use. When the sample is done (CUE_AT_END), detach the sample from the instrument and mark it as free.
This sounds like a lot of work, but actually, it is all done for you. If you assign each sound effect as a MIDI note in a PIMap file (see Playing MIDI Scores), you can create and delete these sounds very efficiently with StartScoreNote()
and StopScoreNote()
. A setting in the PIMap file allows you to control the maximum number of allocated sample players, and they are automatically reused when a sample stops playing. See the example file tsc_soundfx.c.