void Overlays::remove(const Common::String &name) { int id = mix_id(name); int index = findById(id); if (index >= 0) { resetSingle(index); } }
int Overlays::play(const Common::String &name, int loopId, int loopForever, int startNow, int a6) { int id = mix_id(name); int index = findById(id); if (index < 0) { index = findEmpty(); if (index < 0) { return index; } _videos[index].id = id; _videos[index].vqaPlayer = new VQAPlayer(_vm, &_vm->_surfaceGame); // repeat forever _videos[index].vqaPlayer->setBeginAndEndFrame(0, 0, -1, kLoopSetModeJustStart, nullptr, nullptr); _videos[index].loaded = true; } Common::String resourceName = Common::String::format("%s.VQA", name.c_str()); _videos[index].vqaPlayer->open(resourceName); _videos[index].vqaPlayer->setLoop( loopId, loopForever ? -1 : 0, startNow ? kLoopSetModeImmediate : kLoopSetModeEnqueue, nullptr, nullptr); return index; }
int AudioPlayer::playAud(const Common::String &name, int volume, int panFrom, int panTo, int priority, byte flags) { /* Find first available track or, alternatively, the lowest priority playing track */ Track *track = NULL; int lowestPriority = 1000000; Track *lowestPriorityTrack = NULL; for (int i = 0; i != 6; ++i) { Track *ti = &_tracks[i]; if (!isTrackActive(ti)) { track = ti; break; } if (lowestPriorityTrack == NULL || ti->priority < lowestPriority) { lowestPriority = ti->priority; lowestPriorityTrack = ti; } } /* If there's no available track, stop the lowest priority track if it's lower than * the new priority */ if (track == NULL && lowestPriority < priority) { fadeAndStopTrack(lowestPriorityTrack, 1); track = lowestPriorityTrack; } /* If there's still no available track, give up */ if (track == NULL) return -1; /* Load audio resource and store in cache. Playback will happen directly from there. */ int32 hash = mix_id(name); if (!_cache->findByHash(hash)) { Common::SeekableReadStream *r = _vm->getResourceStream(name); if (!r) return -1; int32 size = r->size(); while (!_cache->canAllocate(size)) { if (!_cache->dropOldest()) { delete r; return -1; } } _cache->storeByHash(hash, r); delete r; } AudStream *audStream = new AudStream(_cache, hash); Audio::AudioStream *audioStream = audStream; if (flags & LOOP) { audioStream = new Audio::LoopingAudioStream(audStream, 0, DisposeAfterUse::YES); } Audio::SoundHandle soundHandle; // debug("PlayStream: %s", name.c_str()); int balance = panFrom; _vm->_mixer->playStream( Audio::Mixer::kPlainSoundType, &soundHandle, audioStream, -1, volume * 255 / 100, balance); track->isMaybeActive = true; track->soundHandle = soundHandle; track->priority = priority; track->hash = hash; track->volume = volume; return track - &_tracks[0]; }