int lua_AudioSource_stop(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA)) { AudioSource* instance = getInstance(state); instance->stop(); return 0; } else { lua_pushstring(state, "lua_AudioSource_stop - Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; }
void AudioManager::stop_source(int source_idx) { if (source_idx < 0) return; AudioSource *src = get_audio_source(source_idx); if (src && src->is_playing()) src->stop(); }
void SceneManager::push(Scene* scene, Modality modality /*= Modality::Exclusive*/) { if (!m_activeList.empty()) { auto go = m_activeList.back().first->getAllGameObjects(); for (size_t i = 0; i < go.size(); i++) { //go[i]->deactivate(); if (modality == Modality::Exclusive) { go[i]->setWasEnabled(go[i]->isEnabled()); go[i]->setEnabled(false, false); AudioSource * audio = go[i]->getGameComponent<AudioSource>(); if (audio != nullptr) { if (audio->getType() == AudioType::STREAM) { audio->setWasPlaying(audio->isPlaying()); // pause music audio->stop(); } } } } } if (modality == Modality::Popup) { m_activeList.back().first->notifyCoveredObjects(); } m_activeList.push_back(std::make_pair(scene, modality)); scene->init(*m_viewport); scene->setEngine(m_coreEngine); auto attachedToRoot = scene->getRoot()->getAllAttached(); for (size_t i = attachedToRoot.size() - 1; i > 0; i--) { auto gameComponents = attachedToRoot[i]->getAllGameComponents(); for (size_t j = 0; j < gameComponents.size(); j++) { gameComponents[j]->onStart(); } } updateExclusiveScene(); }
int Soloud::play(AudioSource &aSound, float aVolume, float aPan, int aPaused, int aBus) { if (aSound.mFlags & AudioSource::SINGLE_INSTANCE) { // Only one instance allowed, stop others aSound.stop(); } // Creation of an audio instance may take significant amount of time, // so let's not do it inside the audio thread mutex. aSound.mSoloud = this; SoLoud::AudioSourceInstance *instance = aSound.createInstance(); if (mLockMutexFunc) mLockMutexFunc(mMutex); int ch = findFreeVoice(); if (ch < 0) { if (mUnlockMutexFunc) mUnlockMutexFunc(mMutex); delete instance; return -1; } if (!aSound.mAudioSourceID) { aSound.mAudioSourceID = mAudioSourceID; mAudioSourceID++; } mVoice[ch] = instance; mVoice[ch]->mAudioSourceID = aSound.mAudioSourceID; mVoice[ch]->mBusHandle = aBus; mVoice[ch]->init(mPlayIndex, aSound.mBaseSamplerate, aSound.mChannels, aSound.mFlags); mPlayIndex++; if (aPaused) { mVoice[ch]->mFlags |= AudioSourceInstance::PAUSED; } setVoicePan(ch, aPan); setVoiceVolume(ch, aVolume); setVoiceRelativePlaySpeed(ch, 1); int i; for (i = 0; i < FILTERS_PER_STREAM; i++) { if (aSound.mFilter[i]) { mVoice[ch]->mFilter[i] = aSound.mFilter[i]->createInstance(); } } int scratchneeded = SAMPLE_GRANULARITY * mVoice[ch]->mChannels; mVoice[ch]->mResampleData[0]->mBuffer = new float[scratchneeded]; mVoice[ch]->mResampleData[1]->mBuffer = new float[scratchneeded]; // First buffer will be overwritten anyway; the second may be referenced by resampler memset(mVoice[ch]->mResampleData[0]->mBuffer, 0, sizeof(float) * scratchneeded); memset(mVoice[ch]->mResampleData[1]->mBuffer, 0, sizeof(float) * scratchneeded); if (mUnlockMutexFunc) mUnlockMutexFunc(mMutex); int handle = getHandleFromVoice(ch); return handle; }