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 stopSound(aSound); } if (mLockMutexFunc) mLockMutexFunc(mMutex); int ch = findFreeVoice(); if (ch < 0) { if (mUnlockMutexFunc) mUnlockMutexFunc(mMutex); return -1; } if (!aSound.mAudioSourceID) { aSound.mAudioSourceID = mAudioSourceID; mAudioSourceID++; aSound.mSoloud = this; } mVoice[ch] = aSound.createInstance(); 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; }
result Soloud::setRelativePlaySpeed(handle aVoiceHandle, float aSpeed) { result retVal = 0; FOR_ALL_VOICES_PRE mVoice[ch]->mRelativePlaySpeedFader.mActive = 0; retVal = setVoiceRelativePlaySpeed(ch, aSpeed); FOR_ALL_VOICES_POST return retVal; }