FSoundCueEditor::~FSoundCueEditor() { // Stop any playing sound cues when the cue editor closes UAudioComponent* PreviewComp = GEditor->GetPreviewAudioComponent(); if (PreviewComp && PreviewComp->IsPlaying()) { Stop(); } GEditor->UnregisterForUndo( this ); }
void FSoundCueEditor::TogglePlayback() { UAudioComponent* PreviewComp = GEditor->GetPreviewAudioComponent(); if ( PreviewComp && PreviewComp->IsPlaying() ) { Stop(); } else { PlayCue(); } }
void AShooterProjectile::DisableAndDestroy() { UAudioComponent* ProjAudioComp = FindComponentByClass<UAudioComponent>(); if (ProjAudioComp && ProjAudioComp->IsPlaying()) { ProjAudioComp->FadeOut(0.1f, 0.f); } MovementComp->StopMovementImmediately(); // give clients some time to show explosion SetLifeSpan( 2.0f ); }
void USoundEffectManager::PlaySoundEffect(ESoundEffects SFX_To_Play) { UAudioComponent* Audio = NewObject<UAudioComponent>(this); Audio->RegisterComponent(); Audio->OnAudioFinished.Add(AudioFinishDelegate); USoundWave* SoundEffect = EnumToSoundEffect(SFX_To_Play); Audio->Sound = SoundEffect; Audio->Play(); SoundEffectComponents.Add(Audio); }
bool FAssetTypeActions_SoundBase::IsSoundPlaying(TArray<TWeakObjectPtr<USoundBase>> Objects) const { UAudioComponent* PreviewComp = GEditor->GetPreviewAudioComponent(); if (PreviewComp) { for (TWeakObjectPtr<USoundBase> SoundItem : Objects) { if (PreviewComp->Sound == SoundItem && PreviewComp->IsPlaying()) { return true; } } } return false; }
void FSoundSource::DrawDebugInfo() { // Draw 3d Debug information about this source, if enabled FAudioDeviceManager* DeviceManager = GEngine->GetAudioDeviceManager(); if (DeviceManager && DeviceManager->IsVisualizeDebug3dEnabled()) { const uint32 AudioComponentID = WaveInstance->ActiveSound->GetAudioComponentID(); if (AudioComponentID > 0) { DECLARE_CYCLE_STAT(TEXT("FAudioThreadTask.DrawSourceDebugInfo"), STAT_AudioDrawSourceDebugInfo, STATGROUP_TaskGraphTasks); USoundBase* Sound = WaveInstance->ActiveSound->GetSound(); const FVector Location = WaveInstance->Location; const bool bSpatialized = Buffer->NumChannels == 2 && WaveInstance->bUseSpatialization; const FVector LeftChannelSourceLoc = LeftChannelSourceLocation; const FVector RightChannelSourceLoc = RightChannelSourceLocation; FAudioThread::RunCommandOnGameThread([AudioComponentID, Sound, bSpatialized, Location, LeftChannelSourceLoc, RightChannelSourceLoc]() { UAudioComponent* AudioComponent = UAudioComponent::GetAudioComponentFromID(AudioComponentID); if (AudioComponent) { UWorld* SoundWorld = AudioComponent->GetWorld(); if (SoundWorld) { FRotator SoundRotation = AudioComponent->GetComponentRotation(); DrawDebugCrosshairs(SoundWorld, Location, SoundRotation, 20.0f, FColor::White, false, -1.0f, SDPG_Foreground); if (bSpatialized) { DrawDebugCrosshairs(SoundWorld, LeftChannelSourceLoc, SoundRotation, 20.0f, FColor::Red, false, -1.0f, SDPG_Foreground); DrawDebugCrosshairs(SoundWorld, RightChannelSourceLoc, SoundRotation, 20.0f, FColor::Green, false, -1.0f, SDPG_Foreground); } const FString Name = Sound->GetName(); DrawDebugString(SoundWorld, AudioComponent->GetComponentLocation() + FVector(0, 0, 32), *Name, nullptr, FColor::White, 0.033, false); } } }, GET_STATID(STAT_AudioDrawSourceDebugInfo)); } } }
void USoundEffectManager::PlaySoundEffect_3D(ESoundEffects SFX_To_Play) { UAudioComponent* Audio = NewObject<UAudioComponent>(this); Audio->RegisterComponent(); Audio->AttachTo(GetOwner()->GetRootComponent(),"",EAttachLocation::SnapToTarget,true); Audio->OnAudioFinished.Add(AudioFinishDelegate); USoundWave* SoundEffect = EnumToSoundEffect(SFX_To_Play); Audio->bAllowSpatialization = true; Audio->bOverrideAttenuation = true; Audio->AttenuationOverrides.OmniRadius = 100.f; Audio->AttenuationOverrides.FalloffDistance = 3000.f; Audio->Sound = SoundEffect; Audio->Play(); SoundEffectComponents.Add(Audio); }
void FAssetTypeActions_SoundBase::AssetsActivated( const TArray<UObject*>& InObjects, EAssetTypeActivationMethod::Type ActivationType ) { if (ActivationType == EAssetTypeActivationMethod::Previewed) { USoundBase* TargetSound = NULL; for (auto ObjIt = InObjects.CreateConstIterator(); ObjIt; ++ObjIt) { TargetSound = Cast<USoundBase>(*ObjIt); if ( TargetSound ) { // Only target the first valid sound cue break; } } UAudioComponent* PreviewComp = GEditor->GetPreviewAudioComponent(); if ( PreviewComp && PreviewComp->IsPlaying() ) { // Already previewing a sound, if it is the target cue then stop it, otherwise play the new one if ( !TargetSound || PreviewComp->Sound == TargetSound ) { StopSound(); } else { PlaySound(TargetSound); } } else { // Not already playing, play the target sound cue if it exists PlaySound(TargetSound); } } else { FAssetTypeActions_Base::AssetsActivated(InObjects, ActivationType); } }
void USoundEffectManager::PlaySoundEffect_3D_AtLocation(ESoundEffects SFX_To_Play, FVector Location) { FActorSpawnParameters spawnParams; spawnParams.Owner = GetOwner(); spawnParams.Instigator = GetOwner()->Instigator; AActor* SpawnedObject; SpawnedObject = GetWorld()->SpawnActor<AActor>(SoundPlayer3D, Location, FRotator(0), spawnParams); UAudioComponent* Audio = SpawnedObject->FindComponentByClass<class UAudioComponent>(); Audio->OnAudioFinished.Add(AudioFinishDelegate); USoundWave* SoundEffect = EnumToSoundEffect(SFX_To_Play); Audio->bAllowSpatialization = true; Audio->bOverrideAttenuation = true; Audio->AttenuationOverrides.OmniRadius = 100.f; Audio->AttenuationOverrides.FalloffDistance = 3000.f; Audio->Sound = SoundEffect; Audio->Play(); SoundEffectComponents.Add(Audio); }
UAudioComponent* CreateVoiceAudioComponent(uint32 SampleRate) { UAudioComponent* AudioComponent = nullptr; if (GEngine != nullptr) { if (FAudioDevice* AudioDevice = GEngine->GetMainAudioDevice()) { USoundWaveProcedural* SoundStreaming = NewObject<USoundWaveProcedural>(); SoundStreaming->SampleRate = SampleRate; SoundStreaming->NumChannels = 1; SoundStreaming->Duration = INDEFINITELY_LOOPING_DURATION; SoundStreaming->SoundGroup = SOUNDGROUP_Voice; SoundStreaming->bLooping = false; AudioComponent = AudioDevice->CreateComponent(SoundStreaming, nullptr, nullptr, false); if (AudioComponent) { AudioComponent->bIsUISound = true; AudioComponent->bAllowSpatialization = false; AudioComponent->SetVolumeMultiplier(1.5f); const FStringAssetReference VoiPSoundClassName = GetDefault<UAudioSettings>()->VoiPSoundClass; if (VoiPSoundClassName.IsValid()) { AudioComponent->SoundClassOverride = LoadObject<USoundClass>(nullptr, *VoiPSoundClassName.ToString()); } } else { UE_LOG(LogVoiceDecode, Warning, TEXT("Unable to create voice audio component!")); } } } return AudioComponent; }
void ASafeInteract::Tick(float DeltaTime) { APlayerController* c = GetWorld()->GetFirstPlayerController(); if (!c) return; ACharacterHUD* h = Cast<ACharacterHUD>(c->GetHUD()); if (!h) return; if (EnteringCombination) { if ((this->GetActorLocation() - CharacterReference->GetActorLocation()).Size() > 400.0f) { EnteringCombination = false; Fade = -1.0; } h->DrawSafeString = true; FString string = TestCombination; if (CombinationLength < COMBINATION_LENGTH) { string += "_"; for (int i = 0; i < (COMBINATION_LENGTH - CombinationLength) - 1; i++) { string += " "; } } h->SafeString = string; if (CheckInput()) { UAudioComponent* SpeakerAudio = SafeSpeaker->GetAudioComponent(); UAudioComponent* SpeakerAudio2 = SafeUnlockSpeaker->GetAudioComponent(); if (EnterCombination()) { EnteringCombination = false; h->DrawSafeString = false; h->SafeString = ""; SpeakerAudio2->Play(); IsLocked = false; UnlockSafe(); Fade = -1.0; } else { if (!SpeakerAudio->IsPlaying()) SpeakerAudio->Play(); } } } else { h->DrawSafeString = false; h->SafeString = ""; } if (Fade != 0) { h->BlackBackgroundAlpha = FMath::Clamp(h->BlackBackgroundAlpha + (200 * DeltaTime * Fade), 0.0f, 150.0f); if (h->BlackBackgroundAlpha == 0.0f || h->BlackBackgroundAlpha == 150) Fade = 0; } }
void FSoundCueGraphConnectionDrawingPolicy::BuildAudioFlowRoadmap() { UAudioComponent* PreviewAudioComponent = GEditor->GetPreviewAudioComponent(); FAudioDevice* AudioDevice = PreviewAudioComponent ? PreviewAudioComponent->GetAudioDevice() : nullptr; if (AudioDevice) { USoundCueGraph* SoundCueGraph = CastChecked<USoundCueGraph>(GraphObj); USoundCue* SoundCue = SoundCueGraph->GetSoundCue(); if (PreviewAudioComponent && PreviewAudioComponent->IsPlaying() && PreviewAudioComponent->Sound == SoundCue) { TArray<FWaveInstance*> WaveInstances; const int32 FirstActiveIndex = AudioDevice->GetSortedActiveWaveInstances(WaveInstances, ESortedActiveWaveGetType::QueryOnly); // Run through the active instances and cull out anything that isn't related to this graph if (FirstActiveIndex > 0) { WaveInstances.RemoveAt(0, FirstActiveIndex + 1); } for (int32 WaveIndex = WaveInstances.Num() - 1; WaveIndex >= 0 ; --WaveIndex) { UAudioComponent* WaveInstanceAudioComponent = WaveInstances[WaveIndex]->ActiveSound->AudioComponent.Get(); if (WaveInstanceAudioComponent != PreviewAudioComponent) { WaveInstances.RemoveAtSwap(WaveIndex); } } for (int32 WaveIndex = 0; WaveIndex < WaveInstances.Num(); ++WaveIndex) { TArray<USoundNode*> PathToWaveInstance; if (SoundCue->FindPathToNode(WaveInstances[WaveIndex]->WaveInstanceHash, PathToWaveInstance)) { TArray<USoundCueGraphNode_Root*> RootNode; TArray<UEdGraphNode*> GraphNodes; SoundCueGraph->GetNodesOfClass<USoundCueGraphNode_Root>(RootNode); check(RootNode.Num() == 1); GraphNodes.Add(RootNode[0]); TArray<double> NodeTimes; NodeTimes.Add(FApp::GetCurrentTime()); // Time for the root node for (int32 i = 0; i < PathToWaveInstance.Num(); ++i) { const double ObservationTime = FApp::GetCurrentTime() + 1.f; NodeTimes.Add(ObservationTime); GraphNodes.Add(PathToWaveInstance[i]->GraphNode); } // Record the unique node->node pairings, keeping only the most recent times for each pairing for (int32 i = GraphNodes.Num() - 1; i >= 1; --i) { UEdGraphNode* CurNode = GraphNodes[i]; double CurNodeTime = NodeTimes[i]; UEdGraphNode* NextNode = GraphNodes[i-1]; double NextNodeTime = NodeTimes[i-1]; FExecPairingMap& Predecessors = PredecessorNodes.FindOrAdd(NextNode); // Update the timings if this is a more recent pairing FTimePair& Timings = Predecessors.FindOrAdd(CurNode); if (Timings.ThisExecTime < NextNodeTime) { Timings.PredExecTime = CurNodeTime; Timings.ThisExecTime = NextNodeTime; } } } } } } }