Files
UnrealEngineUWP/Engine/Source/Runtime/AudioMixer/Private/AudioMixerSourceManager.cpp
Dan Oconnor e29126385f Copying //UE4/Dev-Framework to //UE4/Dev-Main (Source: //UE4/Dev-Framework @ 3380068)
#lockdown Nick.Penwarden

==========================
MAJOR FEATURES + CHANGES
==========================

Change 3358702 on 2017/03/22 by Marc.Audy

	Always mark child actors pending kill when in PostLoad as often the World is too early to have a WorldContext which causes issues in DestroyActor
	#jira UE-42679

Change 3358737 on 2017/03/22 by Mieszko.Zielinski

	Exposed UBrainComponent::IsRunning() and UBrainComponent::IsPaused() to Blueprint #UE4

Change 3359062 on 2017/03/22 by Michael.Noland

	Blueprints: Show the Save and Find in CB buttons when working with level script blueprints (they will save/show the map package)

	#jira UE-30748

Change 3359066 on 2017/03/22 by Michael.Noland

	PR #3348: Make fields of FAttributeMetaData editable (Contributed by hoelzl)

	#jira UE-42620

Change 3359069 on 2017/03/22 by Michael.Noland

	PR #3288: InverseLerp Blueprint Tooltips Clarification (Contributed by wunawuna)

	#jira UE-42250

Change 3359108 on 2017/03/22 by Michael.Noland

	Blueprints: Fix an issue where running the editor in a different culture could break pins on nodes that have optional arrays of pins (e.g., animation graph nodes like blend by layer)
	#jira UE-36232

Change 3359235 on 2017/03/22 by Marc.Audy

	Expose bShouldPerformFullTickWhenPaused to blueprints and details panel
	#jira UE-17286

Change 3359324 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Disable collision on NavModifierVolumes. Previously they had an OverlapAll response and generated overlap events. They are only supposed to be used for preventing nav mesh generation, but overlap events could affect gameplay, and also are bad for performance.

	(Integrate CL 3249525 from Odin).

Change 3359326 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Optimization during attachment to check bool before expensive casts and body instance fetching.

	(Integrate CL 3261262 from Odin).

Change 3359327 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Make bSkipAgentHeightCheckWhenPickingNavData actually ignore height when picking data.

	(Integrate CL 3231908 from Odin)

Change 3359328 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Make a static FName in UMovementComponent::OverlapTest const and move it to a namespace.

	(Integrate CL 3259985 from Odin)

Change 3359329 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Fix ProjectileMovementComponent continuing to simulate (and generate hit events) after it is deactivated during simulation. HasStoppedSimulation() should check if bIsActive is false.

	(Integrate CL 3260001 from Odin)

Change 3359330 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Fix accumulated forces in CharacterMovement when movement mode or activation changes.

	- Added CharacterMovementComponent::ClearAccumulatedForces()
	- AddForce() and related functions now avoid adding the force if in MovementMode "None". When ticking in "None", forces are cleared so they don't pile up until the next valid movement mode. Forces are also cleared if the updated component changes or when the capsule simulates physics.
	- CharacterMovementComponent::Deactivate() implemented to stop movement and call ClearAccumulatedForces().
	- ClearAccumulatedForces() now also clears pending launch velocity.
	- Exposed ClearAccumulatedForces() to blueprints.
	- AddForce() and AddImpulse() now also check that character movement is active (not deactivated, able to tick).
	- ApplyAccumulatedForces() does not call ClearAccumulatedForces(), since that would prevent pending launch.
	- SimulateMovement() handles pending launch and clears forces regardless of whether it's simulated proxy. Added note to investigate using ApplyAccumulatedForces() in SimulateMovement().
	- Inlined ActorComponent::IsActive().

	(Integrate CLs 3259933, 3266018 from Odin)

Change 3359338 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) TickCharacterPose() and clear root motion before abandoning tick in UCharacterMovementComponent::PerformMovement() when movement mode is None. Prevents root motion building up until next valid movement mode.

	(Integrate CL 3271928 from Odin)

Change 3359345 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Fix characters sliding when landing on slanted surfaces or stairs, when aggressive "Perch" settings could cause a line trace (from the center of a capsule) instead of capsule trace and thereby screw up the floor distance checks.

	(Integrate CL 3273026 from Odin)

Change 3359381 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Performance tweak to ApplyRadialDamageWithFalloff(). Don't rebuild FRadialDamageEvent each loop over hit actors. Added stats for BreakHitResult()/MakeHitResult() under "stat game".

	(Integrate CLs 3275415, 3276810 from Odin).

Change 3359422 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Fix build (CollisionProfile included).

Change 3359442 on 2017/03/22 by Michael.Noland

	Blueprints: Prevent comment boxes from clipping the last letter of some words at the edge by increasing the padding on the wrap-at position

Change 3359445 on 2017/03/22 by Michael.Noland

	PR #2989: Improved BP comment nodes (Contributed by projectgheist)

	#jira UE-36788
	#jira UE-39118

Change 3359446 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Add support for FScopedMovementUpdate to be able to queue up overlaps that do not require reflexive bGenerateOverlapEvents. This allows custom inspection or processing of overlaps within a scoped move. Overlap events from the move will still only trigger in UpdateOverlaps() if bGenerateOverlapEvents is enabled on both components, as before.

	(Integrate CL 3278307 from Odin)

Change 3359494 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Make some data in FScopedMovementUpdate protected rather than private so it can easily be subclassed, and expose a new helper SetWorldLocationAndRotation().

	(Integrated CL 3280775 from Odin).

Change 3359506 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) MovementComponent::Deactivate() calls StopMovement() to clear cached velocity. It's silly that reactivation many seconds or frames later would restore that velocity. Some special handling in CharacterMovement to keep it acting as before (it cleared velocity, but did not clear the path request, leaving that alone).

	(Integrate CL 3287026 from Odin).

Change 3359514 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Collision.ListComponentsWithResponseToProfile command includes pending kill objects.

	(Integrate CL 3293322 from Odin)

Change 3359553 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Optimization in CharacterMovement tick to not extract transform values twice.

	(Integrate CL 3299098 from Odin).

Change 3359554 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Perf: optimize UKismetMathLibrary::GetForwardVector() (converts Rotator to forward direction). This way we avoid building a matrix, and avoids 1 more SinCos call.

	(Integrate CL 3296254 from Odin).

Change 3359555 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Add OnComponentCollisionSettingsChangedEvent delegate to PrimitiveComponent. Fixed SkeletalMeshComponent not calling Super implementation.

	(Integrate CL 3295744 from Odin)

Change 3359561 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Perf: AActor::GetComponents() with generic type should *not* assume the output array needs space for the entire contents of OwnedComponents. If OwnedComponents.Num() > the array reserve size, this forces an allocation, even if few or no components of the requested type are found.

	(Integrate CL 3299111 from Odin)

Change 3359573 on 2017/03/22 by dan.reynolds

	Added BP log to the Passive Mix Modifier test platform BP

Change 3359593 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Perf: avoid allocations during creation in AAIController::PostInitializeComponents() (in development builds).

	(Integrate CL 3299118 from Odin)

Change 3359595 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Perf: HasActiveCameraComponent() and HasActivePawnControlCameraComponent() don't need to fill in an array while searching for a certain component. Also see CL 3359561, which could cause each of these functions to always cause an allocation when filling in the array when num components > 24.

	(Integrate CL 3299116 from Odin)

Change 3359602 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Clean up some of the new fast overlap code in PrimitiveComponent. Mostly some variable renaming, and CVar access optimization.

	(Integrate CL 3340622 from Odin)

Change 3359616 on 2017/03/22 by Zak.Middleton

	#ue4 - (Merge) Added support for bIgnoreTouches to FCollisionQueryParams. MoveComponent uses this to avoid PhysX collision queries for overlaps in GeomSweepMulti when bGenerateOverlapEvents is off.

	(Integrate CL 3340635 from Odin)

Change 3359864 on 2017/03/23 by Mieszko.Zielinski

	Added a safeguard to prevent crashes resulting from people trying to name their BB keys things longer than 1024 characters #UE4

	#jira UE-43120

Change 3360884 on 2017/03/23 by Zak.Middleton

	#ue4 - (Merge) Audio: AUDIO_MIXER_ENABLE_DEBUG_MODE turned off in Test builds. Shipping already had it off.

	(Integrate CL 3310724 from Odin)

Change 3361045 on 2017/03/23 by Zak.Middleton

	#ue4 - (Merge) Audio: new cvars to help with optimization:

	- au.DisableReverbSubmix
	- au.DisableEQSubmix
	- au.DisableParallelSourceProcessing
	- au.SetAudioChannelCount

	Also checked in some code to cut down on the amount of parameter setting in EQ

	(Integrate of CL 3303165 in Odin by Aaron.Mcleran)

Change 3361172 on 2017/03/23 by Zak.Middleton

	#ue4 - (Merge) Audio: added stat for HRTF.

	(Integrate CL 3310728 from Odin)

Change 3361189 on 2017/03/23 by Zak.Middleton

	#ue4 - (Merge) CVar to toggle HRTF for perf settings. Default is on.

	(Integrate CL 3310926 from Odin).

Change 3361914 on 2017/03/23 by Aaron.McLeran

	UE-42649 Fixing crash in cleaning up active sound in sound concurrency

	-Handling edge case of an active sound not have a sound base ptr, which is possible.

Change 3361924 on 2017/03/23 by Aaron.McLeran

	UE-41378 Fixing passive mix modifier bug

Change 3361978 on 2017/03/23 by Aaron.McLeran

	UE-42627 Fix for when audio device is removed and getting a deadlock in computing audio clock

Change 3361989 on 2017/03/23 by Aaron.McLeran

	PR #3010: Check for null GEngine on sound processing

Change 3362053 on 2017/03/23 by Zak.Middleton

	#ue4 - (Merge) Audio: Perf: Avoid thousands of Array.Add() calls during processing, which on shipping still does checks to see if the allocator has to grow, and updates ArrayCount.

	(Integrate CL 3311120 from Odin)

Change 3362102 on 2017/03/23 by Aaron.McLeran

	PR #3182:  Enabled SwitchOnEnum nodes for EAttenuationShape and EAttenuationDistanceModel

Change 3362153 on 2017/03/23 by Aaron.McLeran

	UE-43286 Oculus audio plugin not working/available

Change 3362162 on 2017/03/23 by Aaron.McLeran

	UE-42252  Frequent ensure in FLevelEditorViewportClient::UpdateAudioListener

Change 3362206 on 2017/03/23 by Aaron.McLeran

	UE-43287 Fixing HRTF spatialization in editor viewport

	- Steam Audio doesn't support multiple audio devices at the moment
	- Instead of hard-coding all audio plugins to not work in main audio device (GDC temp fix), I allow audio plugins to specify if they should be used on main audio device

Change 3362775 on 2017/03/24 by mason.seay

	Replaced deprecated node

Change 3363024 on 2017/03/24 by Ben.Zeigler

	Fix regression in behavior of streamable manager where loading both a valid and null asset used to work but now fails. Instead added a warning for that case, but if only null are requested it still fails with an error

Change 3363030 on 2017/03/24 by Zak.Middleton

	#ue4 - Lower default max sendrate for clients to 60Hz from 90Hz when net speed is high and player count is low. Throttled rate remains at 45Hz. This value has been tested in Paragon with no ill effect, and saves on bandwidth and server CPU when clients run at high framerate.

Change 3363036 on 2017/03/24 by Zak.Middleton

	#ue4 - (Merge) Audio: Perf: turned a float divide into a multiply. It happens at least 32k times per audio update.

	(Integrate CL 3311158 from Odin)

Change 3363541 on 2017/03/24 by Zak.Middleton

	#ue4 - (Merge) Audio: Perf: remove pointer indirection, and successive TArray Add()s in GetChannelMap().

	(Integrate CL 3311169 from Odin)

Change 3363642 on 2017/03/24 by Zak.Middleton

	#ue4 - (Merge) Audio: Perf: Save ~5% total audio update time. Savings in "Source Output Buffers".

	- Removed function call overhead to updating channel map. 64,000 function calls...
	- Simplified FSourceParam::Update() to reduce branching and have 1 return site.
	- Added alternative to GetChannelMap() called UpdateChannelMap() that avoids copying out values to an array. The values can then be fetched from the channel data directly.

	(Integrate CL 3311235 from Odin)

Change 3364441 on 2017/03/24 by Ben.Zeigler

	Fix issue where calling LoadLocalIniFile on a plugin file would result in an empty file. It was assuming engine/game dirs, now it instead pulls it out of GConfig if available.
	This fixes issue where iterative cooking would fail on plugin config files
	Add FindConfigFileWithBaseName to GConfig

Change 3364652 on 2017/03/25 by Phillip.Kavan

	#jira UE-43210 - Fix a runtime VM crash upon removing an element from a set after consecutive add/remove iterations.

	Change summary:
	- Fixed FScriptSet::Add() to initialize the HashIndex member of the new element when the HashSize does not change.

Change 3365609 on 2017/03/27 by Richard.Hinckley

	#jira UEDOC-4720
	Fixed global enums being dropped from documentation after being extracted by Doxygen.

Change 3365737 on 2017/03/27 by Marc.Audy

	Move setting of the ParentComponent property on an actor to PostRepNotifies instead of having a separate OnRep function.

Change 3365795 on 2017/03/27 by Marc.Audy

	Fix compile error

Change 3365894 on 2017/03/27 by Phillip.Kavan

	#jira UE-35507 - Fix for a GLEO when choosing an LSBP class as the default value for a class input pin in a non-LSBP graph.

	Change summary:
	- Modified FGraphPinFilter::IsClassAllowed() to disallow a given class if the type is contained within a map package that does not match the current graph context.

Change 3366067 on 2017/03/27 by Marc.Audy

	Add UWorld* to PostLoadMap indicating which world has been loaded. Null if an error has occurred.
	#jira UE-40228

Change 3366097 on 2017/03/27 by Marc.Audy

	Fixed missed deprecation disable pairing for PostLadMap

Change 3366170 on 2017/03/27 by Aaron.McLeran

	Fixing div by zero

Change 3366221 on 2017/03/27 by Aaron.McLeran

	UE-43240 Removing dependency on component visualizers in runtime Phonon module.

Change 3366698 on 2017/03/27 by Marc.Audy

	Fix Orion compile errors

Change 3366782 on 2017/03/27 by Aaron.McLeran

	Bringing over optimizations from Odin to Dev-framework.

	Original CL 3311435

Change 3366818 on 2017/03/27 by Aaron.McLeran

	Bringing fix from Odin to Dev-Framework from CL 3304533

	Fix for rare condition that stomps memory during source recycling.

Change 3366984 on 2017/03/27 by Michael.Noland

	Blueprints: Downgraded a warning in the connection drawing policy to verbose to suppress it. It does no good to a typical user.
	#jira UE-41638

Change 3367085 on 2017/03/27 by Brent.Pease

	 - Improve AudioMixer buffering so that only two buffers are needed instead of three, buffer submission and buffer processing are ovelapped, and a warning is issued if the audio processing thread can not keep up.
	 - Added time critical thread priority so that audio processing is not starved which would produce clicks and popping
	 - Allow the audio thread to not be created if a platform implements its own BeginGeneratingAudio() call (as happens on Android)

Change 3367434 on 2017/03/28 by Marc.Audy

	Fix UT compile error

Change 3368587 on 2017/03/28 by Mike.Beach

	Adding a "CookedOnly" plugin type (now used by the nativized Blueprint plugin).

Change 3368724 on 2017/03/28 by Zak.Middleton

	#ue4 - MovementComponent does not ignore initial blocking overlaps when moving from SafeMoveUpdatedComponent(). Set "p.MoveIgnoreFirstBlockingOverlap" back to zero and add a new flag that prevents the depenetration test from generating hit events (to prevent the problem discovered in UE-39387).

	#jira UE-41613, UE-28610

Change 3368748 on 2017/03/28 by Dan.Oconnor

	Provide &FUObjectThreadContext::Get().ObjLoaded when using the compilation manager, add validation functions for finding REINST/TRASH references

Change 3368852 on 2017/03/28 by Mike.Beach

	Fixing a CIS error before it happens - wrapping implementation in preprocessor defines to match declaration in header.

Change 3368873 on 2017/03/28 by Dan.Oconnor

	Rather than collecting script object references, just use the ScriptObjectReferences array. This allows reference replacing archives to update ScriptObjectReferences.

Change 3368998 on 2017/03/28 by Dan.Oconnor

	Setting  CLASS_Interface early in the compilation process

Change 3369494 on 2017/03/29 by Marc.Audy

	Fix UAT compile error

Change 3369924 on 2017/03/29 by Zak.Middleton

	#ue4 - Allow CharacterMovement AdjustFloorHeight() to adjust using the line trace if in penetration. Force next floor check so it will check after it depenetrates.

	#jira UE-36973

Change 3369932 on 2017/03/29 by Ben.Zeigler

	#jira UE-19494 Finish asset auditing work by allowing reading back a cooked asset registry in the editor
	Split off FAssetRegistryState as the struct to hold serialization and accessors, to allow loading multiple platform states at once.
	Optimized runtime asset registry serialization to be around 1/3 as large as before. Dependencies are disabled by default for the runtime registry, you can re-enable with bSerializeDependencies in Engine.ini
	Add FAssetPackageData which is explicitly per-package and only updated on save/load time. File size is stored in here and is computed for both editor and cooked data
	Add code to AssetManagerEditorModule to allow loading pre-cooked asset registry files and reading cooked sizes. The Asset Audit window now has a platform drop down that allows reading from cooked data
	Rename ChunkManifestGenerator to AssetRegistryGenerator and change it to directly hold an FAssetRegistryState internally
	Add new experimental AssetRegistry mode for iterative cooking. This mode is much faster as it does not need to do it's own internal dependency checking and it can be enabled with bUseAssetRegistryForIteration
	Change it so during cooking it doesn't directly load string asset references, but instead cues them for cook and uses the asset registry to find and add redirector mappings that are used during save time

Change 3370028 on 2017/03/29 by Ben.Zeigler

	CIS fix

Change 3370360 on 2017/03/29 by Mike.Beach

	Adding an extra field to FPlatformInfo; a 'UBTTarget' identifier intended to sync up with UBT's UnrealTargetPlatform enum (needed for programatically generating plugin platform whitelists).

Change 3370363 on 2017/03/29 by Ben.Zeigler

	Fix issue where loading out of date editor asset registry cache would throw pointless errors

Change 3370414 on 2017/03/29 by Marc.Audy

	Remove autos

Change 3370428 on 2017/03/29 by Ben.Zeigler

	Fix linux CIS issue, remove implicit conversion from FSavePackageResultStruct back to enum result as it was creating ambiguous operators

Change 3370453 on 2017/03/29 by Marc.Audy

	CIS fix

Change 3370548 on 2017/03/29 by Marc.Audy

	#rn Fix issues with seamless travel in PIE and shared sub levels between different parents.

Change 3370564 on 2017/03/29 by Mieszko.Zielinski

	PR #3429: fix comment typo (Contributed by kayama-shift)

Change 3370602 on 2017/03/29 by Mieszko.Zielinski

	Fixed FRecastTileGenerator::Modifiers being erroneously counted twice when stating memory #UE4

Change 3370615 on 2017/03/29 by Phillip.Kavan

	#jira UE-35515 - No longer crash when creating a new BP class from one or more selected Actors in which the root component is not Blueprint-spawnable.

	Change summary:
	- Modified FKismetEditorUtilities::AddComponentsToBlueprint() to handle deferred SceneComponent SCS node adds when the parent component was not also added (due to not being BP-spawnable).

Change 3370693 on 2017/03/29 by Michael.Noland

	Fixing some bad indentation
	#rnx

Change 3370740 on 2017/03/29 by Ben.Zeigler

	DLC/Mod Cooking fixes, the list of packages from release build as in uncooked filename format so fixed code and made this more obvious
	Fix Asset Registry to allow loading multiple source asset registries into the same state, by keeping a list of preallocated buffers

Change 3370792 on 2017/03/29 by Michael.Noland

	Blueprints: Deleted some unversioned backwards compat. code that would only matter for assets older than VER_UE4_OLDEST_LOADABLE_PACKAGE

Change 3370794 on 2017/03/29 by Michael.Noland

	PR #3190: Reduce some output logging
	- Reduced an Oculus log from Log to Verbose because it spams quite a bit
	- Corrected the spelling and the meaning of a blueprint warning when an invalid breakpoint is encountered
	- Treat UInputComponent::GetAxisValue(None) as not a warning
	- Switch FGenericSaveGameSystem::LoadGame to silently attempt to load the file, it returns success/failure and it isn't necessary to have a separate warning at the file i/o layer

	#jira UE-41446

Change 3370831 on 2017/03/29 by Dan.Oconnor

	Iteration on compilation manager
	 - Fix Skeleton class compilation order
	 - Pass ObjLoaded array to compilation manager to ensure all objects get PostLoaded
	 - Make sure data only classes get reinstanced, so that UpdateCustomPropertyListForPostConstruction is run correctly

Change 3370923 on 2017/03/29 by Michael.Noland

	Blueprints: Added an icon to indicate whether or not a macro contains latent actions
	- Note: The state of the icon is cached for performance reasons on request, with the cache being cleared when the BP containing the macro is modified or a macro graph is removed
	- This does mean that editing the inner macro of a nested macro to add/remove a latent action will not show up in visualization for the outer node until the editor is restarted or the outer macro is modified

Change 3371039 on 2017/03/29 by Dan.Oconnor

	Hacky fix for dropping return params when a function's return node is culled

Change 3371750 on 2017/03/30 by Richard.Hinckley

	Stencil write mask exposed. Adds nine new options (all bits, plus each bit individually - write on pass or depth fail). This allows stencil overlaps to be detected by mixing masks.

Change 3372513 on 2017/03/30 by Ben.Zeigler

	#jira UE-43475 Fix cooker issues with string asset references to null packages.
	Fix redirector detection to follow recursive chains, and correctly strip object class from redirected string asset references.

Change 3372565 on 2017/03/30 by Richard.Hinckley

	Rolling back stencil change, will be moved to Dev-Rendering.

Change 3372764 on 2017/03/30 by Marc.Audy

	Do not create a duplicate sub object that is not in the annotation if a sub object of the same name and class already exists.
	#jira UE-43328

	#rn Fixed cases where the blueprint of a class used as a child actor could be dirtied when compiling the owning blueprint.

Change 3372847 on 2017/03/30 by Marc.Audy

	Fix missing include

Change 3372994 on 2017/03/30 by Zak.Middleton

	#ue4 - Fix build in Debug (checkSlow using incorrect function params).

Change 3373195 on 2017/03/30 by Mike.Beach

	For nativization, changing it so we key off of the target platform-info struct instead of the platform (in preparation for defining the nativized plugin's platform whitelist).

Change 3373320 on 2017/03/30 by mason.seay

	Basic for TM-Gameplay map (WIP)

Change 3373448 on 2017/03/30 by Ben.Zeigler

	Fix recursive size display in audit window
	Improve asset manager comments

Change 3373576 on 2017/03/30 by dan.reynolds

	AEOverview Update:

	Updated Passive Mix Modifier Test based on recent changes in behavior

	Also added Initial Delay Time timer to test

Change 3373589 on 2017/03/30 by dan.reynolds

	AEOverview Passive Mix Mod Test Map update

Change 3373624 on 2017/03/30 by Zak.Middleton

	#ue4 - Increase Pawn location replication precision to 2 decimal places from 0. Prevents replicated pawns from being inside geometry by a large amount. Removed CVars controlling CharacterMovement proxy shrink amount and made those instanced properties on the component.

	#jira UE-40420

Change 3374271 on 2017/03/31 by Marc.Audy

	Fix deprecation warning in new UT code

Change 3374320 on 2017/03/31 by Marc.Audy

	Fix HTML5 compile.

Change 3374413 on 2017/03/31 by Jeff.Farris

	Added ENGINE_API to 2 functions in PlanarReflection, so projects can subclass it.

	(Copied CL 3276454 from Robo Recall to Dev-Framework)

Change 3374414 on 2017/03/31 by Jeff.Farris

	Added support for setting UNavigationSystem::bUpdateNavOctreeOnComponentChange

	(Copied CL 3267903 from RoboRecall to Dev-Framework)

Change 3374616 on 2017/03/31 by Ben.Zeigler

	Copy of Fortnite CL #3312058 to add a missing redirector. I do not understand why this is not erroring on Main, I guess my minor cook changes somehow exposed this

Change 3374664 on 2017/03/31 by Jeff.Farris

	Consted AIController::GetBrainComponent()

	(Copied 3239101 from Robo Recall to Dev-Framework)

Change 3374665 on 2017/03/31 by Jeff.Farris

	PrimitiveComponent bIgnoreRadialImpulse and bIgnoreRadialForce are now exposed to BPs. bIgnoreRadialImpulse now respected when applying impulse to relevant movement components.

	(Coped CL 3242355 from Robo Recall to Dev-Framework)

Change 3374779 on 2017/03/31 by Jeff.Farris

	Exposed SetAllPhysicsAngularVelocity to blueprints

	(Copied CL 3228390 from Robo Recall to Dev-Framework)

Change 3374792 on 2017/03/31 by Ben.Zeigler

	#jira UE-42618
	PR #3347: Improve support for FGameplayAttributeData properties in attribute sets (Contributed by hoelzl)

Change 3374844 on 2017/03/31 by Ben.Zeigler

	#jira UE-42587 Fix issue where supressed gameplay effects that granted abilities would only work the first time, it now clears out of date ability handles

Change 3374925 on 2017/03/31 by Marc.Audy

	Don't throw warning about missing world context for inactive worlds.
	#jira UE-42679

Change 3374927 on 2017/03/31 by Michael.Noland

	Editor: Added options for configuring the editor window background color and texture, which can be useful to visually distinguish the editor when switching between different branches or projects

Change 3374995 on 2017/03/31 by Michael.Noland

	Editor: Rewrote CallInEditor support and promoted it so it can be used on functions in any class, not just blueprints derived from AActor:
	- CallInEditor used on native UFUNCTION() declarations will now show up without having to make a BP subclass
	- CallInEditor can now be used as a top-level keyword in the UFUNCTION() declaration (e.g., UFUNCTION(Category=CoolCommands, CallInEditor))
	- Now shows each function as a separate button, placed in the category associated with the function
	- The button strip entry is now searchable by function name or tooltip
	- Prevented operating on functions that have parameters or return values, which would crash before
	- Removed the duplicate copies of properties placed in the Blutility section
	- Added a scoped transaction around CallInEditor execution
	- Allowed functions to be marked as CallInEditor in addition to custom events (currently we don't allow editing category or tooltip on custom events...)

	Editor: Moved Experimental/EarlyAccessPreview details customizations up to UObject so it can be used on any class, not just actors/components

	Upgrade Note: Behavior has changed so that CallInEditor can be called on CDOs as well, this will probably be walked back in a subsequent update, at least for actors and components.

Change 3375005 on 2017/03/31 by Michael.Noland

	Fixing incremental compilation error due to missing include
	#rnx

Change 3375015 on 2017/03/31 by Michael.Noland

	Fixing incremental compilation error due to missing include (for real)
	#rnx

Change 3375045 on 2017/03/31 by Marc.Audy

	Only calculate the streaming levels prefix during seamless travel if it is a PIE world
	#jira UE-43485

Change 3375053 on 2017/03/31 by Ben.Zeigler

	#jira UE-41988 Fix it so leaving PIE while gameplay debugger is active will disable HUD extensions properly, restoring ability to print messages to screen

Change 3375057 on 2017/03/31 by Ben.Zeigler

	#jira UE-39226 Don't add to DrawDebug list for player controllers with no local player

Change 3375121 on 2017/03/31 by Michael.Noland

	Added missing include for FScopedTransaction
	#rnx

Change 3375222 on 2017/03/31 by mason.seay

	Submitting work done to TM-Gameplay.  Still WIP

Change 3375308 on 2017/03/31 by Michael.Noland

	Editor: Added back CDO filtering to CallInEditor, it's too easy to explode in the BP editor.  May consider allowing opt-in behavior when we revisit Blutilities

Change 3375321 on 2017/03/31 by Ben.Zeigler

	#jira UE-39062 Fix issue where using the level editor toolbar to modify blueprints was not properly marking the blueprints as modified, so the constructor links weren't being updated until manually compiling or resaving
	Always recompute post constructor links when calling MarkBlueprintAsModified, as it can be called from native and other places where we modified CDOs but don't have a property changed event

Change 3375372 on 2017/03/31 by Ben.Zeigler

	#jira UE-39568 Change Components to specifically update LatentActions the same as Actors do, so they update properly if bUpdateWhilePaused is set

Change 3375380 on 2017/03/31 by Marc.Audy

	Modify IsMainAudioDevice to deal with the case where no audio device has been created.

Change 3375402 on 2017/03/31 by Marc.Audy

	Fix DuplicateWorldForPIE in the case that the OwningWorld is null.

Change 3376037 on 2017/04/02 by Phillip.Kavan

	#jira UE-35332 - Preserve the least common ancestor pin type on object array function node inputs after a node refresh.

	Change summary:
	- Added UK2Node_CallArrayFunction::GetDynamicallyTypedPins() to consolidate the code that retrieves type-dependent parameter pins.
	- Added FBlueprintEditorUtils::FindLinkedPinWithAuthoritativePinType() to consolidate the code that considers other linked pins when choosing which type to propagate to type-dependent parameter pins.
	- Added FBlueprintEditorUtils::PropagatePinTypeInfo() to consolidate the common code from UK2Node_CallArrayFunction::PropagateArrayTypeInfo(); this eliminated a redundant retrieval of the target pin set.
	- Refactored UK2Node_CallArrayFunction::PropagateArrayTypeInfo() to now call FBlueprintEditorUtils::PropagatePinTypeInfo() after retrieving the set of dynamically-typed pins.
	- Refactored UK2Node_CallArrayFunction::NotifyPinConnectionListChanged() to remove some unnecessary iteration passes and to ensure that we propagate the authoritative (least common ancestor) pin type for object- and struct-based types.

Change 3376364 on 2017/04/03 by Richard.Hinckley

	UE-40920 Fix to Paper2D flipbook timeline editor. Previously, the timeline shown was one frame shorter than the animation. Now, the timeline shows the correct frame count.

Change 3376366 on 2017/04/03 by Richard.Hinckley

	UE-40920 Bugfix to Paper2D flipbook editor. The red line indicating the current frame now adjusts properly if the timeline is longer than the editor window and the scroll bar is moved to the right.

Change 3376517 on 2017/04/03 by Marc.Audy

	PR #3195: Added support for GamePad on RawInput Plugin (Contributed by katze7514)
	#jira UE-41499

Change 3376708 on 2017/04/03 by Mike.Beach

	Moving nativized plugins into a centralized folder (so we can use it as an additional plugin lookup dir) - this is so we can ultimately keep the generated code around for debugging purposes.

	Summary of changes:
	- nativized plugins now moved to ...\Intermediate\Plugins\<PLATFORM>\NativizedAssets
	- corresponding manifest files get saved inside the module and named to match the platform
	- nativized modules now whitelisted only for the platform they were generated for
	- cleanup on how we generate paths (now piping in platform name) and pass multi-cook process ids (for building manifest filenames)
	- extending the 'NativizeAssets' command line, so you can use it to specify the target plugin path (utilized by UAT to coordinate the plugin path between cook & build - was previously hardcoded in multiple places).

Change 3376826 on 2017/04/03 by Phillip.Kavan

	#jira UE-43330 - Fix a crash when adding an input parameter to a Custom Event node after deleting a Function Graph containing a Create Event node.

	Change summary:
	- Modified UK2Node_CreateDelegate::HandleAnyChangeWithoutNotifying() to check for a valid blueprint before accessing it (since the accessor is now a checked operation).
	- Modified UK2Node_CreateDelegate::GetScopeClass() to also check for a valid blueprint before accessing it.
	- Switched 'NULL' to 'nullptr' in a few spots.

Change 3376831 on 2017/04/03 by Ben.Zeigler

	#jira UE-43500, clean up UPackage when EDL/async loading fails. This restores EDL LoadPackage to work the same as non EDL and return NULL instead of an invalid empty package

Change 3376846 on 2017/04/03 by Ben.Zeigler

	#jira UE-38760 Properly refresh exec pins when removing pin from a Switch on Int node

Change 3376850 on 2017/04/03 by Dan.Oconnor

	Use authoritative class to mitigate compilation order issues

Change 3376961 on 2017/04/03 by Ben.Zeigler

	#jira UE-43127 Add struct ops implementations for FIntVector and FBox2d, any blueprint type needs struct ops to avoid crashes
	Fix Box2d variable name in NoExportTypes

Change 3376985 on 2017/04/03 by Ben.Zeigler

	#jira UE-43582 Remove Xbox-specific code from AssetRegistry because it won't work after my refactor. The serialization is much faster now and neither Bob nor I can conceive of a way this would take long enough to stall the main thread. If it it is somehow a problem, it should be wrapped in a slow task instead

Change 3377009 on 2017/04/03 by Ben.Zeigler

	#jira UE-43036 Fix crash when right clicking blueprint with no parent class. Ensures are fine but crashes should be avoided so people can try to copy data out of them

Change 3377054 on 2017/04/03 by Zak.Middleton

	#ue4 - Fix CharacterMovementComponent updated with very high delta time on server when initially joining. Make sure the ServerTimeStamp is initialized to current world time rather than zero to prevent large delta.

	#jira UE-40344
	#udn https://udn.unrealengine.com/questions/310497/large-delta-time-for-first-player-movement-update.html

Change 3377061 on 2017/04/03 by Dan.Oconnor

	Fixes for issues exposed by cooking with compilation manager. When cooking we end up with more blueprints compiling at a single time, which highlighted issues reading from generated classes while they were actively regenerating.

	Note that EInternalCompilerFlags::PostponeLocalsGenerationUntilPhaseTwo has only been added to mitigate risk - there is no known reason that existing compilation flows can't postpone generatation of local variables.

Change 3377073 on 2017/04/03 by Mike.Beach

	CIS fix - proper initialization ordering.

Change 3377371 on 2017/04/03 by Ben.Zeigler

	#jira UE-43144 Disallow creating map of FText, like bool it is not hashable

Change 3377395 on 2017/04/03 by Dan.Oconnor

	Build fix - make order in source match initialization order in artifact

Change 3377417 on 2017/04/03 by Dan.Oconnor

	Speculative SA fix

Change 3377496 on 2017/04/03 by Aaron.McLeran

	#jira UE-43558 Cleaning up shutdown code with audio plugins.

Change 3377608 on 2017/04/03 by Zak.Middleton

	#ue4 - Added function ACharacter::CacheInitialMeshOffset() to cache initial mesh offset, used as the target for network smoothing. Added a call to this function from BeginPlay() in addition to the existing call from PostInitializeComponents(), and exposed this to blueprints as well. This fixes the case of people moving the mesh in BeginPlay rather than in the editor or construction script and not having the mesh offset reflected correctly in network games.

	#jira UE-38966

Change 3377880 on 2017/04/03 by Aaron.McLeran

	Audio bug fixes

	#jira UE-43600  Fixing sounds played by playsoundatlocation for audio volume calculations
	#jira UE-43601 Fixing listener volume interpolation
	#jida UE-43602 Fixing reverb/eq interpolation

Change 3377908 on 2017/04/03 by Phillip.Kavan

	#jira UE-43565 - Fix a regression on type-dependent array function node pins that have more than one link.

	Change summary:
	- Added FBlueprintEditorUtils::FindLinkedPinWithMostDerivedPinType()
	- Modified FBlueprintEditorUtils::FindLinkedPinWithAuthoritativePinType() to properly handle pins that have multiple links.

Change 3377912 on 2017/04/03 by Dan.Oconnor

	Fix for missing SUBINSTANCE variables on anim BP skeletons. I elected to force SUBINSTANCE variable creation for the compilation manager codepath

Change 3377946 on 2017/04/03 by Ben.Zeigler

	#jira UE-43594 Fix issue with streamable manager where a failed load would leave bAsyncLoadRequestOutstanding, which would confuse later calls to stream the same asset
	Lower some error verbosity now that I believe I have tracked down the issue

Change 3377950 on 2017/04/03 by Michael.Noland

	Blueprints: Prevent merge tool from crashing in SVN when looking at a file with gaps in the revision history
	(May still not work correctly, but it won't crash; full fix covered by UE-43603)
	#jira UE-22428

Change 3377981 on 2017/04/03 by Michael.Noland

	PR #3416: UE-43005: Prevent crash due to too long name (Contributed by projectgheist)

	#jira UE-43291
	#jira UE-43005

Change 3378039 on 2017/04/04 by Michael.Noland

	PhysX: Allowed the editor to compile when bRuntimePhysicsCooking is disabled (WITH_EDITOR is used in every place in C++ to force it in already)

Change 3378041 on 2017/04/04 by Michael.Noland

	Paper2D: Adjusted under what circumstances CreatePhysicsMeshes is called on various Paper2D types to match UProceduralMeshComponent

Change 3378081 on 2017/04/04 by Dan.Oconnor

	Fix Blueprint Context nodes so that they don't rely on Ar.IsBeingSaved() call before compilation
	3x because of copy/paste

Change 3378094 on 2017/04/04 by Dan.Oconnor

	Add missing preload call for compilation manager

Change 3378917 on 2017/04/04 by Marc.Audy

	Fix static analysis (which is very dumb)

Change 3378986 on 2017/04/04 by Dan.Oconnor

	Fix bad merge

Change 3379100 on 2017/04/04 by Dan.Oconnor

	Fix missing CPF_ConstParm/CPF_ReferenceParm/CPF_OutParm logic in 'fast' skeleton path
	#jira UE-43629

Change 3379102 on 2017/04/04 by Ben.Zeigler

	Actually fix StreamableManager issues with cancelling a request messing up things in the future. We now always queue a request, even if it failed before or there is one in progress. This has to be done to avoid issues with cancelling the existing request or mounting new files after it's failed once
	Now that StreamableManager will retry missing files, add failed load packages to the known missing list so it won't spam errors over and over

Change 3379147 on 2017/04/04 by Zak.Middleton

	#ue4 - Improve on CL 3377608: Made Character::CacheInitialMeshOffset() take location and rotation params so you can be explicit on the values, in case you try to change these during network smoothing, where reading the relative offsets would have been skewed.

Change 3379254 on 2017/04/04 by Aaron.McLeran

	Fixing sounds in audio mixer when no EQ has been set.

Change 3379760 on 2017/04/04 by Ben.Zeigler

	#jira UE-43647 Don't delete failed async packages that are rooted

[CL 3380073 by Dan Oconnor in Main branch]
2017-04-04 20:49:52 -04:00

1476 lines
48 KiB
C++

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "AudioMixerSourceManager.h"
#include "AudioMixerSource.h"
#include "AudioMixerDevice.h"
#include "AudioMixerSourceVoice.h"
#include "AudioMixerSubmix.h"
#include "IAudioExtensionPlugin.h"
DEFINE_STAT(STAT_AudioMixerHRTF);
static int32 DisableParallelSourceProcessingCvar = 0;
FAutoConsoleVariableRef CVarDisableParallelSourceProcessing(
TEXT("au.DisableParallelSourceProcessing"),
DisableParallelSourceProcessingCvar,
TEXT("Disables using async tasks for processing sources.\n")
TEXT("0: Not Disabled, 1: Disabled"),
ECVF_Default);
#define ONEOVERSHORTMAX (3.0517578125e-5f) // 1/32768
#define ENVELOPE_TAIL_THRESHOLD (1.58489e-5f) // -96 dB
#define VALIDATE_SOURCE_MIXER_STATE 1
namespace Audio
{
FSourceParam::FSourceParam(float InNumInterpFrames)
: StartValue(0.0f)
, EndValue(0.0f)
, CurrentValue(0.0f)
, NumInterpFrames(InNumInterpFrames)
, NumInterpFramesInverse(0.0f)
, Frame(0.0f)
, bIsInit(true)
, bIsDone(false)
{
NumInterpFramesInverse = (NumInterpFrames == 0.0f ? 0.0f : (1.0f / NumInterpFrames));
}
void FSourceParam::Reset()
{
bIsInit = true;
}
void FSourceParam::SetValue(float InValue)
{
if (bIsInit || NumInterpFrames == 0.0f)
{
bIsInit = false;
CurrentValue = InValue;
StartValue = InValue;
EndValue = InValue;
Frame = NumInterpFrames;
if (NumInterpFrames == 0.0f)
{
bIsDone = true;
}
else
{
bIsDone = false;
}
}
else
{
StartValue = CurrentValue;
EndValue = InValue;
Frame = 0.0f;
bIsDone = false;
}
}
float FSourceParam::Update()
{
if (!bIsDone)
{
float Alpha = Frame * NumInterpFramesInverse;
if (Alpha >= 1.0f)
{
bIsDone = true;
CurrentValue = EndValue;
}
else
{
CurrentValue = FMath::Lerp(StartValue, EndValue, Alpha);
}
Frame += 1.0f;
}
return CurrentValue;
}
float FSourceParam::GetValue() const
{
return CurrentValue;
}
/*************************************************************************
* FMixerSourceManager::FSourceInfo
**************************************************************************/
FMixerSourceManager::FSourceInfo::FSourceInfo()
: PitchSourceParam(FSourceParam(128))
, VolumeSourceParam(FSourceParam(256))
, LPFCutoffFrequencyParam(FSourceParam(128))
, ChannelMapParam(FSourceChannelMap(256))
{
// Note: initialization is all done by FMixerSourceManager::Init
}
FMixerSourceManager::FSourceInfo::~FSourceInfo()
{
}
/*************************************************************************
* FMixerSourceManager
**************************************************************************/
FMixerSourceManager::FMixerSourceManager(FMixerDevice* InMixerDevice)
: MixerDevice(InMixerDevice)
, NumActiveSources(0)
, NumTotalSources(0)
, NumSourceWorkers(4)
, bInitialized(false)
{
}
FMixerSourceManager::~FMixerSourceManager()
{
if (SourceWorkers.Num() > 0)
{
for (int32 i = 0; i < SourceWorkers.Num(); ++i)
{
delete SourceWorkers[i];
SourceWorkers[i] = nullptr;
}
SourceWorkers.Reset();
}
}
void FMixerSourceManager::Init(const FSourceManagerInitParams& InitParams)
{
AUDIO_MIXER_CHECK(InitParams.NumSources > 0);
if (bInitialized || !MixerDevice)
{
return;
}
AUDIO_MIXER_CHECK(MixerDevice->GetSampleRate() > 0);
NumTotalSources = InitParams.NumSources;
MixerSources.Init(nullptr, NumTotalSources);
SourceInfos.AddDefaulted(NumTotalSources);
for (int32 i = 0; i < NumTotalSources; ++i)
{
FSourceInfo& SourceInfo = SourceInfos[i];
//SourceInfo.BufferQueue
SourceInfo.BufferQueueListener = nullptr;
SourceInfo.CurrentPCMBuffer = nullptr;
SourceInfo.CurrentAudioChunkNumFrames = 0;
//SourceInfo.SourceBuffer
//SourceInfo.AudioPluginOutputData
//SourceInfo.CurrentFrameValues
//SourceINfo.NextFrameValues
SourceInfo.CurrentFrameAlpha = 0.0f;
SourceInfo.CurrentFrameIndex = 0;
SourceInfo.NumFramesPlayed = 0;
// These are in the constructor
//SourceInfo.PitchSourceParam = FSourceParam(128);
//SourceInfo.VolumeSourceParam = FSourceParam(256);
//SourceInfo.LPFCutoffFrequencyParam = FSourceParam(128);
//SourceInfo.ChannelMapParam = FSourceChannelMap(256);
//SourceInfo.SpatParams
//SourceInfo.ScratchChannelMap
//SourceInfo.LowPassFilters
SourceInfo.SourceEffectChainId = INDEX_NONE;
//SourceInfo.SourceEffects
//SourceInfo.SourceEffectPresets
SourceInfo.SourceEnvelopeFollower = Audio::FEnvelopeFollower(AUDIO_SAMPLE_RATE, 10, 100, Audio::EPeakMode::Peak);
SourceInfo.SourceEnvelopeValue = 0.0f;
SourceInfo.bEffectTailsDone = false;
//SourceInfo.SourceEffectInputData
//SourceInfo.SourceEffectOutputData
//SourceInfo.ReverbPluginOutputBuffer
SourceInfo.PostEffectBuffers = nullptr;
//SourceInfo.OutputBuffer
SourceInfo.bIs3D = false;
SourceInfo.bIsCenterChannelOnly = false;
SourceInfo.bIsActive = false;
SourceInfo.bIsPlaying = false;
SourceInfo.bIsPaused = false;
SourceInfo.bIsDone = false;
SourceInfo.bIsBusy = false;
SourceInfo.bUseHRTFSpatializer = false;
SourceInfo.bUseOcclusionPlugin = false;
SourceInfo.bUseReverbPlugin = false;
SourceInfo.bHasStarted = false;
SourceInfo.bIsDebugMode = false;
//SourceInfo.DebugName
SourceInfo.NumInputChannels = 0;
SourceInfo.NumPostEffectChannels = 0;
SourceInfo.NumInputFrames = 0;
}
GameThreadInfo.bIsBusy.AddDefaulted(NumTotalSources);
GameThreadInfo.bIsDone.AddDefaulted(NumTotalSources);
GameThreadInfo.bEffectTailsDone.AddDefaulted(NumTotalSources);
GameThreadInfo.bNeedsSpeakerMap.AddDefaulted(NumTotalSources);
GameThreadInfo.bIsDebugMode.AddDefaulted(NumTotalSources);
GameThreadInfo.FreeSourceIndices.Reset(NumTotalSources);
for (int32 i = NumTotalSources - 1; i >= 0; --i)
{
GameThreadInfo.FreeSourceIndices.Add(i);
}
// Initialize the source buffer memory usage to max source scratch buffers (num frames times max source channels)
const int32 NumFrames = MixerDevice->GetNumOutputFrames();
for (int32 SourceId = 0; SourceId < NumTotalSources; ++SourceId)
{
FSourceInfo& SourceInfo = SourceInfos[SourceId];
SourceInfo.SourceBuffer.Reset(NumFrames * 8);
SourceInfo.AudioPluginOutputData.AudioBuffer.Reset(NumFrames * 2);
}
// Setup the source workers
SourceWorkers.Reset();
if (NumSourceWorkers > 0)
{
const int32 NumSourcesPerWorker = NumTotalSources / NumSourceWorkers;
int32 StartId = 0;
int32 EndId = 0;
while (EndId < NumTotalSources)
{
EndId = FMath::Min(StartId + NumSourcesPerWorker, NumTotalSources);
SourceWorkers.Add(new FAsyncTask<FAudioMixerSourceWorker>(this, StartId, EndId));
StartId = EndId;
}
}
AUDIO_MIXER_CHECK(SourceWorkers.Num() == NumSourceWorkers);
bInitialized = true;
bPumpQueue = false;
}
void FMixerSourceManager::Update()
{
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
#if VALIDATE_SOURCE_MIXER_STATE
for (int32 i = 0; i < NumTotalSources; ++i)
{
if (!GameThreadInfo.bIsBusy[i])
{
// Make sure that our bIsFree and FreeSourceIndices are correct
AUDIO_MIXER_CHECK(GameThreadInfo.FreeSourceIndices.Contains(i) == true);
}
}
#endif
// Pump the source command queue from the game thread to make sure
// playsound calls, param updates, etc, all happen simultaneously
bPumpQueue = true;
}
void FMixerSourceManager::ReleaseSource(const int32 SourceId)
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
AUDIO_MIXER_CHECK(SourceId < NumTotalSources);
AUDIO_MIXER_CHECK(bInitialized);
AUDIO_MIXER_CHECK(MixerSources[SourceId] != nullptr);
AUDIO_MIXER_DEBUG_LOG(SourceId, TEXT("Is releasing"));
FSourceInfo& SourceInfo = SourceInfos[SourceId];
#if AUDIO_MIXER_ENABLE_DEBUG_MODE
if (SourceInfo.bIsDebugMode)
{
DebugSoloSources.Remove(SourceId);
}
#endif
// Call OnRelease on the BufferQueueListener to give it a chance
// to release any resources it owns on the audio render thread
if (SourceInfo.BufferQueueListener)
{
SourceInfo.BufferQueueListener->OnRelease();
SourceInfo.BufferQueueListener = nullptr;
}
// Remove the mixer source from its submix sends
TMap<uint32, FMixerSourceSubmixSend>& SubmixSends = MixerSources[SourceId]->GetSubmixSends();
for (auto SubmixSendItem : SubmixSends)
{
SubmixSendItem.Value.Submix->RemoveSourceVoice(MixerSources[SourceId]);
}
// Delete the source effects
SourceInfo.SourceEffectChainId = INDEX_NONE;
ResetSourceEffectChain(SourceId);
SourceInfo.SourceEnvelopeFollower.Reset();
SourceInfo.bEffectTailsDone = true;
// Delete the mixer source and null the slot
delete MixerSources[SourceId];
MixerSources[SourceId] = nullptr;
// Reset all state and data
SourceInfo.PitchSourceParam.Reset();
SourceInfo.VolumeSourceParam.Reset();
SourceInfo.LPFCutoffFrequencyParam.Reset();
SourceInfo.LowPassFilters.Reset();
SourceInfo.ChannelMapParam.Reset();
SourceInfo.BufferQueue.Empty();
SourceInfo.CurrentPCMBuffer = nullptr;
SourceInfo.CurrentAudioChunkNumFrames = 0;
SourceInfo.SourceBuffer.Reset();
SourceInfo.AudioPluginOutputData.AudioBuffer.Reset();
SourceInfo.CurrentFrameValues.Reset();
SourceInfo.NextFrameValues.Reset();
SourceInfo.CurrentFrameAlpha = 0.0f;
SourceInfo.CurrentFrameIndex = 0;
SourceInfo.NumFramesPlayed = 0;
SourceInfo.PostEffectBuffers = nullptr;
SourceInfo.OutputBuffer.Reset();
SourceInfo.bIs3D = false;
SourceInfo.bIsCenterChannelOnly = false;
SourceInfo.bIsActive = false;
SourceInfo.bIsPlaying = false;
SourceInfo.bIsDone = true;
SourceInfo.bIsPaused = false;
SourceInfo.bIsBusy = false;
SourceInfo.bUseHRTFSpatializer = false;
SourceInfo.bUseOcclusionPlugin = false;
SourceInfo.bUseReverbPlugin = false;
SourceInfo.bHasStarted = false;
SourceInfo.bIsDebugMode = false;
SourceInfo.DebugName = FString();
SourceInfo.NumInputChannels = 0;
SourceInfo.NumPostEffectChannels = 0;
GameThreadInfo.bNeedsSpeakerMap[SourceId] = false;
}
void FMixerSourceManager::BuildSourceEffectChain(const int32 SourceId, FSoundEffectSourceInitData& InitData, const TArray<FSourceEffectChainEntry>& InSourceEffectChain)
{
// Create new source effects. The memory will be owned by the source manager.
for (const FSourceEffectChainEntry& ChainEntry : InSourceEffectChain)
{
// Presets can have null entries
if (!ChainEntry.Preset)
{
continue;
}
FSoundEffectSource* NewEffect = static_cast<FSoundEffectSource*>(ChainEntry.Preset->CreateNewEffect());
NewEffect->RegisterWithPreset(ChainEntry.Preset);
// Get this source effect presets unique id so instances can identify their originating preset object
const uint32 PresetUniqueId = ChainEntry.Preset->GetUniqueID();
InitData.ParentPresetUniqueId = PresetUniqueId;
NewEffect->Init(InitData);
NewEffect->SetPreset(ChainEntry.Preset);
NewEffect->SetEnabled(!ChainEntry.bBypass);
// Add the effect instance
FSourceInfo& SourceInfo = SourceInfos[SourceId];
SourceInfo.SourceEffects.Add(NewEffect);
// Add a slot entry for the preset so it can change while running. This will get sent to the running effect instance if the preset changes.
SourceInfo.SourceEffectPresets.Add(nullptr);
}
}
void FMixerSourceManager::ResetSourceEffectChain(const int32 SourceId)
{
FSourceInfo& SourceInfo = SourceInfos[SourceId];
for (int32 i = 0; i < SourceInfo.SourceEffects.Num(); ++i)
{
SourceInfo.SourceEffects[i]->UnregisterWithPreset();
delete SourceInfo.SourceEffects[i];
SourceInfo.SourceEffects[i] = nullptr;
}
SourceInfo.SourceEffects.Reset();
for (int32 i = 0; i < SourceInfo.SourceEffectPresets.Num(); ++i)
{
SourceInfo.SourceEffectPresets[i] = nullptr;
}
SourceInfo.SourceEffectPresets.Reset();
}
bool FMixerSourceManager::GetFreeSourceId(int32& OutSourceId)
{
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
if (GameThreadInfo.FreeSourceIndices.Num())
{
OutSourceId = GameThreadInfo.FreeSourceIndices.Pop();
AUDIO_MIXER_CHECK(OutSourceId < NumTotalSources);
AUDIO_MIXER_CHECK(!GameThreadInfo.bIsBusy[OutSourceId]);
AUDIO_MIXER_CHECK(!GameThreadInfo.bIsDebugMode[OutSourceId]);
AUDIO_MIXER_CHECK(NumActiveSources < NumTotalSources);
++NumActiveSources;
GameThreadInfo.bIsBusy[OutSourceId] = true;
return true;
}
AUDIO_MIXER_CHECK(false);
return false;
}
int32 FMixerSourceManager::GetNumActiveSources() const
{
return NumActiveSources;
}
void FMixerSourceManager::InitSource(const int32 SourceId, const FMixerSourceVoiceInitParams& InitParams)
{
AUDIO_MIXER_CHECK(SourceId < NumTotalSources);
AUDIO_MIXER_CHECK(GameThreadInfo.bIsBusy[SourceId]);
AUDIO_MIXER_CHECK(!GameThreadInfo.bIsDebugMode[SourceId]);
AUDIO_MIXER_CHECK(InitParams.BufferQueueListener != nullptr);
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
#if AUDIO_MIXER_ENABLE_DEBUG_MODE
GameThreadInfo.bIsDebugMode[SourceId] = InitParams.bIsDebugMode;
#endif
AudioMixerThreadCommand([this, SourceId, InitParams]()
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
AUDIO_MIXER_CHECK(InitParams.SourceVoice != nullptr);
FSourceInfo& SourceInfo = SourceInfos[SourceId];
SourceInfo.bIsPlaying = false;
SourceInfo.bIsPaused = false;
SourceInfo.bIsActive = true;
SourceInfo.bIsBusy = true;
SourceInfo.bIsDone = false;
SourceInfo.bUseHRTFSpatializer = InitParams.bUseHRTFSpatialization;
SourceInfo.BufferQueueListener = InitParams.BufferQueueListener;
SourceInfo.NumInputChannels = InitParams.NumInputChannels;
SourceInfo.NumInputFrames = InitParams.NumInputFrames;
// Initialize the number of per-source LPF filters based on input channels
SourceInfo.LowPassFilters.AddDefaulted(InitParams.NumInputChannels);
// Setup the spatialization settings preset
if (InitParams.SpatializationPluginSettings != nullptr)
{
MixerDevice->SpatializationPluginInterface->SetSpatializationSettings(SourceId, InitParams.SpatializationPluginSettings);
}
// Setup the occlusion settings preset
if (InitParams.OcclusionPluginSettings != nullptr)
{
MixerDevice->OcclusionInterface->SetOcclusionSettings(SourceId, InitParams.OcclusionPluginSettings);
SourceInfo.bUseOcclusionPlugin = true;
}
// Setup the reverb settings preset
if (InitParams.ReverbPluginSettings != nullptr)
{
MixerDevice->ReverbPluginInterface->SetReverbSettings(SourceId, InitParams.AudioComponentUserID, InitParams.ReverbPluginSettings);
SourceInfo.bUseReverbPlugin = true;
}
// Default all sounds to not consider effect chain tails when playing
SourceInfo.bEffectTailsDone = true;
// Copy the source effect chain if the channel count is 1 or 2
if (InitParams.NumInputChannels <= 2)
{
// If we're told to care about effect chain tails, then we're not allowed
// to stop playing until the effect chain tails are finished
SourceInfo.bEffectTailsDone = !InitParams.bPlayEffectChainTails;
FSoundEffectSourceInitData InitData;
InitData.SampleRate = AUDIO_SAMPLE_RATE;
InitData.NumSourceChannels = InitParams.NumInputChannels;
InitData.AudioClock = MixerDevice->GetAudioTime();
if (InitParams.NumInputFrames != INDEX_NONE)
{
InitData.SourceDuration = (float)InitParams.NumInputFrames / AUDIO_SAMPLE_RATE;
}
else
{
// Procedural sound waves have no known duration
InitData.SourceDuration = (float)INDEX_NONE;
}
SourceInfo.SourceEffectChainId = InitParams.SourceEffectChainId;
BuildSourceEffectChain(SourceId, InitData, InitParams.SourceEffectChain);
}
SourceInfo.CurrentFrameValues.Init(0.0f, InitParams.NumInputChannels);
SourceInfo.NextFrameValues.Init(0.0f, InitParams.NumInputChannels);
AUDIO_MIXER_CHECK(MixerSources[SourceId] == nullptr);
MixerSources[SourceId] = InitParams.SourceVoice;
// Loop through the source's sends and add this source to those submixes with the send info
for (int32 i = 0; i < InitParams.SubmixSends.Num(); ++i)
{
const FMixerSourceSubmixSend& MixerSourceSend = InitParams.SubmixSends[i];
MixerSourceSend.Submix->AddOrSetSourceVoice(InitParams.SourceVoice, MixerSourceSend.SendLevel);
}
#if AUDIO_MIXER_ENABLE_DEBUG_MODE
AUDIO_MIXER_CHECK(!SourceInfo.bIsDebugMode);
SourceInfo.bIsDebugMode = InitParams.bIsDebugMode;
AUDIO_MIXER_CHECK(SourceInfo.DebugName.IsEmpty());
SourceInfo.DebugName = InitParams.DebugName;
#endif
AUDIO_MIXER_DEBUG_LOG(SourceId, TEXT("Is initializing"));
});
}
void FMixerSourceManager::ReleaseSourceId(const int32 SourceId)
{
AUDIO_MIXER_CHECK(GameThreadInfo.bIsBusy[SourceId]);
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
AUDIO_MIXER_CHECK(NumActiveSources > 0);
--NumActiveSources;
GameThreadInfo.bIsBusy[SourceId] = false;
#if AUDIO_MIXER_ENABLE_DEBUG_MODE
GameThreadInfo.bIsDebugMode[SourceId] = false;
#endif
GameThreadInfo.FreeSourceIndices.Push(SourceId);
AUDIO_MIXER_CHECK(GameThreadInfo.FreeSourceIndices.Contains(SourceId));
AudioMixerThreadCommand([this, SourceId]()
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
ReleaseSource(SourceId);
});
}
void FMixerSourceManager::Play(const int32 SourceId)
{
AUDIO_MIXER_CHECK(SourceId < NumTotalSources);
AUDIO_MIXER_CHECK(GameThreadInfo.bIsBusy[SourceId]);
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
AudioMixerThreadCommand([this, SourceId]()
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
FSourceInfo& SourceInfo = SourceInfos[SourceId];
SourceInfo.bIsPlaying = true;
SourceInfo.bIsPaused = false;
SourceInfo.bIsActive = true;
AUDIO_MIXER_DEBUG_LOG(SourceId, TEXT("Is playing"));
});
}
void FMixerSourceManager::Stop(const int32 SourceId)
{
AUDIO_MIXER_CHECK(SourceId < NumTotalSources);
AUDIO_MIXER_CHECK(GameThreadInfo.bIsBusy[SourceId]);
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
AudioMixerThreadCommand([this, SourceId]()
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
FSourceInfo& SourceInfo = SourceInfos[SourceId];
SourceInfo.bIsPlaying = false;
SourceInfo.bIsPaused = false;
SourceInfo.bIsActive = false;
AUDIO_MIXER_DEBUG_LOG(SourceId, TEXT("Is stopping"));
});
}
void FMixerSourceManager::Pause(const int32 SourceId)
{
AUDIO_MIXER_CHECK(SourceId < NumTotalSources);
AUDIO_MIXER_CHECK(GameThreadInfo.bIsBusy[SourceId]);
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
AudioMixerThreadCommand([this, SourceId]()
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
FSourceInfo& SourceInfo = SourceInfos[SourceId];
SourceInfo.bIsPaused = true;
SourceInfo.bIsActive = false;
});
}
void FMixerSourceManager::SetPitch(const int32 SourceId, const float Pitch)
{
AUDIO_MIXER_CHECK(SourceId < NumTotalSources);
AUDIO_MIXER_CHECK(GameThreadInfo.bIsBusy[SourceId]);
AudioMixerThreadCommand([this, SourceId, Pitch]()
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
SourceInfos[SourceId].PitchSourceParam.SetValue(Pitch);
});
}
void FMixerSourceManager::SetVolume(const int32 SourceId, const float Volume)
{
AUDIO_MIXER_CHECK(SourceId < NumTotalSources);
AUDIO_MIXER_CHECK(GameThreadInfo.bIsBusy[SourceId]);
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
AudioMixerThreadCommand([this, SourceId, Volume]()
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
SourceInfos[SourceId].VolumeSourceParam.SetValue(Volume);
});
}
void FMixerSourceManager::SetSpatializationParams(const int32 SourceId, const FSpatializationParams& InParams)
{
AUDIO_MIXER_CHECK(SourceId < NumTotalSources);
AUDIO_MIXER_CHECK(GameThreadInfo.bIsBusy[SourceId]);
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
AudioMixerThreadCommand([this, SourceId, InParams]()
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
SourceInfos[SourceId].SpatParams = InParams;
});
}
void FMixerSourceManager::SetChannelMap(const int32 SourceId, const TArray<float>& ChannelMap, const bool bInIs3D, const bool bInIsCenterChannelOnly)
{
AUDIO_MIXER_CHECK(SourceId < NumTotalSources);
AUDIO_MIXER_CHECK(GameThreadInfo.bIsBusy[SourceId]);
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
AudioMixerThreadCommand([this, SourceId, ChannelMap, bInIs3D, bInIsCenterChannelOnly]()
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
FSourceInfo& SourceInfo = SourceInfos[SourceId];
// Set whether or not this is a 3d channel map and if its center channel only. Used for reseting channel maps on device change.
SourceInfo.bIs3D = bInIs3D;
SourceInfo.bIsCenterChannelOnly = bInIsCenterChannelOnly;
// Fix up the channel map in case device output count changed
const int32 NumSourceChannels = SourceInfo.bUseHRTFSpatializer ? 2 : SourceInfo.NumInputChannels;
const int32 NumOutputChannels = MixerDevice->GetNumDeviceChannels();
const int32 ChannelMapSize = NumSourceChannels * NumOutputChannels;
// If this is true, then the device changed while the command was in-flight
if (ChannelMap.Num() != ChannelMapSize)
{
TArray<float> NewChannelMap;
// If 3d then just zero it out, we'll get another channel map shortly
if (bInIs3D)
{
NewChannelMap.AddZeroed(ChannelMapSize);
GameThreadInfo.bNeedsSpeakerMap[SourceId] = true;
}
// Otherwise, get an appropriate channel map for the new device configuration
else
{
MixerDevice->Get2DChannelMap(NumSourceChannels, NumOutputChannels, bInIsCenterChannelOnly, NewChannelMap);
}
SourceInfo.ChannelMapParam.SetChannelMap(NewChannelMap);
}
else
{
GameThreadInfo.bNeedsSpeakerMap[SourceId] = false;
SourceInfo.ChannelMapParam.SetChannelMap(ChannelMap);
}
});
}
void FMixerSourceManager::SetLPFFrequency(const int32 SourceId, const float InLPFFrequency)
{
AUDIO_MIXER_CHECK(SourceId < NumTotalSources);
AUDIO_MIXER_CHECK(GameThreadInfo.bIsBusy[SourceId]);
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
AudioMixerThreadCommand([this, SourceId, InLPFFrequency]()
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
float SampleRate = MixerDevice->GetSampleRate();
AUDIO_MIXER_CHECK(SampleRate > 0.0f);
const float NormalizedFrequency = 2.0f * InLPFFrequency / SampleRate;
SourceInfos[SourceId].LPFCutoffFrequencyParam.SetValue(NormalizedFrequency);
});
}
void FMixerSourceManager::SubmitBuffer(const int32 SourceId, FMixerSourceBufferPtr InSourceVoiceBuffer, const bool bSubmitSynchronously)
{
AUDIO_MIXER_CHECK(SourceId < NumTotalSources);
AUDIO_MIXER_CHECK(InSourceVoiceBuffer->AudioBytes <= (uint32)InSourceVoiceBuffer->AudioData.Num());
// If we're submitting synchronously then don't use AudioMixerThreadCommand but submit directly
if (bSubmitSynchronously)
{
SourceInfos[SourceId].BufferQueue.Enqueue(InSourceVoiceBuffer);
}
else
{
// make sure we're on the game/audio thread
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
// Use a thread command
AudioMixerThreadCommand([this, SourceId, InSourceVoiceBuffer]()
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
SourceInfos[SourceId].BufferQueue.Enqueue(InSourceVoiceBuffer);
});
}
}
void FMixerSourceManager::SetSubmixSendInfo(const int32 SourceId, FMixerSubmixPtr Submix, const float SendLevel)
{
AUDIO_MIXER_CHECK(SourceId < NumTotalSources);
AUDIO_MIXER_CHECK(GameThreadInfo.bIsBusy[SourceId]);
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
AudioMixerThreadCommand([this, SourceId, Submix, SendLevel]()
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
Submix->AddOrSetSourceVoice(MixerSources[SourceId], SendLevel);
});
}
int64 FMixerSourceManager::GetNumFramesPlayed(const int32 SourceId) const
{
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
return SourceInfos[SourceId].NumFramesPlayed;
}
bool FMixerSourceManager::IsDone(const int32 SourceId) const
{
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
return GameThreadInfo.bIsDone[SourceId];
}
bool FMixerSourceManager::IsEffectTailsDone(const int32 SourceId) const
{
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
return GameThreadInfo.bEffectTailsDone[SourceId];
}
bool FMixerSourceManager::NeedsSpeakerMap(const int32 SourceId) const
{
AUDIO_MIXER_CHECK_GAME_THREAD(MixerDevice);
return GameThreadInfo.bNeedsSpeakerMap[SourceId];
}
void FMixerSourceManager::ReadSourceFrame(const int32 SourceId)
{
FSourceInfo& SourceInfo = SourceInfos[SourceId];
const int32 NumChannels = SourceInfo.NumInputChannels;
// Check if the next frame index is out of range of the total number of frames we have in our current audio buffer
bool bNextFrameOutOfRange = (SourceInfo.CurrentFrameIndex + 1) >= SourceInfo.CurrentAudioChunkNumFrames;
bool bCurrentFrameOutOfRange = SourceInfo.CurrentFrameIndex >= SourceInfo.CurrentAudioChunkNumFrames;
bool bReadCurrentFrame = true;
// Check the boolean conditions that determine if we need to pop buffers from our queue (in PCMRT case) *OR* loop back (looping PCM data)
while (bNextFrameOutOfRange || bCurrentFrameOutOfRange)
{
// If our current frame is in range, but next frame isn't, read the current frame now to avoid pops when transitioning between buffers
if (bNextFrameOutOfRange && !bCurrentFrameOutOfRange)
{
// Don't need to read the current frame audio after reading new audio chunk
bReadCurrentFrame = false;
AUDIO_MIXER_CHECK(SourceInfo.CurrentPCMBuffer.IsValid());
const int16* AudioData = (const int16*)SourceInfo.CurrentPCMBuffer->AudioData.GetData();
const int32 CurrentSampleIndex = SourceInfo.CurrentFrameIndex * NumChannels;
for (int32 Channel = 0; Channel < NumChannels; ++Channel)
{
SourceInfo.CurrentFrameValues[Channel] = (float)AudioData[CurrentSampleIndex + Channel] * ONEOVERSHORTMAX;
}
}
// If this is our first PCM buffer, we don't need to do a callback to get more audio
if (SourceInfo.CurrentPCMBuffer.IsValid())
{
if (SourceInfo.CurrentPCMBuffer->LoopCount == Audio::LOOP_FOREVER && !SourceInfo.CurrentPCMBuffer->bRealTimeBuffer)
{
AUDIO_MIXER_DEBUG_LOG(SourceId, TEXT("Hit Loop boundary, looping."));
SourceInfo.CurrentFrameIndex = FMath::Max(SourceInfo.CurrentFrameIndex - SourceInfo.CurrentAudioChunkNumFrames, 0);
break;
}
SourceInfo.BufferQueueListener->OnSourceBufferEnd();
}
// If we have audio in our queue, we're still playing
if (!SourceInfo.BufferQueue.IsEmpty())
{
FMixerSourceBufferPtr NewBufferPtr;
SourceInfo.BufferQueue.Dequeue(NewBufferPtr);
SourceInfo.CurrentPCMBuffer = NewBufferPtr;
AUDIO_MIXER_CHECK(MixerSources[SourceId]->NumBuffersQueued.GetValue() > 0);
MixerSources[SourceId]->NumBuffersQueued.Decrement();
SourceInfo.CurrentAudioChunkNumFrames = SourceInfo.CurrentPCMBuffer->AudioBytes / (NUM_BYTES_PER_SAMPLE * NumChannels);
// Subtract the number of frames in the current buffer from our frame index.
// Note: if this is the first time we're playing, CurrentFrameIndex will be 0
if (bReadCurrentFrame)
{
SourceInfo.CurrentFrameIndex = FMath::Max(SourceInfo.CurrentFrameIndex - SourceInfo.CurrentAudioChunkNumFrames, 0);
}
else
{
// Since we're not reading the current frame, we allow the current frame index to be negative (NextFrameIndex will then be 0)
// This prevents dropping a frame of audio on the buffer boundary
SourceInfo.CurrentFrameIndex = -1;
}
}
else
{
SourceInfo.bIsDone = true;
return;
}
bNextFrameOutOfRange = (SourceInfo.CurrentFrameIndex + 1) >= SourceInfo.CurrentAudioChunkNumFrames;
bCurrentFrameOutOfRange = SourceInfo.CurrentFrameIndex >= SourceInfo.CurrentAudioChunkNumFrames;
}
if (SourceInfo.CurrentPCMBuffer.IsValid())
{
// Grab the 16-bit PCM audio data (which could be a new audio chunk from previous ReadSourceFrame call)
const int16* AudioData = (const int16*)SourceInfo.CurrentPCMBuffer->AudioData.GetData();
const int32 NextSampleIndex = (SourceInfo.CurrentFrameIndex + 1) * NumChannels;
if (bReadCurrentFrame)
{
const int32 CurrentSampleIndex = SourceInfo.CurrentFrameIndex * NumChannels;
for (int32 Channel = 0; Channel < NumChannels; ++Channel)
{
SourceInfo.CurrentFrameValues[Channel] = (float)AudioData[CurrentSampleIndex + Channel] * ONEOVERSHORTMAX;
SourceInfo.NextFrameValues[Channel] = (float)AudioData[NextSampleIndex + Channel] * ONEOVERSHORTMAX;
}
}
else
{
for (int32 Channel = 0; Channel < NumChannels; ++Channel)
{
SourceInfo.NextFrameValues[Channel] = (float)AudioData[NextSampleIndex + Channel] * ONEOVERSHORTMAX;
}
}
}
}
void FMixerSourceManager::ComputeSourceBuffersForIdRange(const int32 SourceIdStart, const int32 SourceIdEnd)
{
SCOPE_CYCLE_COUNTER(STAT_AudioMixerSourceBuffers);
const int32 NumFrames = MixerDevice->GetNumOutputFrames();
// Local variable used for sample values
float SampleValue = 0.0f;
for (int32 SourceId = SourceIdStart; SourceId < SourceIdEnd; ++SourceId)
{
FSourceInfo& SourceInfo = SourceInfos[SourceId];
SourceInfo.SourceBuffer.Reset();
if (!SourceInfo.bIsBusy || !SourceInfo.bIsPlaying || SourceInfo.bIsPaused)
{
continue;
}
// Fill array with elements all at once to avoid sequential Add() operation overhead.
const int32 NumSourceChannels = SourceInfo.NumInputChannels;
SourceInfo.SourceBuffer.AddUninitialized(NumFrames * NumSourceChannels);
int32 SampleIndex = 0;
for (int32 Frame = 0; Frame < NumFrames; ++Frame)
{
// If the source is done, then we'll just write out 0s
if (!SourceInfo.bIsDone)
{
// Whether or not we need to read another sample from the source buffers
// If we haven't yet played any frames, then we will need to read the first source samples no matter what
bool bReadNextSample = !SourceInfo.bHasStarted;
// Reset that we've started generating audio
SourceInfo.bHasStarted = true;
// Update the PrevFrameIndex value for the source based on alpha value
while (SourceInfo.CurrentFrameAlpha >= 1.0f)
{
// Our inter-frame alpha lerping value is causing us to read new source frames
bReadNextSample = true;
// Bump up the current frame index
SourceInfo.CurrentFrameIndex++;
// Bump up the frames played -- this is tracking the total frames in source file played
// CurrentFrameIndex can wrap for looping sounds so won't be accurate in that case
SourceInfo.NumFramesPlayed++;
SourceInfo.CurrentFrameAlpha -= 1.0f;
}
// If our alpha parameter caused us to jump to a new source frame, we need
// read new samples into our prev and next frame sample data
if (bReadNextSample)
{
ReadSourceFrame(SourceId);
}
}
// If we've finished reading all buffer data, then just write out 0s
if (SourceInfo.bIsDone)
{
for (int32 Channel = 0; Channel < NumSourceChannels; ++Channel)
{
SourceInfo.SourceBuffer[SampleIndex++] = 0.0f;
}
}
else
{
// Get the volume value of the source at this frame index
for (int32 Channel = 0; Channel < NumSourceChannels; ++Channel)
{
const float CurrFrameValue = SourceInfo.CurrentFrameValues[Channel];
const float NextFrameValue = SourceInfo.NextFrameValues[Channel];
const float CurrentAlpha = SourceInfo.CurrentFrameAlpha;
SampleValue = FMath::Lerp(CurrFrameValue, NextFrameValue, CurrentAlpha);
SourceInfo.SourceBuffer[SampleIndex++] = SampleValue;
}
const float CurrentPitchScale = SourceInfo.PitchSourceParam.Update();
SourceInfo.CurrentFrameAlpha += CurrentPitchScale;
}
}
}
}
void FMixerSourceManager::ComputePostSourceEffectBufferForIdRange(const int32 SourceIdStart, const int32 SourceIdEnd)
{
SCOPE_CYCLE_COUNTER(STAT_AudioMixerSourceEffectBuffers);
const int32 NumFrames = MixerDevice->GetNumOutputFrames();
const bool bIsDebugModeEnabled = DebugSoloSources.Num() > 0;
for (int32 SourceId = SourceIdStart; SourceId < SourceIdEnd; ++SourceId)
{
FSourceInfo& SourceInfo = SourceInfos[SourceId];
if (!SourceInfo.bIsBusy || !SourceInfo.bIsPlaying || SourceInfo.bIsPaused)
{
continue;
}
// Get the source buffer
TArray<float>& Buffer = SourceInfo.SourceBuffer;
const int32 NumInputChans = SourceInfo.NumInputChannels;
float CurrentVolumeValue = SourceInfo.VolumeSourceParam.GetValue();
// Process the per-source LPF if the source hasn't actually been finished
if (!SourceInfo.bIsDone)
{
for (int32 Frame = 0; Frame < NumFrames; ++Frame)
{
FSourceParam& LPFFrequencyParam = SourceInfo.LPFCutoffFrequencyParam;
// Update the frequency at the block rate
const float LPFFreq = LPFFrequencyParam.Update();
// Update the volume
#if AUDIO_MIXER_ENABLE_DEBUG_MODE
CurrentVolumeValue = (bIsDebugModeEnabled && !SourceInfo.bIsDebugMode) ? 0.0f : SourceInfo.VolumeSourceParam.Update();
#else
CurrentVolumeValue = SourceInfo.VolumeSourceParam.Update();
#endif
for (int32 Channel = 0; Channel < NumInputChans; ++Channel)
{
SourceInfo.LowPassFilters[Channel].SetFrequency(LPFFreq);
// Process the source through the filter
const int32 SampleIndex = NumInputChans * Frame + Channel;
Buffer[SampleIndex] = CurrentVolumeValue * SourceInfo.LowPassFilters[Channel].ProcessAudio(Buffer[SampleIndex]);
}
}
}
const int32 NumSamples = Buffer.Num();
// Now process the effect chain if it exists
if (SourceInfo.SourceEffects.Num() > 0 && (!SourceInfo.bIsDone || !SourceInfo.bEffectTailsDone))
{
SourceInfo.SourceEffectInputData.CurrentVolume = CurrentVolumeValue;
SourceInfo.SourceEffectOutputData.AudioFrame.Reset();
SourceInfo.SourceEffectOutputData.AudioFrame.AddZeroed(NumInputChans);
SourceInfo.SourceEffectInputData.AudioFrame.Reset();
SourceInfo.SourceEffectInputData.AudioFrame.AddZeroed(NumInputChans);
// Process the effect chain for this buffer per frame
for (int32 Sample = 0; Sample < NumSamples; Sample += NumInputChans)
{
// Get the buffer input sample
for (int32 Chan = 0; Chan < NumInputChans; ++Chan)
{
SourceInfo.SourceEffectInputData.AudioFrame[Chan] = Buffer[Sample + Chan];
}
for (int32 SourceEffectIndex = 0; SourceEffectIndex < SourceInfo.SourceEffects.Num(); ++SourceEffectIndex)
{
if (SourceInfo.SourceEffects[SourceEffectIndex]->IsActive())
{
SourceInfo.SourceEffects[SourceEffectIndex]->Update();
SourceInfo.SourceEffects[SourceEffectIndex]->ProcessAudio(SourceInfo.SourceEffectInputData, SourceInfo.SourceEffectOutputData);
// Copy the output of the effect into the input so the next effect will get the outputs audio
for (int32 Chan = 0; Chan < NumInputChans; ++Chan)
{
SourceInfo.SourceEffectInputData.AudioFrame[Chan] = SourceInfo.SourceEffectOutputData.AudioFrame[Chan];
}
}
}
// Copy audio frame back to the buffer
for (int32 Chan = 0; Chan < NumInputChans; ++Chan)
{
Buffer[Sample + Chan] = SourceInfo.SourceEffectInputData.AudioFrame[Chan];
}
}
}
bool bReverbPluginUsed = false;
if (SourceInfo.bUseReverbPlugin)
{
const FSpatializationParams* SourceSpatParams = &SourceInfo.SpatParams;
// Move the audio buffer to the reverb plugin buffer
AudioPluginInputData.SourceId = SourceId;
AudioPluginInputData.AudioBuffer = &Buffer;
AudioPluginInputData.SpatializationParams = SourceSpatParams;
AudioPluginInputData.NumChannels = NumInputChans;
SourceInfo.AudioPluginOutputData.AudioBuffer.Reset();
SourceInfo.AudioPluginOutputData.AudioBuffer.AddZeroed(AudioPluginInputData.AudioBuffer->Num());
MixerDevice->ReverbPluginInterface->ProcessSourceAudio(AudioPluginInputData, SourceInfo.AudioPluginOutputData);
// Make sure the buffer counts didn't change and are still the same size
AUDIO_MIXER_CHECK(SourceInfo.AudioPluginOutputData.AudioBuffer.Num() == Buffer.Num());
// Copy the reverb-processed data back to the source buffer
SourceInfo.ReverbPluginOutputBuffer.Reset();
SourceInfo.ReverbPluginOutputBuffer.Append(SourceInfo.AudioPluginOutputData.AudioBuffer);
bReverbPluginUsed = true;
}
if (SourceInfo.bUseOcclusionPlugin)
{
const FSpatializationParams* SourceSpatParams = &SourceInfo.SpatParams;
// Move the audio buffer to the occlusion plugin buffer
AudioPluginInputData.SourceId = SourceId;
AudioPluginInputData.AudioBuffer = &Buffer;
AudioPluginInputData.SpatializationParams = SourceSpatParams;
AudioPluginInputData.NumChannels = NumInputChans;
SourceInfo.AudioPluginOutputData.AudioBuffer.Reset();
SourceInfo.AudioPluginOutputData.AudioBuffer.AddZeroed(AudioPluginInputData.AudioBuffer->Num());
MixerDevice->OcclusionInterface->ProcessAudio(AudioPluginInputData, SourceInfo.AudioPluginOutputData);
// Make sure the buffer counts didn't change and are still the same size
AUDIO_MIXER_CHECK(SourceInfo.AudioPluginOutputData.AudioBuffer.Num() == Buffer.Num());
// Copy the occlusion-processed data back to the source buffer and mix with the reverb plugin output buffer
if (bReverbPluginUsed)
{
for (int32 i = 0; i < Buffer.Num(); ++i)
{
Buffer[i] = SourceInfo.ReverbPluginOutputBuffer[i] + SourceInfo.AudioPluginOutputData.AudioBuffer[i];
}
}
else
{
FMemory::Memcpy(Buffer.GetData(), SourceInfo.AudioPluginOutputData.AudioBuffer.GetData(), sizeof(float) * Buffer.Num());
}
}
else if (bReverbPluginUsed)
{
for (int32 i = 0; i < Buffer.Num(); ++i)
{
Buffer[i] += SourceInfo.ReverbPluginOutputBuffer[i];
}
}
// Compute the source envelope
float AverageSampleValue;
for (int32 Sample = 0; Sample < NumSamples;)
{
AverageSampleValue = 0.0f;
for (int32 Chan = 0; Chan < NumInputChans; ++Chan)
{
AverageSampleValue += Buffer[Sample++];
}
AverageSampleValue /= NumInputChans;
SourceInfo.SourceEnvelopeFollower.ProcessAudio(AverageSampleValue);
}
// Copy the current value of the envelope follower (block-rate value)
SourceInfo.SourceEnvelopeValue = SourceInfo.SourceEnvelopeFollower.GetCurrentValue();
SourceInfo.bEffectTailsDone = SourceInfo.bEffectTailsDone || SourceInfo.SourceEnvelopeValue < ENVELOPE_TAIL_THRESHOLD;
// Check the source effect tails condition
if (SourceInfo.bIsDone && SourceInfo.bEffectTailsDone)
{
// If we're done and our tails our done, clear everything out
SourceInfo.BufferQueue.Empty();
SourceInfo.CurrentFrameValues.Reset();
SourceInfo.NextFrameValues.Reset();
SourceInfo.CurrentPCMBuffer = nullptr;
}
// If the source has HRTF processing enabled, run it through the spatializer
if (SourceInfo.bUseHRTFSpatializer)
{
SCOPE_CYCLE_COUNTER(STAT_AudioMixerHRTF);
TSharedPtr<IAudioSpatialization> SpatializationPlugin = MixerDevice->SpatializationPluginInterface;
AUDIO_MIXER_CHECK(SpatializationPlugin.IsValid());
AUDIO_MIXER_CHECK(NumInputChans == 1);
AudioPluginInputData.AudioBuffer = &Buffer;
AudioPluginInputData.NumChannels = NumInputChans;
AudioPluginInputData.SourceId = SourceId;
AudioPluginInputData.SpatializationParams = &SourceInfo.SpatParams;
SourceInfo.AudioPluginOutputData.AudioBuffer.Reset();
SourceInfo.AudioPluginOutputData.AudioBuffer.AddZeroed(2 * NumFrames);
SpatializationPlugin->ProcessAudio(AudioPluginInputData, SourceInfo.AudioPluginOutputData);
// We are now a 2-channel file and should not be spatialized using normal 3d spatialization
SourceInfo.NumPostEffectChannels = 2;
SourceInfo.PostEffectBuffers = &SourceInfo.AudioPluginOutputData.AudioBuffer;
}
else
{
// Otherwise our pre- and post-effect channels are the same as the input channels
SourceInfo.NumPostEffectChannels = SourceInfo.NumInputChannels;
// Set the ptr to use for post-effect buffers
SourceInfo.PostEffectBuffers = &Buffer;
}
}
}
void FMixerSourceManager::ComputeOutputBuffersForIdRange(const int32 SourceIdStart, const int32 SourceIdEnd)
{
SCOPE_CYCLE_COUNTER(STAT_AudioMixerSourceOutputBuffers);
const int32 NumFrames = MixerDevice->GetNumOutputFrames();
const int32 NumOutputChannels = MixerDevice->GetNumDeviceChannels();
// Reset the dry/wet buffers for all the sources
const int32 NumOutputSamples = NumFrames * NumOutputChannels;
for (int32 SourceId = SourceIdStart; SourceId < SourceIdEnd; ++SourceId)
{
FSourceInfo& SourceInfo = SourceInfos[SourceId];
SourceInfo.OutputBuffer.Reset();
SourceInfo.OutputBuffer.AddZeroed(NumOutputSamples);
}
for (int32 SourceId = SourceIdStart; SourceId < SourceIdEnd; ++SourceId)
{
FSourceInfo& SourceInfo = SourceInfos[SourceId];
// Don't need to compute anything if the source is not playing or paused (it will remain at 0.0 volume)
// Note that effect chains will still be able to continue to compute audio output. The source output
// will simply stop being read from.
if (!SourceInfo.bIsBusy || !SourceInfo.bIsPlaying || SourceInfo.bIsPaused)
{
continue;
}
for (int32 Frame = 0; Frame < NumFrames; ++Frame)
{
const int32 PostEffectChannels = SourceInfo.NumPostEffectChannels;
AUDIO_MIXER_CHECK(SourceInfo.ChannelMapParam.ChannelValues.Num() == PostEffectChannels * NumOutputChannels);
float SourceSampleValue = 0.0f;
// For each source channel, compute the output channel mapping
for (int32 SourceChannel = 0; SourceChannel < PostEffectChannels; ++SourceChannel)
{
const int32 SourceSampleIndex = Frame * PostEffectChannels + SourceChannel;
TArray<float>* Buffer = SourceInfo.PostEffectBuffers;
SourceSampleValue = (*Buffer)[SourceSampleIndex];
// Make sure that our channel map is appropriate for the source channel and output channel count!
SourceInfo.ChannelMapParam.UpdateChannelMap();
for (int32 OutputChannel = 0; OutputChannel < NumOutputChannels; ++OutputChannel)
{
// Look up the channel map value (maps input channels to output channels) for the source
// This is the step that either applies the spatialization algorithm or just maps a 2d sound
const int32 ChannelMapIndex = NumOutputChannels * SourceChannel + OutputChannel;
const float ChannelMapValue = SourceInfo.ChannelMapParam.GetChannelValue(ChannelMapIndex);
// If we have a non-zero sample value, write it out. Note that most 3d audio channel maps
// for surround sound will result in 0.0 sample values so this branch should save a bunch of multiplies + adds
if (ChannelMapValue > 0.0f)
{
AUDIO_MIXER_CHECK(ChannelMapValue >= 0.0f && ChannelMapValue <= 1.0f);
// Scale the input source sample for this source channel value
const float SampleValue = SourceSampleValue * ChannelMapValue;
const int32 OutputSampleIndex = Frame * NumOutputChannels + OutputChannel;
SourceInfo.OutputBuffer[OutputSampleIndex] += SampleValue;
}
}
}
}
}
}
void FMixerSourceManager::MixOutputBuffers(const int32 SourceId, TArray<float>& OutWetBuffer, const float SendLevel) const
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
AUDIO_MIXER_CHECK(SourceId < NumTotalSources);
if (SendLevel > 0.0f)
{
const FSourceInfo& SourceInfo = SourceInfos[SourceId];
const TArray<float>& SourceOutputBuffer = SourceInfo.OutputBuffer;
for (int32 SampleIndex = 0; SampleIndex < OutWetBuffer.Num(); ++SampleIndex)
{
OutWetBuffer[SampleIndex] += SourceOutputBuffer[SampleIndex] * SendLevel;
}
}
}
void FMixerSourceManager::UpdateDeviceChannelCount(const int32 InNumOutputChannels)
{
// Update all source's to appropriate channel maps
for (int32 SourceId = 0; SourceId < NumTotalSources; ++SourceId)
{
FSourceInfo& SourceInfo = SourceInfos[SourceId];
// Don't need to do anything if it's not active
if (!SourceInfo.bIsActive)
{
continue;
}
SourceInfo.ScratchChannelMap.Reset();
const int32 NumSoureChannels = SourceInfo.bUseHRTFSpatializer ? 2 : SourceInfo.NumInputChannels;
// If this is a 3d source, then just zero out the channel map, it'll cause a temporary blip
// but it should reset in the next tick
if (SourceInfo.bIs3D)
{
GameThreadInfo.bNeedsSpeakerMap[SourceId] = true;
SourceInfo.ScratchChannelMap.AddZeroed(NumSoureChannels * InNumOutputChannels);
}
// If it's a 2D sound, then just get a new channel map appropriate for the new device channel count
else
{
SourceInfo.ScratchChannelMap.Reset();
MixerDevice->Get2DChannelMap(NumSoureChannels, InNumOutputChannels, SourceInfo.bIsCenterChannelOnly, SourceInfo.ScratchChannelMap);
}
SourceInfo.ChannelMapParam.SetChannelMap(SourceInfo.ScratchChannelMap);
}
}
void FMixerSourceManager::UpdateSourceEffectChain(const uint32 InSourceEffectChainId, const TArray<FSourceEffectChainEntry>& InSourceEffectChain, const bool bPlayEffectChainTails)
{
AudioMixerThreadCommand([this, InSourceEffectChainId, InSourceEffectChain, bPlayEffectChainTails]()
{
FSoundEffectSourceInitData InitData;
InitData.AudioClock = MixerDevice->GetAudioClock();
InitData.SampleRate = AUDIO_SAMPLE_RATE;
for (int32 SourceId = 0; SourceId < NumTotalSources; ++SourceId)
{
FSourceInfo& SourceInfo = SourceInfos[SourceId];
if (SourceInfo.SourceEffectChainId == InSourceEffectChainId)
{
SourceInfo.bEffectTailsDone = !bPlayEffectChainTails;
// Check to see if the chain didn't actually change
TArray<FSoundEffectSource *>& ThisSourceEffectChain = SourceInfo.SourceEffects;
bool bReset = false;
if (InSourceEffectChain.Num() == ThisSourceEffectChain.Num())
{
for (int32 SourceEffectId = 0; SourceEffectId < ThisSourceEffectChain.Num(); ++SourceEffectId)
{
const FSourceEffectChainEntry& ChainEntry = InSourceEffectChain[SourceEffectId];
FSoundEffectSource* SourceEffectInstance = ThisSourceEffectChain[SourceEffectId];
if (!SourceEffectInstance->IsParentPreset(ChainEntry.Preset))
{
// As soon as one of the effects change or is not the same, then we need to rebuild the effect graph
bReset = true;
break;
}
// Otherwise just update if it's just to bypass
SourceEffectInstance->SetEnabled(!ChainEntry.bBypass);
}
}
else
{
bReset = true;
}
if (bReset)
{
InitData.NumSourceChannels = SourceInfo.NumInputChannels;
if (SourceInfo.NumInputFrames != INDEX_NONE)
{
InitData.SourceDuration = (float)SourceInfo.NumInputFrames / AUDIO_SAMPLE_RATE;
}
else
{
// Procedural sound waves have no known duration
InitData.SourceDuration = (float)INDEX_NONE;
}
// First reset the source effect chain
ResetSourceEffectChain(SourceId);
// Rebuild it
BuildSourceEffectChain(SourceId, InitData, InSourceEffectChain);
}
}
}
});
}
void FMixerSourceManager::ComputeNextBlockOfSamples()
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
SCOPE_CYCLE_COUNTER(STAT_AudioMixerSourceManagerUpdate);
if (bPumpQueue)
{
bPumpQueue = false;
PumpCommandQueue();
}
if (NumSourceWorkers > 0 && !DisableParallelSourceProcessingCvar)
{
AUDIO_MIXER_CHECK(SourceWorkers.Num() == NumSourceWorkers);
for (int32 i = 0; i < SourceWorkers.Num(); ++i)
{
SourceWorkers[i]->StartBackgroundTask();
}
for (int32 i = 0; i < SourceWorkers.Num(); ++i)
{
SourceWorkers[i]->EnsureCompletion();
}
}
else
{
// Get the next block of frames from the source buffers
ComputeSourceBuffersForIdRange(0, NumTotalSources);
// Compute the audio source buffers after their individual effect chain processing
ComputePostSourceEffectBufferForIdRange(0, NumTotalSources);
// Get the audio for the output buffers
ComputeOutputBuffersForIdRange(0, NumTotalSources);
}
// Update the game thread copy of source doneness
for (int32 SourceId = 0; SourceId < NumTotalSources; ++SourceId)
{
FSourceInfo& SourceInfo = SourceInfos[SourceId];
GameThreadInfo.bIsDone[SourceId] = SourceInfo.bIsDone;
GameThreadInfo.bEffectTailsDone[SourceId] = SourceInfo.bEffectTailsDone;
}
}
void FMixerSourceManager::AudioMixerThreadCommand(TFunction<void()> InFunction)
{
// Add the function to the command queue
SourceCommandQueue.Enqueue(MoveTemp(InFunction));
}
void FMixerSourceManager::PumpCommandQueue()
{
AUDIO_MIXER_CHECK_AUDIO_PLAT_THREAD(MixerDevice);
// Pop and execute all the commands that came since last update tick
TFunction<void()> CommandFunction;
while (SourceCommandQueue.Dequeue(CommandFunction))
{
CommandFunction();
}
}
}