Accessing SoundWave PCM Data from C++ Code

Hi All -

I would like to use the PCM data that is saved in a .wav file directly as the starting point for a procedurally generated sound. I already have a “procedural sound node” working which can fill the PCM buffer with data created in code at runtime. I would now like to use data from an existing .wav asset (and modify it with some code).

I tried using the USoundWave 's RawData.GetCopy() and can see the bytes in this buffer, but the data here seems to be compressed or not what I’m expecting. I created a simple sound file with only three samples at -1.0 0.0 and 1.0, but do not see these in the buffer.

How can I access the PCM Data from a USoundWave?

I think you’re interested in the RawPCMData variable. You can look in FAudioThumbnail::GenerateWaveformPreview for an example of how to make sure it has been decompressed before you use it.

Thanks !!

That IS exactly what I’m looking for. The data still looks slightly “off” though. I created a very simple test wave file using MATLAB and output the signal x=-1.0 0.0 1.0]. I expected to see the values -32768 0 32767 ] for the 3 samples in the buffer, but I see -32768 -28 32767 ] instead (very close but not exact). I have the soundwave asset compression quality set to 100, and MATLAB should output an uncompressed wave file. Other tests show the results come out very close to the original signal, but not quite exact.

It seems this has been compressed/decompressed with “high quality” (compression quality set to 100), but not treated as completely uncompressed.

Does compression quality set to 100 mean uncompressed, or just high quality compression?

It might also be worth looking into VST Synthesisers, providing you can find ones that are open-source.

a vst wrapper for ue4 would be awesome!
its way beyond my ue4 knowledge atm, maybe someone else could have a go
sdk
http://www.steinberg.net/en/company/developers.html
open source examples
http://sourceforge.net/projects/mda-vst/

High quality. And with ogg, not the best possible quality because in UE3 there was some code put in to try and make the compression quality consistent across platforms because XMA had worse quality. You can try changing the VORBIS_QUALITY_MODIFIER define in AudioFormatOgg.cpp to 0 and see if you get something more like what you would like to be seeing. I need to figure out what to do about that define :confused:

@ - Thanks for the info! For my case it’s OK that the quality is not so perfect even at quality setting = 100. I just needed to confirm that the differences are coming from the compression and not my misunderstanding of the implementation.

@tegleg , @TheJamsh : I’m only working with a few hand-crafted audio assets atm, so I’m able to get by without a full VST tool for now.

I have my nodes working now as expected now! I just need to do some clean up and make sure I’m using Unreal’s objects properly (construction/destruction etc.)

Thanks all.