AudioComponent not playing sound in PIE.

This is strange, there is sound in simulation, but in other modes, no sound at all.

In Tick function:

	if (!IsRunningDedicatedServer() && AudioComponent == NULL)
		AudioComponent = CreateVoiceAudioComponent(44100);

	if (AudioComponent != nullptr)
		if (AudioComponent->Sound)
			USoundWaveProcedural* SoundStreaming = CastChecked<USoundWaveProcedural>(AudioComponent->Sound);
			uint32 const maxBytes = 44100;
			uint8 buf[maxBytes];
			SoundStreaming->GeneratePCMData(buf, 44100);
			SoundStreaming->QueueAudio(buf, 5120); 
			UE_LOG(LogTemp, Warning, TEXT("AudioComponent->Sound is null."));


And the CreateVoiceAudioComponent function: (copied from OnlineSubsystemUtils.cpp)

   UAudioComponent* AudioComponent = nullptr;
	if (GEngine != nullptr)
		if (FAudioDevice* AudioDevice = GEngine->GetMainAudioDevice())
			USoundWaveProcedural* SoundStreaming = NewObject<USoundWaveProcedural>();
			SoundStreaming->SampleRate = SampleRate;
			SoundStreaming->NumChannels = 1;
			SoundStreaming->Duration = INDEFINITELY_LOOPING_DURATION;
			SoundStreaming->SoundGroup = SOUNDGROUP_Music;
			SoundStreaming->bLooping = false;

			AudioComponent = AudioDevice->CreateComponent(SoundStreaming);
			if (AudioComponent)
				AudioComponent->bIsUISound = true;
				AudioComponent->bAllowSpatialization = false;

	return AudioComponent;

It plays noise in simulation, but nothing in other mode.
Help please!

When I start PIE mode , then wait for a number of seconds then exit, it will play noise for the same number of seconds.

You are giving it an uninitialized buffer of 44100 bytes. You will get random results, if it happens to be based on zeroed out memory you will get silence. If not you will get random noise for one second (assuming the sample rate is also 44100) and then silence (procedural audio component inserts silence during buffer underflow by default).

PIE maybe just happens to to have zeroed out data.

Isn’t GeneratePCMData generated noise?
I don’t think this is the problem.
I’ve tried to make my SoundStreaming accessible in BP then create AudioComponent from BP, feed the SoundStreaming, then it works.
So it might be something with creating the UAudioComponent in C++ code.

Ah I might be remembering wrong. I think GeneratePCMData is called by the audio component on any sound wave it uses, and you aren’t supposed to call it yourself in your code.

If I am reading/remembering things right, you add generated sound to your USoundWaveProcedural with QueueAudio and then the audio component reads it by calling GeneratePCMData() on your USoundWaveProcedural, the same interface it uses for other sound waves.

Hey dude, Sorry for opening an old thread, but do you know if this is how usoundwaveprocedural should work? I have a vidoeo call system that returns the audio as frame buffers. I queue the audio frame using QueueAudio and then set the sound in my audio component, but I get no sound AND the GeneratePCMData is never called. So the Audio is never pumped into the audio buffer which in turn means it’s never sent into the sound rendering thread.

I think GeneratePCMData is only part of the old audio system. I’m using the new one now so it is by subclassing USynthComponent and implementing OnGenerateAudio.