Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Audio playback and spectrum analysis libarary for C# [closed]

I would like to create a little application that plays back a music file (format doesn't really matter). The hard part is: at the same time I would like to display the current amplitude of the lower frequencies (bass), the middle frequencies and the high frequencies.

So I would need some kind of simple spectral analysis together with playback functionality. Is there a C# audio library that can do this without too much hassle?

The purpose of this project is to drive an RGB-LED lighting system I've recently installed in my room ;-)

like image 609
Boris Avatar asked Dec 27 '22 17:12

Boris


1 Answers

NAudio : http://naudio.codeplex.com/ (Open source)

Bass and Bass.Net: http://www.un4seen.com/ (Free for non commercial)

Fmod Ex: http://www.fmod.org/index.html (Also free for non commercial use)

Doing what you need using Bass is very easy:

string filepath ="";
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero, null);
int handle = Bass.BASS_StreamCreateFile(filepath, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT);
Bass.BASS_ChannelPlay(handle,false);

Then to get spectrum:

float[] buffer = new float[256];
Bass.BASS_ChannelGetData(handle, buffer, (int)BASSData.BASS_DATA_FFT256);

From there you can easily average bands for specific frequencies

like image 109
mrvux Avatar answered Feb 13 '23 02:02

mrvux