Been looking for a way to do this all day with no hope. I'm creating a project with MP3 playback functionality and I'm trying to include a spectrogram (or spectrum analyser.. not sure what the proper name for it is) similar to this http://puu.sh/4lkMn.png (Winamp) (though if it's not in bars, that's fine too)
I've currently been using WMP for the audio playback but WMP doesn't have any methods for plotting a spectrogram.
I looked into using NAudio which seems promising: http://naudio.codeplex.com/ They have a demo for the Spectrum Analyser but they do not provide a source for that demo.
I also looked into this http://wpfsvl.codeplex.com/ which uses NAudio but it uses WPF instead of WinForms (my project is using WinForms) and I'm not sure how I would convert it to WinForms.
Google doesn't seem to have too much information on this for .Net The only thing I really need is an actual example of the source with NAudio implementation, but all I could find was other people pointing out the fact that the example source isn't actually made available.
..And I just noticed that their demo has 'wpf' in the name, so even if the source was available it'd be similar to the WPFSVL implementation which I'm incapable of. :(
I found the example I converted from, it was AudioVSTToolbox
Here is my result from all this: http://puu.sh/4mWU8.png
(I'm copying my Winamp theme :) )
The minimum required to get Spectrum Analyzer working from that Toolbox are the following:
If converting to VB .Net, I used the converter here. It doesn't convert everything correctly though, the following are notable fixes required: (I can't remember all the changes I did unfortunately, it's not too difficult and you can search around for any conversion problems you may have)
MathUtilsclass Removedreturnfrom anyYield return ...statements and addIteratorto the method.MathUtilsclass to a module to fix error with extensions.Casestatements with...,Else.varfromFor Eachstatements.ExtendedGraphicsclass, rename the NamespaceSystem.Drawing.ExtendedtoAudioSystem.Drawing.Extendedas it conflicts with theSystemNamespace.A few changes I made personally:
In the
NAudioEngineclass I changed the value of theDesiredLatencyproperty to 200 as the default causes static.In the
NAudioEngineclass I changed the Pause functionality to use fading because without fading there seems to be a bug which produces static when resuming. Do the following changes to add fading (and additionally volume control):Add the Fields:
In the
OpenFileMethod, change all in theTrystatement to:In the
Pause()Method changewaveOutDevice.Pause()tofadeInOut.BeginFadeOut(fadeDuration())In the
Play()Method, InCanPlaystatement:To change the style of the graphic to bars, in the code of the custom Spectrum Analyzer control, change the default value of
Public DoSpectrumGraph As Boolean = TruetoFalse. Then you can change the fields above that to style the bars however you wish.In the
Event Overridesregion, you can change the colours/drawing methods.