From 4cbafaef8119f4c4d83e578fc8ca74c53528f784 Mon Sep 17 00:00:00 2001 From: Georgy Treshchev Date: Sat, 20 Feb 2021 08:41:37 +0100 Subject: [PATCH] Correct filling of LPCM data, working with compressed formats --- .../Private/RuntimeAudioImporterLibrary.cpp | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/RuntimeAudioImporter/Source/RuntimeAudioImporter/Private/RuntimeAudioImporterLibrary.cpp b/RuntimeAudioImporter/Source/RuntimeAudioImporter/Private/RuntimeAudioImporterLibrary.cpp index 224cd14..f9de4a2 100644 --- a/RuntimeAudioImporter/Source/RuntimeAudioImporter/Private/RuntimeAudioImporterLibrary.cpp +++ b/RuntimeAudioImporter/Source/RuntimeAudioImporter/Private/RuntimeAudioImporterLibrary.cpp @@ -218,14 +218,19 @@ class USoundWave* URuntimeAudioImporterLibrary::GetSoundWaveObject(const uint8* Status = TranscodingStatus::UnsupportedBitDepth; return nullptr; } - sw->InvalidateCompressedData(); sw->RawData.Lock(LOCK_READ_WRITE); - void* LockedData = sw->RawData.Realloc(WaveDataSize); - FMemory::Memcpy(LockedData, WaveData, WaveDataSize); + FMemory::Memcpy(sw->RawData.Realloc(WaveDataSize), WaveData, WaveDataSize); sw->RawData.Unlock(); + OnProgress_Internal(85); + + // RawPCMDataSize = WaveDataSize - 44 bytes (the header of the WAV data) = SampleDataSize + sw->RawPCMDataSize = WaveInfo.SampleDataSize; + sw->RawPCMData = (uint8*)FMemory::Malloc(sw->RawPCMDataSize); + FMemory::Memmove(sw->RawPCMData, WaveData, WaveDataSize); + // Callback Dispatcher OnProgress (not completely accurate implementation) - OnProgress_Internal(80); + OnProgress_Internal(90); int32 DurationDiv = *WaveInfo.pChannels * *WaveInfo.pBitsPerSample * *WaveInfo.pSamplesPerSec; if (DurationDiv) @@ -244,7 +249,7 @@ class USoundWave* URuntimeAudioImporterLibrary::GetSoundWaveObject(const uint8* sw->SoundGroup = ESoundGroup::SOUNDGROUP_Default; // Callback Dispatcher OnProgress (not completely accurate implementation) - OnProgress_Internal(85); + OnProgress_Internal(95); } else { @@ -270,16 +275,6 @@ class USoundWave* URuntimeAudioImporterLibrary::GetSoundWaveObject(const uint8* return nullptr; } - sw->RawPCMData = (uint8*)FMemory::Malloc(sw->RawPCMDataSize); - - // Callback Dispatcher OnProgress (not completely accurate implementation) - OnProgress_Internal(90); - - FMemory::Memcpy(sw->RawPCMData, WaveInfo.SampleDataStart, sw->RawPCMDataSize); - - // Callback Dispatcher OnProgress (not completely accurate implementation) - OnProgress_Internal(95); - if (!sw) { Status = TranscodingStatus::InvalidUSoundWave;