Download

How can i get RawPCMData from FSoundBuffer?

So basically i am trying to record game sound and save it to .wav file while player in game.
Later on maybe it also will be used to stream gameplay.

Problem arise when i try read compressed data from buffer. Maybe its first need to be decompressed?
There is very little information about UE4 audio recording and streaming actually.

So far what i have done. (Using FPS shooter template)

  1. I created simple C++ Actor class.
  2. And in Tick function() implemented this

void AAudioActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (GEngine) {
// finding active audio device
audioDeviceManager = GEngine->GetAudioDeviceManager();
}

if (audioDeviceManager) {

    // getting all buffers from that device
    TArray<FSoundBuffer*> AllAudioDeviceBuffers = audioDeviceManager->Buffers;
    UE_LOG(LogTemp, Warning, TEXT("Buffer size: %d"), AllAudioDeviceBuffers.Num());

    // for every buffer reading its info
    USoundWave *dest = nullptr;

    for (const auto &buffer : AllAudioDeviceBuffers) {
        int32 bufferSize = buffer->GetSize();
        buffer->ReadCompressedInfo(dest); // <--- HERE where warning comes

        UE_LOG(LogTemp, Warning, TEXT("Buffer Size: %f"), &bufferSize);
        if (dest) {
            uint8 *rawPCMdata = dest->RawPCMData; // <--- HERE cant get data
            int32 PCMSize = dest->RawPCMDataSize;

            UE_LOG(LogTemp, Warning, TEXT("Size %d"), PCMSize);
        }
    }        
}

}

  1. When i starting game, In output log it gives me this warnings.

LogTemp: Warning: Buffer size: 2
LogXAudio2: Warning: Attempting to read compressed info without a compression state instance for resource ‘/Engine/EditorSounds/Notifications/CompileSuccess.CompileSuccess’
LogTemp: Warning: Buffer Size: 0.000000
LogXAudio2: Warning: Attempting to read compressed info without a compression state instance for resource ‘/Game/FirstPerson/Audio/FirstPersonTemplateWeaponFire02.FirstPersonTemplateWeaponFire02’