Download

Grabbing decibels from audio

So I am currently working on a school project that is going to be used to create awareness among teenagers of the extends of hearing damage.
One of the mechanics is that when in an area with a lot of noise the user puts on his/her hearing protection in-game. But for the user to know when a certain noise is damaging we want to show a decibel meter.
I have checked out Exi’s sound visualizer and Goddess Sound visualizer but they all only offer visualization of 1 soundwave. I would like to visualize the current sound rather than the source of the sound.
If anyone can point me in the right direction or even has some examples that would be amazing.

Hi Erikb

From the USoundWave class you can ask for the bytes size and the RawPCMData, which is just a regular uint8*, and you can use some formulas to read the PCM data and find decibels in certain amount of bytes, I am using this to get microphone decibels for one of my projects,



//NOT REAL DECIBELS, just faked hehe
float getDecibels(uint8* data, uint32 inByteSize)
{
	int16_t Samples;
	float Squared = 0;
	for (uint32 i = 0; i < (inByteSize / 2); i++)
	{
		Samples = (data[i * 2 + 1] << 8) | data[i * 2];
		Squared += ((float)Samples * (float)Samples);
	}
	float Dec = (2 * (Squared / inByteSize));
	Dec = FMath::Sqrt(Dec);
	Dec = ((Dec / 32768.0) * 200.f);

	return Dec;
}



there is a lot of info just type for PCM data and c++, pretty sure that you can find more examples!

And by the way, I heard that the new 4.16 will come with a cool node to do stuff like this for us!

RawPCM data isn’t packaged though, so it won’t work in a packaged project AFAIK. I wrote a system similar to the Goddess one, but compress the data for packaged games.

The new Audio Engine has better tools for this kind of thing (like envelope followers etc), I’d update to 4.16 and start poking around.

I believe is totally packageble since is just a public member outside the editor’s pragmas, otherwise yes he can compress the data in a custom class, indeed, but I think is better if we wait a bit for the next release, totally agree with TheJamsh

The audio data is compressed (generally to Ogg) on packaging. But anyway OP was after the resultant sound rather than specific sources, so although I haven’t used it yet, pretty sure TheJamsh is correct in that the new audio rendering engine should provide a way to do this.

Thanks for the answers I will definitely look into 4.16