Browse Source

Add extra error handling to loading songs

master
Thomas Cheyney 4 years ago
parent
commit
1553b979d8
3 changed files with 18 additions and 14 deletions
  1. BIN
      Content/Blueprints/BP_controller.uasset
  2. +13
    -11
      Plugins/eXiSoundVis/Source/eXiSoundVis/Private/SoundVisComponent.cpp
  3. +5
    -3
      Plugins/eXiSoundVis/Source/eXiSoundVis/Public/SoundVisComponent.h

BIN
Content/Blueprints/BP_controller.uasset View File


+ 13
- 11
Plugins/eXiSoundVis/Source/eXiSoundVis/Private/SoundVisComponent.cpp View File

@ -41,7 +41,7 @@ void USoundVisComponent::TickComponent(float DeltaTime, ELevelTick TickType, FAc
/// Functions to load Data from the HardDrive /// Functions to load Data from the HardDrive
void USoundVisComponent::LoadSoundFileFromHD(const FString& InFilePath)
bool USoundVisComponent::LoadSoundFileFromHD(const FString& InFilePath)
{ {
// Create new SoundWave Object // Create new SoundWave Object
CompressedSoundWaveRef = NewObject<USoundWave>(USoundWave::StaticClass()); CompressedSoundWaveRef = NewObject<USoundWave>(USoundWave::StaticClass());
@ -50,7 +50,7 @@ void USoundVisComponent::LoadSoundFileFromHD(const FString& InFilePath)
if (!CompressedSoundWaveRef) { if (!CompressedSoundWaveRef) {
PrintError(TEXT("Failed to create new SoundWave Object!")); PrintError(TEXT("Failed to create new SoundWave Object!"));
return;
return false;
} }
// If true, the Sound was successfully loaded // If true, the Sound was successfully loaded
@ -64,6 +64,7 @@ void USoundVisComponent::LoadSoundFileFromHD(const FString& InFilePath)
if (bLoaded) if (bLoaded)
{ {
UE_LOG(LogTemp, Error, TEXT("LoadSoundFileFromHD 0"));
// Fill the SoundData into the SoundWave Object // Fill the SoundData into the SoundWave Object
if (RawFile.Num() > 0) { if (RawFile.Num() > 0) {
@ -92,11 +93,11 @@ void USoundVisComponent::LoadSoundFileFromHD(const FString& InFilePath)
if (!bLoaded) { if (!bLoaded) {
PrintError(TEXT("Something went wrong while loading the Sound Data!")); PrintError(TEXT("Something went wrong while loading the Sound Data!"));
return;
return false;
} }
// Fill the PCMSampleBuffer // Fill the PCMSampleBuffer
GetPCMDataFromFile(CompressedSoundWaveRef);
return GetPCMDataFromFile(CompressedSoundWaveRef);
} }
bool USoundVisComponent::FillSoundWaveInfo(USoundWave* InSoundWave, TArray<uint8>* InRawFile) bool USoundVisComponent::FillSoundWaveInfo(USoundWave* InSoundWave, TArray<uint8>* InRawFile)
@ -124,18 +125,18 @@ bool USoundVisComponent::FillSoundWaveInfo(USoundWave* InSoundWave, TArray<uint8
/// Function to decompress the compressed Data that comes with the .ogg file /// Function to decompress the compressed Data that comes with the .ogg file
void USoundVisComponent::GetPCMDataFromFile(USoundWave* InSoundWave)
bool USoundVisComponent::GetPCMDataFromFile(USoundWave* InSoundWave)
{ {
if (InSoundWave == nullptr) { if (InSoundWave == nullptr) {
PrintError(TEXT("Passed SoundWave pointer is a nullptr!")); PrintError(TEXT("Passed SoundWave pointer is a nullptr!"));
return;
return false;
} }
if (InSoundWave->NumChannels < 1 || InSoundWave->NumChannels > 2) { if (InSoundWave->NumChannels < 1 || InSoundWave->NumChannels > 2) {
PrintError(TEXT("SoundWave Object has not the right amount of Channels. Plugin only supports 1 or 2!")); PrintError(TEXT("SoundWave Object has not the right amount of Channels. Plugin only supports 1 or 2!"));
return;
return false;
} }
if (GEngine) if (GEngine)
@ -151,13 +152,14 @@ void USoundVisComponent::GetPCMDataFromFile(USoundWave* InSoundWave)
// Creates a new DecompressWorker and starts it // Creates a new DecompressWorker and starts it
InitNewDecompressTask(InSoundWave); InitNewDecompressTask(InSoundWave);
return true;
} }
else { else {
PrintError(TEXT("Couldn't get a valid Pointer to the Main AudioDevice!")); PrintError(TEXT("Couldn't get a valid Pointer to the Main AudioDevice!"));
return;
} }
} }
return false;
} }
void USoundVisComponent::CalculateFrequencySpectrum(USoundWave* InSoundWaveRef, const float InStartTime, const float InDuration, TArray<float>& OutFrequencies) void USoundVisComponent::CalculateFrequencySpectrum(USoundWave* InSoundWaveRef, const float InStartTime, const float InDuration, TArray<float>& OutFrequencies)
@ -399,9 +401,9 @@ void USoundVisComponent::HandleFrequencySpectrumCalculation()
/// Blueprint Versions of the File Data Functions /// Blueprint Versions of the File Data Functions
void USoundVisComponent::BP_LoadSoundFileFromHD(const FString InFilePath)
bool USoundVisComponent::BP_LoadSoundFileFromHD(const FString InFilePath)
{ {
LoadSoundFileFromHD(InFilePath);
return LoadSoundFileFromHD(InFilePath);
} }
void USoundVisComponent::BP_LoadAllSoundFileNamesFromHD(bool& bLoaded, const FString InDirectoryPath, const bool bInAbsolutePath, const FString InFileExtension, TArray<FString>& OutSoundFileNamesWithPath, TArray<FString>& OutSoundFileNamesWithoutPath) void USoundVisComponent::BP_LoadAllSoundFileNamesFromHD(bool& bLoaded, const FString InDirectoryPath, const bool bInAbsolutePath, const FString InFileExtension, TArray<FString>& OutSoundFileNamesWithPath, TArray<FString>& OutSoundFileNamesWithoutPath)
@ -653,4 +655,4 @@ void USoundVisComponent::BP_GetAverageFrequencyValueInRange(USoundWave* InSoundW
} }
OutAverageFrequency = ValueSum / NumberOfFrequencies; OutAverageFrequency = ValueSum / NumberOfFrequencies;
}
}

+ 5
- 3
Plugins/eXiSoundVis/Source/eXiSoundVis/Public/SoundVisComponent.h View File

@ -134,14 +134,14 @@ public:
/// Functions to load Data from the HardDrive /// Functions to load Data from the HardDrive
// Function to load a sound file from the HD // Function to load a sound file from the HD
void LoadSoundFileFromHD(const FString& InFilePath);
bool LoadSoundFileFromHD(const FString& InFilePath);
// Function to fill in the RawFile sound data into the USoundWave object // Function to fill in the RawFile sound data into the USoundWave object
bool FillSoundWaveInfo(class USoundWave* InSoundWave, TArray<uint8>* InRawFile); bool FillSoundWaveInfo(class USoundWave* InSoundWave, TArray<uint8>* InRawFile);
/// Function to decompress the compressed Data that comes with the .ogg file /// Function to decompress the compressed Data that comes with the .ogg file
void GetPCMDataFromFile(class USoundWave* InSoundWave);
bool GetPCMDataFromFile(class USoundWave* InSoundWave);
/// Function to calculate the frequency spectrum /// Function to calculate the frequency spectrum
@ -158,6 +158,8 @@ public:
// DEBUG Test function to check if Task can call stuff in here // DEBUG Test function to check if Task can call stuff in here
void Notify_SoundDecompressed(); void Notify_SoundDecompressed();
void Notify_FailedToDecompress();
// Function that is looped to handle the calculation of the FrequencySpectrum // Function that is looped to handle the calculation of the FrequencySpectrum
UFUNCTION() UFUNCTION()
void HandleFrequencySpectrumCalculation(); void HandleFrequencySpectrumCalculation();
@ -171,7 +173,7 @@ public:
* *
*/ */
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Load Sound File"), Category = "SoundVis | SoundFile") UFUNCTION(BlueprintCallable, meta = (DisplayName = "Load Sound File"), Category = "SoundVis | SoundFile")
void BP_LoadSoundFileFromHD(const FString InFilePath);
bool BP_LoadSoundFileFromHD(const FString InFilePath);
/** /**
* Will get an Array of Names of the Found SoundFiles * Will get an Array of Names of the Found SoundFiles


Loading…
Cancel
Save