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)
MathUtils
class Removedreturn
from anyYield return ...
statements and addIterator
to the method.MathUtils
class to a module to fix error with extensions.Case
statements with...,Else
.var
fromFor Each
statements.ExtendedGraphics
class, rename the NamespaceSystem.Drawing.Extended
toAudioSystem.Drawing.Extended
as it conflicts with theSystem
Namespace.A few changes I made personally:
In the
NAudioEngine
class I changed the value of theDesiredLatency
property to 200 as the default causes static.In the
NAudioEngine
class 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
OpenFile
Method, change all in theTry
statement to:In the
Pause()
Method changewaveOutDevice.Pause()
tofadeInOut.BeginFadeOut(fadeDuration())
In the
Play()
Method, InCanPlay
statement: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 = True
toFalse
. Then you can change the fields above that to style the bars however you wish.In the
Event Overrides
region, you can change the colours/drawing methods.