Hi,
I’m trying to decompress a SoundWave to access raw PCM data.
I’ve been trying like this, at BeginPlay():
if (MusicWave != nullptr) {
// MusicWave->AudioDecompressor->StartSynchronousTask();
MusicWave->AudioDecompressor->StartBackgroundTask();
MusicWave->AudioDecompressor->WaitCompletionWithTimeout(600);
UE_LOG(LogMyActor, Log, TEXT("RAW PCM DATA SIZE %d"), MusicWave->RawPCMDataSize);
}
Starting a sync task crashed the UE editor immediately when hitting Play, so I tried it in the background and wait, but yielded the same crash.
I’ve managed to access some raw data as follows:
const uint8* data = (const uint8*)MusicWave->RawData.Lock(LOCK_READ_ONLY);
if (data != nullptr) {
FString str;
for (int32 i = 0; i < MusicWave->RawData.GetBulkDataSize(); ++i) {
char buf[8];
sprintf(buf, " %d", data[i]);
str += (const char*)buf;
}
UE_LOG(LogMyActor, Log, TEXT("str %s"), str.GetCharArray().GetData());
}
else {
UE_LOG(LogMyActor, Log, TEXT("data is nullptr"));
}
MusicWave->RawData.Unlock();
However I’m not sure if this is the raw sound data which is ready to be processed (e.g. to which I can apply FFT to), or it’s the raw bytes of the sound file (including WAV metadata).
I would also be very happy if someone could point out how it’s possible to create such an UPROPERTY to which I can assign any kind of file (.wav in this case) as a buffer. From then on it would be a simple .wav file parsing to get the PCM data and apply FFT to extract the spectrum.