diff --git a/RuntimeAudioImporter/Source/RuntimeAudioImporter/Private/RuntimeAudioImporterBPLibrary.cpp b/RuntimeAudioImporter/Source/RuntimeAudioImporter/Private/RuntimeAudioImporterBPLibrary.cpp index 2553cab..42a7b9c 100644 --- a/RuntimeAudioImporter/Source/RuntimeAudioImporter/Private/RuntimeAudioImporterBPLibrary.cpp +++ b/RuntimeAudioImporter/Source/RuntimeAudioImporter/Private/RuntimeAudioImporterBPLibrary.cpp @@ -9,7 +9,15 @@ URuntimeAudioImporterBPLibrary::URuntimeAudioImporterBPLibrary(const FObjectInit } -/* Transcode audio file to USoundWave static object */ +/** +* Transcode audio file to USoundWave static object +* +* @param filePath Path to the audio file to import +* @param Format Audio file format (extension) +* @param status Final import status (TranscodingStatus) +* @param DefineFormatAutomatically Whether to define format (extension) automatically or not +* @return Returns USoundWave Static Object. +*/ class USoundWave* URuntimeAudioImporterBPLibrary::GetSoundWaveFromAudioFile(const FString& filePath, TEnumAsByte < AudioFormat > Format, TEnumAsByte < TranscodingStatus >& status, bool DefineFormatAutomatically) { return GetUSoundWaveFromAudioFile_Internal(filePath, Format, status, DefineFormatAutomatically); @@ -79,20 +87,31 @@ class USoundWave* URuntimeAudioImporterBPLibrary::GetSoundWaveObject(const uint8 return sw; } -/* Destroy USoundWave static object */ -void URuntimeAudioImporterBPLibrary::DestroySoundWave(USoundWave* ReadySoundWave, bool& SuccessfullyDestroyed) { - if (IsValid(ReadySoundWave) && ReadySoundWave->IsReadyForFinishDestroy()) { - FMemory::Free(ReadySoundWave->RawPCMData); +/** +* Destroy USoundWave static object +* +* @return Returns true - success, false - failure. +*/ +bool URuntimeAudioImporterBPLibrary::DestroySoundWave(USoundWave* ReadySoundWave) { - ReadySoundWave->RawData.RemoveBulkData(); + if (IsValid(ReadySoundWave) && ReadySoundWave->IsValidLowLevel()) { + + /* Free memory */ ReadySoundWave->InvalidateCompressedData(); - ReadySoundWave->FreeResources(); + FMemory::Free(ReadySoundWave->RawPCMData); + ReadySoundWave->RawData.RemoveBulkData(); ReadySoundWave->RemoveAudioResource(); + /* Free memory */ + + /* Destroying USoundWave object as UObject */ ReadySoundWave->ConditionalBeginDestroy(); - SuccessfullyDestroyed = true; + ReadySoundWave = NULL; + /* Destroying USoundWave object as UObject */ + + return true; } else { - SuccessfullyDestroyed = false; + return false; } } diff --git a/RuntimeAudioImporter/Source/RuntimeAudioImporter/Public/RuntimeAudioImporterBPLibrary.h b/RuntimeAudioImporter/Source/RuntimeAudioImporter/Public/RuntimeAudioImporterBPLibrary.h index d4e0554..af172c5 100644 --- a/RuntimeAudioImporter/Source/RuntimeAudioImporter/Public/RuntimeAudioImporterBPLibrary.h +++ b/RuntimeAudioImporter/Source/RuntimeAudioImporter/Public/RuntimeAudioImporterBPLibrary.h @@ -43,12 +43,25 @@ class RUNTIMEAUDIOIMPORTER_API URuntimeAudioImporterBPLibrary : public UBlueprin GENERATED_UCLASS_BODY() public: - /* Transcode audio file to USoundWave static object */ + /** + * Transcode audio file to USoundWave static object + * + * @param filePath Path to the audio file to import + * @param Format Audio file format (extension) + * @param status Final import status (TranscodingStatus) + * @param DefineFormatAutomatically Whether to define format (extension) automatically or not + * @return Returns USoundWave Static Object. + */ UFUNCTION(BlueprintCallable, meta = (Keywords = "Importer, Transcoder, Converter, MP3, FLAC, WAV", ToolTip = "Transcode audio file to USoundWave static object"), Category = "RuntimeAudioImporter") static class USoundWave* GetSoundWaveFromAudioFile(const FString & filePath, TEnumAsByte < AudioFormat > Format, TEnumAsByte < TranscodingStatus > & status, bool DefineFormatAutomatically); - UFUNCTION(BlueprintCallable, meta = (Keywords = "MP3, FLAC, WAV, Destroy", ToolTip = "After the Soundwave is no longer needed, you need to call this function to free memory"), Category = "RuntimeAudioImporter") - static void DestroySoundWave(USoundWave * ReadySoundWave, bool& SuccessfullyDestroyed); + /** + * Destroy USoundWave static object + * + * @return Returns true - success, false - failure. + */ + UFUNCTION(BlueprintCallable, meta = (Keywords = "Importer, Transcoder, Converter, MP3, FLAC, WAV, Destroy", ToolTip = "After the Soundwave is no longer needed, you need to call this function to free memory"), Category = "RuntimeAudioImporter") + static bool DestroySoundWave(USoundWave * ReadySoundWave); private: