unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop, float pitch, float pan, float gain) { std::string key = std::string(pszFilePath); struct soundData *sound; if(!s_effects.count(key)) { sound = new struct soundData(); sound->chunk = Mix_LoadWAV(pszFilePath); sound->isLooped = bLoop; s_effects[key] = sound; } else { sound = s_effects[key]; } // This is safe here since Emscripten is just passing back an // incrementing integer each time you use the Mix_LoadWAV method. unsigned int result = (unsigned int) sound->chunk; // XXX: This is a bit of a hack, but... Choose a channel based on the // modulo of the # of channels. This allows us to set the volume // without passing around both chunk address and channel. Mix_PlayChannel(result % NR_CHANNELS, sound->chunk, bLoop ? -1 : 0); return result; }
void SimpleAudioEngine::unloadEffect(const char* pszFilePath) { std::string key = std::string(pszFilePath); if(!s_effects.count(key)) { return; } struct soundData *sound = s_effects[key]; Mix_FreeChunk(sound->chunk); delete sound; s_effects.erase(key); }