Make channel index a global variable in embedded player.

This commit is contained in:
Skyth 2024-12-20 03:41:42 +03:00
parent 68343a574c
commit e3a2dd9e90

View file

@ -24,9 +24,7 @@ enum class EmbeddedSound
struct EmbeddedSoundData
{
static const int SimultaneousLimit = 4;
Mix_Chunk* chunk{};
int channelIndex{};
};
static std::array<EmbeddedSoundData, size_t(EmbeddedSound::Count)> g_embeddedSoundData = {};
@ -41,6 +39,8 @@ static const std::unordered_map<std::string_view, EmbeddedSound> g_embeddedSound
{ "sys_actstg_pausewinopen", EmbeddedSound::SysActStgPauseWinOpen },
};
static size_t g_channelIndex;
static void PlayEmbeddedSound(EmbeddedSound s)
{
EmbeddedSoundData &data = g_embeddedSoundData[size_t(s)];
@ -86,9 +86,9 @@ static void PlayEmbeddedSound(EmbeddedSound s)
data.chunk = Mix_LoadWAV_RW(SDL_RWFromConstMem(soundData, soundDataSize), 1);
}
Mix_PlayChannel(data.channelIndex % EmbeddedSoundData::SimultaneousLimit, data.chunk, 0);
++data.channelIndex;
Mix_PlayChannel(g_channelIndex % MIX_CHANNELS, data.chunk, 0);
++g_channelIndex;
}
void EmbeddedPlayer::Init()