StartPlaying() on it. How do you determine the most appropriate class? Here are some hints:BSimpleGameSound and BFileGameSound classes. And, of course, you can write your own derived classes if none of these classes meet your requirements.BGameSound (or BGameSound-derived) object can play only once at a time, so you'll need to use cloned copies of the sound, one for each channel of polyphony you allow.class MultipleEffect { public: MultipleEffect(BGameSound * sound, int polyphony) { m_fx = new BGameSound *[polyphony]; m_fx[0] = sound; for (int ix=1; ix<polyphony; ix++) { m_fx[ix] = sound->Clone(); } m_current = 0; m_polyphony = polyphony; } void StartPlaying() { int id = atomic_add(&m_current, 1) % m_polyphony; m_fx[id]->StartPlaying(); } private: int32 m_current; int32 m_polyphony; BGameSound *m_fx; };
StartPlaying() implementation automatically selects the oldest one and reuses it. Since StartPlaying() restarts a sound from the beginning if it's called on a playing sound, this works out well - if polyphony is 3, and there are already three sounds playing, the oldest one will be reset and played from the beginning.BSimpleGameSound, the sound data buffer is also cloned, so you'll have multiple copies of the sound effect in memory. Keep this in mind as you write your code, as you can rapidly use a lot of memory this way.