Page 1 of 1

[2.2] OgreAL spectrum analysis and beat detection

Posted: Thu Apr 23, 2020 7:15 pm
by Lax
Hi all,

I extended OgreAL a little bit. I now use newer version of OpenAL implementation from github:

* https://github.com/kcat/openal-soft

* I also implemented audio spectrum analysis with beat detection. I orientated on: https://www.parallelcube.com/2018/03/10 ... d-and-ue4/

* For fft I use the library kiss_fft (https://github.com/berndporr/kiss-fft), which is now part of OgreAL.

See scenario:



If somebody wants to use the OgreAL extension in its own projects. It can be downloaded from this site:

https://sourceforge.net/p/nowa-engine/s ... al/OgreAL/
Code example:

Code: Select all

// Create sound and use (streaming = true)

int spectrumProcessingSize = 1024;
int numberOfBands= 30;
float minHeight = 0.05f;
float maxHeight = 16.0f;

sound->enableSpectrumAnalysis(true, spectrumProcessingSize, numberOfBands, OgreAL::MathWindowType::BARLETT, OgreAL::SpectrumPreparationType::LOGARITHMIC, 0);
sound->addSoundSpectrumHandler(SimpleSoundComponent::soundSpectrumFuncPtr);

void SimpleSoundComponent::soundSpectrumFuncPtr(OgreAL::Sound* sound)
{
	OgreAL::Sound::SpectrumParameter* spectrumParameter = sound->getSpectrumParameter();
	if (nullptr != spectrumParameter)
	{
		auto levelData = sound:getLevelData();
		
		if (sound->isInstrument(OgreAL::Instrument::KICK_DRUM))
		{
			// do something
		}
		
		if (sound->isInstrument(OgreAL::Instrument::SNARE_DRUM))
		{
			// do something
		}
		
		if (sound:isSpectrumArea(OgreAL::SpectrumArea::DEEP_BASS))
		{
			// do something
		}
		
		for (int i = 0; i < sound->getActualSpectrumSize() - 1; i++)
		{
			 local newY = minHeight + (levelData[i] * (maxHeight - minHeight) * 0.5f);
			 lines->setStartPosition(i, Vector3(i * 0.2f, 0, 0));
			 lines->setWidth(i, 0.2f);
			 lines->setHeight(i, newY);
		}
	}
}
The detection and spectrum algorithm can have some optimizations or adapting internal parameter is necessary. Play for yourself. I have no more patience to put more effort into this topic :)

Best Regards
Lax

Re: [2.2] OgreAL spectrum analysis and beat detection

Posted: Thu Apr 23, 2020 8:12 pm
by xrgo
niiiiice! and many many thanks for sharing

Re: [2.2] OgreAL spectrum analysis and beat detection

Posted: Sun Apr 26, 2020 5:08 pm
by Lax
You‘re welcome :wink:

Re: [2.2] OgreAL spectrum analysis and beat detection

Posted: Tue Apr 28, 2020 3:51 am
by rujialiu
While I probably won't have chance to use it in our projects, I personally like this very much. Thanks for sharing!!!