Audio spectrum using WPF and C++ CLI

Hi! this is my first post and I want to begin to tell you about my experiences and experiments regard .NET world.

There is a feature that lots of applications and sites miss. I'm talking about the audio spectrum, sometime built by fake bars that don't follow the music. So I developed a mixed assembly using C++ CLI that process audio samples and computes peaks grouping them by frequency range. Through DirectShow I load audio track and I grab 44100 samples per second and I transform them with FFT (I found this good guide) . FFT is heavy calculation to repeat many times per second, thus I chosen C++ CLI to reduce interop, limiting it only to the peaks exposed as a property.

The WPF side contains a custom element named AudioVisualization that 12 times per second loads peaks and shows bars using animations. My sample player contains a simple skin, but obviuosly we can customize bars exploiting WPF capabilities.

Here a video demo:

Reyalp
Reyalp

Full source code is available here.

Published 16 February 2008 01:38 PM by RiccioloCristian
Filed under: , ,

Comments

# Rob Relyea said on 16 February, 2008 12:39 PM

Ricciolo did a post about a new control that he built that can visualize audio spectrum in WPF . 

# Pietro said on 18 February, 2008 11:23 AM

Nice first post. C++/CLI is useful in such a situation.

-Pietro

# Ron N said on 01 April, 2008 12:16 PM

Awesome sample.  However, I can't compile it.

Should the DirectX 9 SDK be installed in order to compile?  I got the following error trying to compile with VS2008:

fatal error C1083: Cannot open include file: 'dxtrans.h': No such file or directory C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\Qedit.h 498 Ricciolo.Media.WaveSpectrum

# RiccioloCristian said on 04 April, 2008 05:52 PM

No, you need only Platform SDK. May be I used full path to the header files. Check them into the property project.

# Elaina said on 08 April, 2009 05:31 AM

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

Elaina

www.craigslistmaster.info

# chao said on 23 April, 2009 11:01 PM

I downloaded the code and compile by vs 2008, it comes out 5 errors which including Ron's. I'm a beginner of VS2008. What should i do to make it work?

Thanks

# Anton Winter said on 29 May, 2009 09:51 PM

hi all, i ran into the dxtrans.h problem as well.  here is the fix

Remove anything to do with "dxtrans.h" and "IDXEffect" from qedit.h( comment them out)

for file "qedit.h"

> //#include "dxtrans.h" -- Line 498

> IDxtCompositor //: public IDXEffect -- Line 837

> IDxtAlphaSetter //: public IDXEffect -- Line 1151

> IDxtJpeg //: public IDXEffect -- Line 1345

> IDxtKey //: public IDXEffect -- Line 1735

# Anton Winter said on 29 May, 2009 10:14 PM

Hi Cris,  thanks for putting up this code.  there is so little info on wpf and audio visualizers out there.

right now im getting around 60% cpu when running it.  is there a way to speed it up, even if it means less accurate results?

# JaneRadriges said on 13 June, 2009 12:46 PM

Great post! I'll subscribe right now wth my feedreader software!

# Adam Walker said on 30 June, 2009 10:57 AM

Hi there, I just downloaded the source for your project and managed to get it to build via alot of commenting in qedit.h.

Unfortunately now the accuracy seems to be quite a way out...

Any chance of a re-release? Or possibly even the source for your silverlight FFT project?

I'm currently trying to learn about interoperability with win32 and wpf to visulise, and you seem to know what you're doing!

Source would help me enormously!

# The Dude said on 08 January, 2010 09:04 PM

This is by far the best looking sample for an audio spectrum visualizer that I have found. However, I am completely puzzled by following line:

float v = (((int)sqrtf(im * im) / FFT_LEN/2) % 100);

I realize the progress bars display have a max of 100, but why % 100? Conceptually, it seems like that would give arbitrary values for the peak, since the numbers are often greater than 100, sometimes by orders of magnitude.... However, as I said, this is a darn good looking equalizer, so it works fine despite that I don't understand it...

For those concerned about performance, you'll notice that since the block size is the same every time the FFT is called, so you can store an array of the angles for fSin1, fSin2 and fCos1 and fCos2.

# maneesh said on 01 February, 2010 10:33 AM

I have downloaded your app. It works on some machines but does not work on other. I have dotnet framework installed on all machines. Does you application have any special dependencies?

# wintanweor said on 09 February, 2010 06:39 PM

open decline 180 climatic globe warmest

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Search

Go

This Blog

Sponsors





Syndication

 
Page view counter