├── 1600348737376.gif ├── MyProject3.uproject ├── README.md └── SourceCode ├── MyProject3.Build.cs ├── MyProject3.cpp ├── MyProject3.h ├── MyProject3GameModeBase.cpp ├── MyProject3GameModeBase.h ├── SpectralVisualiser.cpp └── SpectralVisualiser.h /1600348737376.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdityaPrakash-26/SoundWaveVisualizer/a62ec71326bd009126498d93a82425411b1fd79b/1600348737376.gif -------------------------------------------------------------------------------- /MyProject3.uproject: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "EngineAssociation": "4.25", 4 | "Category": "", 5 | "Description": "", 6 | "Modules": [ 7 | { 8 | "Name": "MyProject3", 9 | "Type": "Runtime", 10 | "LoadingPhase": "Default", 11 | "AdditionalDependencies": [ 12 | "Engine" 13 | ] 14 | } 15 | ], 16 | "Plugins": [ 17 | { 18 | "Name": "TimeSynth", 19 | "Enabled": true 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sound Wave Visualizer 2 | An Unreal Engine 4 utility tool, allowing you to visualize sound waves in 3D. Easy to integrate and minimum dependencies. 3 | 4 | ![Gif](1600348737376.gif) 5 | 6 | ## Features 7 | - Use any of the default 3D props or even upload your own. 8 | - Customiseable sound range, to achieve the visualization you want. 9 | - Edit the sound track. 10 | - Change number of bars/meshes. 11 | 12 | ## How it works? 13 | The most important part of the code is: 14 | ```cpp 15 | for(auto SpecData : TimeSynthComponent->GetSpectralData()){ 16 | UStaticMeshComponent* SpectrumBar = SpectrumBars[SpecData.FrequencyHz / 50.f - 1]; 17 | 18 | FVector BarScale = SpectrumBar->GetComponentScale(); 19 | BarScale.Z = 1.f + SpecData.Magnitude/5.f; 20 | SpectrumBar->SetWorldScale3D(FMath::VInterpTo(SpectrumBar->GetComponentScale(), BarScale, DeltaTime, 5.f)); 21 | } 22 | ``` 23 | The `TimeSynthComponent` returns the spectral data(which has several properties like frequencies, magnitude etc). Firstly, we pull the Frequency(in Hz) from the data, and divide it by `50` to get the bar we wish to modify. That is, every bar in the array/mesh spans over a range of `50 Hz`. (Note: the `-1` is there for the index). 24 | 25 | Next, we change the Z-length, or the height of the bar calculated above. This is divided by `5` (or we can choose any other number), to get the new scale. Finally, we intepolate from current height to the calculated height. 26 | 27 | ## Setup 28 | - Install Epic games from their [website](https://www.epicgames.com/store/en-US/) 29 | - Navigate to Unreal Engine in the sidebar 30 | - Download Unreal Engine 4.25.3 31 | - Open the project 32 | -------------------------------------------------------------------------------- /SourceCode/MyProject3.Build.cs: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | using UnrealBuildTool; 4 | 5 | public class MyProject3 : ModuleRules 6 | { 7 | public MyProject3(ReadOnlyTargetRules Target) : base(Target) 8 | { 9 | PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; 10 | 11 | PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" , "TimeSynth"}); 12 | 13 | PrivateDependencyModuleNames.AddRange(new string[] { }); 14 | 15 | // Uncomment if you are using Slate UI 16 | // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); 17 | 18 | // Uncomment if you are using online features 19 | // PrivateDependencyModuleNames.Add("OnlineSubsystem"); 20 | 21 | // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SourceCode/MyProject3.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #include "MyProject3.h" 4 | #include "Modules/ModuleManager.h" 5 | 6 | IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, MyProject3, "MyProject3" ); 7 | -------------------------------------------------------------------------------- /SourceCode/MyProject3.h: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | 7 | -------------------------------------------------------------------------------- /SourceCode/MyProject3GameModeBase.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | 4 | #include "MyProject3GameModeBase.h" 5 | 6 | -------------------------------------------------------------------------------- /SourceCode/MyProject3GameModeBase.h: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "GameFramework/GameModeBase.h" 7 | #include "MyProject3GameModeBase.generated.h" 8 | 9 | /** 10 | * 11 | */ 12 | UCLASS() 13 | class MYPROJECT3_API AMyProject3GameModeBase : public AGameModeBase 14 | { 15 | GENERATED_BODY() 16 | 17 | }; 18 | -------------------------------------------------------------------------------- /SourceCode/SpectralVisualiser.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | 4 | #include "SpectralVisualiser.h" 5 | #include "TimeSynthComponent.h" 6 | #include "Components/StaticMeshComponent.h" 7 | // Sets default values 8 | ASpectralVisualiser::ASpectralVisualiser() 9 | { 10 | // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. 11 | PrimaryActorTick.bCanEverTick = true; 12 | 13 | SpectrumBarSpacing = 100.f; 14 | 15 | TimeSynthComponent = CreateDefaultSubobject("TimeSynthComponent"); 16 | TimeSynthComponent->bEnableSpectralAnalysis = true; 17 | 18 | SetRootComponent(TimeSynthComponent); 19 | 20 | for(int32 i = 1; i<=20; i++){ 21 | TimeSynthComponent->FrequenciesToAnalyze.Add(i*50); 22 | 23 | FString SpectrumBarName = FString::Printf(TEXT("SpectrumBar%dHz"), i*50); 24 | 25 | UStaticMeshComponent* SpectrumBar = CreateDefaultSubobject(*SpectrumBarName); 26 | 27 | SpectrumBar->SetupAttachment(TimeSynthComponent); 28 | SpectrumBar->SetStaticMesh(SpectrumBarMesh); 29 | SpectrumBar->SetRelativeLocation(FVector(i* SpectrumBarSpacing, 0.f, 0.f)); 30 | SpectrumBars.Add(SpectrumBar); 31 | } 32 | 33 | } 34 | 35 | // Called when the game starts or when spawned 36 | void ASpectralVisualiser::BeginPlay() 37 | { 38 | Super::BeginPlay(); 39 | 40 | Refresh(); 41 | 42 | TimeSynthComponent->PlayClip(TimeSynthClip); 43 | 44 | } 45 | 46 | // Called every frame 47 | void ASpectralVisualiser::Tick(float DeltaTime) 48 | { 49 | Super::Tick(DeltaTime); 50 | 51 | for(auto SpecData : TimeSynthComponent->GetSpectralData()){ 52 | UStaticMeshComponent* SpectrumBar = SpectrumBars[SpecData.FrequencyHz / 50.f - 1]; 53 | 54 | FVector BarScale = SpectrumBar->GetComponentScale(); 55 | BarScale.Z = 1.f + SpecData.Magnitude/5.f; 56 | SpectrumBar->SetWorldScale3D(FMath::VInterpTo(SpectrumBar->GetComponentScale(), BarScale, DeltaTime, 5.f)); 57 | } 58 | } 59 | 60 | void ASpectralVisualiser::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) 61 | { 62 | Super::PostEditChangeProperty(PropertyChangedEvent); 63 | 64 | Refresh(); 65 | 66 | } 67 | 68 | void ASpectralVisualiser::Refresh() 69 | { 70 | for(int i = 0; i<=20; i++){ 71 | if(SpectrumBars.IsValidIndex(i)){ 72 | UStaticMeshComponent* SpectrumBar = SpectrumBars[i]; 73 | SpectrumBar->SetStaticMesh(SpectrumBarMesh); 74 | SpectrumBar->SetRelativeLocation(FVector((i+1) * SpectrumBarSpacing, 0.f, 0.f)); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /SourceCode/SpectralVisualiser.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "GameFramework/Actor.h" 7 | #include "SpectralVisualiser.generated.h" 8 | 9 | UCLASS() 10 | class MYPROJECT3_API ASpectralVisualiser : public AActor 11 | { 12 | GENERATED_BODY() 13 | 14 | public: 15 | // Sets default values for this actor's properties 16 | ASpectralVisualiser(); 17 | 18 | protected: 19 | // Called when the game starts or when spawned 20 | virtual void BeginPlay() override; 21 | virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; 22 | 23 | void Refresh(); 24 | 25 | UPROPERTY(EditAnywhere, Category = "Audio") 26 | class UTimeSynthComponent* TimeSynthComponent; 27 | 28 | UPROPERTY(EditAnywhere, Category = "Audio") 29 | class UTimeSynthClip* TimeSynthClip; 30 | 31 | UPROPERTY(EditAnywhere, Category = "Audio") 32 | TArray SpectrumBars; 33 | 34 | UPROPERTY(EditAnywhere, Category = "Audio") 35 | float SpectrumBarSpacing; //this is the distance between two bars 36 | 37 | UPROPERTY(EditAnywhere, Category = "Audio") 38 | UStaticMesh* SpectrumBarMesh; 39 | 40 | public: 41 | // Called every frame 42 | virtual void Tick(float DeltaTime) override; 43 | 44 | }; 45 | --------------------------------------------------------------------------------