[2.2] OgreAL spectrum analysis and beat detection

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Lax
Gnoll
Posts: 683
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 65

[2.2] OgreAL spectrum analysis and beat detection

Post 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

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 169

Re: [2.2] OgreAL spectrum analysis and beat detection

Post by xrgo »

niiiiice! and many many thanks for sharing
Lax
Gnoll
Posts: 683
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 65

Re: [2.2] OgreAL spectrum analysis and beat detection

Post by Lax »

You‘re welcome :wink:

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

rujialiu
Goblin
Posts: 296
Joined: Mon May 09, 2016 8:21 am
x 35

Re: [2.2] OgreAL spectrum analysis and beat detection

Post by rujialiu »

While I probably won't have chance to use it in our projects, I personally like this very much. Thanks for sharing!!!