function to destroy audio and change memory deallocation

This commit is contained in:
Respirant
2020-12-29 14:01:16 +03:00
parent 117f3ed389
commit 6cb272b840
3 changed files with 24 additions and 6 deletions
@@ -79,6 +79,23 @@ 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);
ReadySoundWave->RawData.RemoveBulkData();
ReadySoundWave->InvalidateCompressedData();
ReadySoundWave->FreeResources();
ReadySoundWave->RemoveAudioResource();
ReadySoundWave->ConditionalBeginDestroy();
SuccessfullyDestroyed = true;
}
else {
SuccessfullyDestroyed = false;
}
}
#include "ThirdParty/dr_wav.h"
#include "ThirdParty/dr_mp3.h"
@@ -125,7 +142,9 @@ class USoundWave* URuntimeAudioImporterBPLibrary::GetUSoundWaveFromAudioFile_Int
USoundWave* ReadyUSoundWave = GetSoundWaveObject((const uint8*)pWavFileData, wavFileSize, status); // A ready USoundWave static object
drwav_free(pSampleData, NULL);
drwav_free(pWavFileData, NULL);
return ReadyUSoundWave;
}
@@ -4,7 +4,7 @@
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Runtime/Engine/Classes/Sound/SoundWave.h"
#include "Sound/SoundWave.h"
#include "Developer/TargetPlatform/Public/Interfaces/IAudioFormat.h"
@@ -47,6 +47,9 @@ public:
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);
private:
/* Main internal get USoundWave from audio file */
@@ -19,11 +19,7 @@ public class RuntimeAudioImporter : ModuleRules
}
);
PrivateIncludePaths.AddRange(
new string[] {
// ... add other private include paths required here ...
}
);
//PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "ThirdParty"));
PublicDependencyModuleNames.AddRange(