Hey guys,
I spend some time on writing an importer for .ogg files. For this I made my own USoundFactory and implemented the function FactoryCreateBinary.
Now I ran into a few problems with the data.
The importing itself works so far, but the sound itself is not working as I want it to work.
The USoundFactory does this with the Buffer that gets passed in the FactoryCreateBinary function:
Sound->RawData.Lock( LOCK_READ_WRITE );
void* LockedData = Sound->RawData.Realloc( BufferEnd-Buffer );
FMemory::Memcpy( LockedData, Buffer, BufferEnd-Buffer );
Sound->RawData.Unlock();
So it’s basically copying the Buffer into the RawData of the USoundWave. RawData is of type FByteBulkData.
Naw RawData is commented to be
, so I can’t really use that.
In fact, if I do it the same way, I just can’t an imported USoundWave object that does not play anything.
Here is what I did, and what results in sound actually playing:
FByteBulkData* BulkData = &Sound->CompressedFormatData.GetFormat(FName("OGG"));
BulkData->Lock(LOCK_READ_WRITE);
FMemory::Memmove(BulkData->Realloc(RawOggData.Num()), RawOggData.GetData(), RawOggData.Num());
BulkData->Unlock();
RawOggData is just a TArray in which I copied the Buffer:
// Array that holds the Raw Ogg Data
TArray<uint8> RawOggData;
RawOggData.Empty(BufferEnd - Buffer);
RawOggData.AddUninitialized(BufferEnd - Buffer);
// Copy over the Buffer into the Raw Ogg Data array
FMemory::Memcpy(RawOggData.GetData(), Buffer, RawOggData.Num());
So I put the Buffer into the CompressedFormatData, which is a TMap of FByteBulkData. Key is OGG here.
While this works in the Editor Process in which I imported the file, the file does not play anthing anymore after I closed and re-opened the editor.
Now I assume that the Editor clears the CompressedFormatData? What I can do with the Buffer/SampleData to store it?
I looked into different functions but I can’t figure it out. One thing I came to was using:
OggInfo.ExpandFile(RawPCMData.GetData(), &QualityInfo);
With OggInfo being of type FVorbisAudioInfo, RawPCMData being a TArray again and QualityInfo being of type FSoundQualityInfo.
Before I call this I called
OggInfo.ReadCompressedInfo(RawOggData.GetData(), RawOggData.Num(), &QualityInfo)
.
This, if I understood it correctly, should have filled the QualityInfo as well as the VorbisData Pointer that is inside of the OggInfo.
But ExpandFile is freezing the Editor. In Debug mode it breaks at checking if BytesRead is < 0. I don’t even get how that can fail as BytesRead is of type long.
I feel like I’m running in a circle. Would really love some help here. Is it even possible to import .ogg files and “save” them properly for Editor restarts and even packaging?