Reading Audio Data from Event in C++

Can you access the audio data in code from within an UFMODAudioComponent / UFMODAmbientSound while the audio is playing? I know you would typically add an event to the file in the FMOD Studio, add that event to the sound in UE4.

There is also examples in the api that show how to read data from low level. I can read directly from sound files. But I do not want to do that. I want to read data from the events in the game from where they are placed in the world. Am I missing something in the code examples?

Is there an actual way to gain access to the data coming from the event? Is it compressed, or in a specific format once it is in an event? Or is it just standard FMOD_SOUND_FORMAT_PCMFLOAT?

I’ve read a few posts on getWaveData, but that is gone, right? Do I use DSP related commands? I seen some stuff on channel groups, active channels, and such. Am I looking in the right direction? I feel like there is just one element I’m missing, and it confusing me.

Hi Tim,
You can do what you want, but you’ll have to dig into some C++ code to do it.

If you just want the general sound levels, you can use the FMOD function DSP::getMeteringInfo to obtain them. You’ll have to peek into the underlying channel and DSP effect to do that.

For example, the following code can be added to the UFMODAudioComponent will print the rms levels during the TickComponent function:

	FMOD::ChannelGroup* ChanGroup = nullptr;
	if (ChanGroup)
		FMOD::DSP* ChanDSP = nullptr;
		if (ChanDSP)
			ChanDSP->setMeteringEnabled(false, true);
			ChanDSP->getMeteringInfo(nullptr, &Info);
			UE_LOG(LogFMOD, Warning, TEXT("Metering: %d channels, %d len.  rms: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f" ), 
					Info.numchannels, Info.numsamples, 
					Info.rmslevel[0], Info.rmslevel[1], Info.rmslevel[2], Info.rmslevel[3], Info.rmslevel[4], Info.rmslevel[5]);

Alternatively, if you want the actual PCM signal rather than just overall volume level, then the best way to do that is to have a custom DSP effect. The effect can have a read callback that is passed the PCM float data.

You can create your DSP at runtime and add it to the event instance’s channelgroup. See the dsp_custom low-level example in the Programmers API, available from the FMOD download page. It shows registering a custom DSP that halves the signal. Instead you could just read the signal and pass it through unchanged.

Ah, Ok. I’d be doing the latter, and trying to get the PCM data.

All my metering info says 0. I did an output for all 4 values in the struct, and they all say 0. Even the numchannels, should it not at least say 1?

It should only come through 0 initially, until the next mix that occurs with actual sound data (~20ms). I can test and get back to you.

Ok Thanks. Because I’m not sure if I’m setting up my instance in code right.

Hi Tim, I updated the above answer code with exactly what I put into UFMODAudioComponent::TickComponent just inside the “if (bIsActive)” block. It should spam out rms levels for the sound.