For the sake of documenting what was a really long struggle getting seeking / start from / any deeper audio issues with an vorbis OGG -> soundwave importer, i found that UE4 relies on both the RawData and RawPCMData part of a soundwave to perform tasks deeper than just playing audio, the solution i found was to use the SerializeWaveFile function on pcm data to make a normal .wav type rawdata and then set the rawdata that way. I’m not certain if works in packaged games. Code for setting the RawData:
//SERIALIZE PCM AND FILL IN RAW DATA
TArray < uint8 > rawSerialized;
SerializeWaveFile(rawSerialized, sw->RawPCMData, info.SampleDataSize, info.NumChannels, info.SampleRate);
sw->RawData.Lock(LOCK_READ_WRITE);
void* LockedData = sw->RawData.Realloc(rawSerialized.Num());
FMemory::Memcpy(LockedData, rawSerialized.GetData(), info.SampleDataSize);
sw->RawData.Unlock();
**Full Frankenstein OGG import code: **
USoundWave* **XXXXXXXXX**::GetSoundWaveFromOGGFile(const FString& filePath, bool& Success){
if (filePath == "") { Success = false; return nullptr; }
char* filePathChar = TCHAR_TO_ANSI(*filePath);
USoundWave* sw = NewObject<USoundWave>(USoundWave::StaticClass());
if (!sw) { Success = false; return nullptr; }
TArray < uint8 > rawFile1;
FFileHelper::LoadFileToArray(rawFile1, filePath.GetCharArray().GetData());
FByteBulkData* bulkData = &sw->CompressedFormatData.GetFormat(TEXT("OGG"));
bulkData->Lock(LOCK_READ_WRITE);
FMemory::Memcpy(bulkData->Realloc(rawFile1.Num()), rawFile1.GetData(), rawFile1.Num());
bulkData->Unlock();
FSoundQualityInfo info;
FVorbisAudioInfo vorbis_obj;
if (!vorbis_obj.ReadCompressedInfo(rawFile1.GetData(), rawFile1.Num(), &info))
{
return nullptr;
}
else
{
sw->SoundGroup = ESoundGroup::SOUNDGROUP_Default;
sw->NumChannels = info.NumChannels;
sw->Duration = info.Duration;
//sw->TotalSamples = info.SampleDataSize;
sw->RawPCMDataSize = info.SampleDataSize;
sw->SetSampleRate(info.SampleRate);
// - Decompress and bake PCM Data from file into SoundWave
sw->RawPCMData = (uint8*)FMemory::Malloc(sw->RawPCMDataSize);
vorbis_obj.ExpandFile(sw->RawPCMData, &info);
sw->bDecompressedFromOgg = true;
//SERIALIZE PCM AND FILL IN RAW DATA
TArray < uint8 > rawSerialized;
SerializeWaveFile(rawSerialized, sw->RawPCMData, info.SampleDataSize, info.NumChannels, info.SampleRate);
sw->RawData.Lock(LOCK_READ_WRITE);
void* LockedData = sw->RawData.Realloc(rawSerialized.Num());
FMemory::Memcpy(LockedData, rawSerialized.GetData(), info.SampleDataSize);
sw->RawData.Unlock();
}
if (!sw) { Success = false; return nullptr; }
Success = true;
return sw;
}