void SoundSource::Play(SoundStream* stream) { if (!audio_) return; // If no frequency set yet, set from the stream's default if (frequency_ == 0.0f && stream) SetFrequency(stream->GetFrequency()); SharedPtr<SoundStream> streamPtr(stream); // If sound source is currently playing, have to lock the audio mutex. When stream playback is explicitly // requested, clear the existing sound if any if (position_) { MutexLock lock(audio_->GetMutex()); sound_.Reset(); PlayLockless(streamPtr); } else { sound_.Reset(); PlayLockless(streamPtr); } // Stream playback is not supported for network replication, no need to mark network dirty }
void SoundSource::Play(Sound* sound) { if (!audio_) return; // If no frequency set yet, set from the sound's default if (frequency_ == 0.0f && sound) SetFrequency(sound->GetFrequency()); // If sound source is currently playing, have to lock the audio mutex if (position_) { MutexLock lock(audio_->GetMutex()); PlayLockless(sound); } else PlayLockless(sound); // Forget the Sound & Is Playing attribute previous values so that they will be sent again, triggering // the sound correctly on network clients even after the initial playback if (networkState_ && networkState_->attributes_ && networkState_->previousValues_.size()) { for (unsigned i = 1; i < networkState_->previousValues_.size(); ++i) { // The indexing is different for SoundSource & SoundSource3D, as SoundSource3D removes two attributes, // so go by attribute types VariantType type = networkState_->attributes_->at(i).type_; if (type == VAR_RESOURCEREF || type == VAR_BOOL) networkState_->previousValues_[i] = Variant::EMPTY; } } MarkNetworkUpdate(); }
void SoundSource::PlayLockless(Sound* sound) { // Reset the time position in any case timePosition_ = 0.0f; if (sound) { if (!sound->IsCompressed()) { // Uncompressed sound start signed char* start = sound->GetStart(); if (start) { // Free existing stream & stream buffer if any soundStream_.Reset(); streamBuffer_.Reset(); sound_ = sound; position_ = start; fractPosition_ = 0; return; } } else { // Compressed sound start PlayLockless(sound->GetDecoderStream()); sound_ = sound; return; } } // If sound pointer is null or if sound has no data, stop playback StopLockless(); sound_.Reset(); }
void SoundSource::Play(Sound* sound) { if (!audio_) return; // If no frequency set yet, set from the sound's default if (frequency_ == 0.0f && sound) SetFrequency(sound->GetFrequency()); // If sound source is currently playing, have to lock the audio mutex if (position_) { MutexLock lock(audio_->GetMutex()); PlayLockless(sound); } else PlayLockless(sound); MarkNetworkUpdate(); }