OGG file importer - How to work with the Buffer?

Hey eXi,

Sorry it sounded like you had audio playing at some point, where the issue was only with having the asset persist between editor launches. I’ve only written one factory type, for my own custom extended music module code (.xm) and it doesn’t use USoundFactory and full disclosure: I’ve only been using UE4 for a little over a month.

What I was stating is that if you’re able to get the ogg to raw 16 bit PCM, it would be fairly simple to append a wav file header to the pcm data. The WAV format is somewhat of a modular one in that WAV files are able to define different codecs based upon the header within the file. So thinking that FactoryCreateBinary is being sent a buffer containing the exact bytes of the file, you could take the ogg, expand it to acquire the pcm (raw wave data in 16 bit signed integers, interleaved if stereo) from the ogg file and prefix it with the file header of wav that accurately describes the uncompressed pcm (such as if its stereo or mono), then the Super::FactoryCreateBinary would read that to setup its internals as if it were a wav file on disk (in theory).

I may be incorrect but it seems that unreal basically reads from the actual file input once, saves the path to the original file if you want to reimport it at a later time where the cooking process actually deals with deciding what should be compressed or not. So I’d think the goal would be to get the input buffer containing the ogg data, then convert that to wav in memory then send that to Super while you declare the file type is WAV.

So yea, it sounds like if UE4 does have ogg expanding functions in it that are for whatever reason failing, you could try utilizing public domain Ogg Vorbis decoder ( stb/stb_vorbis.c at master · nothings/stb · GitHub ) to get the pcm data. That way you’ll at least be able to determine if it is a bug with UE or not.

Once you got the pcm in a 16bit signed integer format, you would just prefix the data with a basic wav file header. I found this on google but you may be able to find a better resource: Microsoft WAVE soundfile format

Basically, you just insert those descriptions in ahead of the pcm data, that should leave you with a compatible WAV file (in memory) that you can pass to the super.

If i’m missing / misunderstanding anything, let me know. I’m interested to hear about it as I plan on writing various factories as well. Thanks

Also, on your note about the differences between ogg and wav. PCM (pulse code modulation) is ultimately what hits the speakers, unreal basically requires that the pcm be in sixteen bit signed integers (shorts) which is traditionally standard. when the integer is SHORT_MIN the speaker is all the way in, and SHORT_MAX out (or vicsa versa), the actual movement/acceleration of the speaker moving in and out is what produces the sound though. When speaking of the most basic type of WAV file, it has this raw pcm data immediately after the file header for the wav, where formats like OGG and MP3 use methods to have less variation in the samples, then use compression on top of that similar to zip.