MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Update

Method Update

Source/Engine/Audio/AudioSource.cpp:389–510  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

387}
388
389void AudioSource::Update()
390{
391 PROFILE_CPU();
392 PROFILE_MEM(Audio);
393
394 // Update the velocity
395 const Vector3 pos = GetPosition();
396 const float dt = Math::Max(Time::Update.UnscaledDeltaTime.GetTotalSeconds(), ZeroTolerance);
397 const auto prevVelocity = _velocity;
398 _velocity = (pos - _prevPos) / dt;
399 _prevPos = pos;
400 if (_velocity != prevVelocity && Is3D())
401 {
402 AudioBackend::Source::VelocityChanged(SourceID, _velocity);
403 }
404
405 // Reset starting to play value once time is greater than zero
406 if (_startingToPlay && GetTime() > 0.0f)
407 {
408 _startingToPlay = false;
409 }
410
411 if (Math::NearEqual(GetTime(), _startTime) && _isActuallyPlayingSth && _startingToPlay)
412 ClipStarted();
413
414 if (!UseStreaming() && Math::NearEqual(GetTime(), 0.0f) && _isActuallyPlayingSth && !_startingToPlay)
415 {
416 int32 queuedBuffers;
417 AudioBackend::Source::GetQueuedBuffersCount(SourceID, queuedBuffers);
418 if (queuedBuffers)
419 {
420 if (GetIsLooping())
421 {
422 Stop();
423 Play();
424 }
425 else
426 {
427 Stop();
428 }
429 ClipFinished();
430 }
431 }
432
433 // Skip other update logic if it's not valid streamable source
434 if (!UseStreaming() || SourceID == 0)
435 return;
436 auto clip = Clip.Get();
437 clip->Locker.Lock();
438
439 // Handle streaming buffers queue submit (ensure that clip has loaded the first chunk with audio data)
440 if (_needToUpdateStreamingBuffers && clip->Buffers[_streamingFirstChunk] != 0)
441 {
442 // Get buffers in a queue count
443 int32 numQueuedBuffers;
444 AudioBackend::Source::GetQueuedBuffersCount(SourceID, numQueuedBuffers);
445
446 // Queue missing buffers

Callers

nothing calls this directly

Calls 13

Is3DFunction · 0.85
GetTimeFunction · 0.85
QueueBufferFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
GetIsLoopingFunction · 0.70
GetPositionFunction · 0.50
MaxFunction · 0.50
NearEqualFunction · 0.50
StopFunction · 0.50
GetMethod · 0.45

Tested by

no test coverage detected