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:
- All contents of the folder 'NAudio-Visualizing' (except the Waveform stuff unless you want it).
- CommonUtils\ColorUtils.cs
- CommonUtils\ExtendedGraphics.cs
- CommonUtils\MathUtils.cs
- CommonUtils\MidiUtils.cs
- CommonUtils\Audio\NAudio\AudioUtilsNAudio.cs
- CommonUtils\Audio\NAudio\NAudio.dll
- CommonUtils\FFT\AudioAnalyzer.cs
- CommonUtils\FFT\FFTWindows.cs
- CommonUtils\FFT\LomontFFT.cs
- CommonUtils\FFT\ExocortexDSP\Complex.cs
- CommonUtils\FFT\ExocortexDSP\ComplexF.cs
- CommonUtils\FFT\ExocortexDSP\Fourier.cs
- CommonUtils\FFT\ExocortexDSP\FourierDirection.cs
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)
- In the
MathUtils
class Removedreturn
from anyYield return ...
statements and addIterator
to the method. - Change the
MathUtils
class to a module to fix error with extensions. - Fix
Case
statements with...,Else
. - Remove
var
fromFor Each
statements. - In the
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:
Private m_Volume As Single = 0.2F 'Desired default volume
Private audioFileReader As AudioFileReader
Private fadeInOut As FadeInOutSampleProvider
Private m_fadeDuration As Integer = 250 'Desired fading duration
In the OpenFile
Method, change all in the Try
statement to:
waveOutDevice = New WaveOutEvent() With { _
.DesiredLatency = definedLatency _
}
audioFileReader = New AudioFileReader(path)
ActiveStream = DirectCast(audioFileReader, WaveStream)
inputStream = New WaveChannel32(ActiveStream)
fadeInOut = New FadeInOutSampleProvider(New WaveToSampleProvider(inputStream))
audioFileReader.Volume = Volume()
sampleAggregator = New SampleAggregator(m_fftDataSize)
AddHandler inputStream.Sample, AddressOf inputStream_Sample
waveOutDevice.Init(New SampleToWaveProvider(fadeInOut))
ChannelLength = inputStream.TotalTime.TotalSeconds
FileTag = TagLib.File.Create(path)
GenerateWaveformData(path)
CanPlay = True
In the Pause()
Method change waveOutDevice.Pause()
to fadeInOut.BeginFadeOut(fadeDuration())
In the Play()
Method, In CanPlay
statement:
fadeInOut.BeginFadeIn(fadeDuration())
waveOutDevice.Play()
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
to False
. 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.