May 2009 - Posts

Silverlight - Real time audio peak meter

I have implemented an audio peak meter for Silverlight. It uses two different ways: pre computed FFT or real time FFT.

The first technique is a console application that process audio file using DirectShow and produce a dat file containing peaks data, 12 frames per second. Then a DataAudioPeakMeter load this data file and it keeps MediaElement and BarVisualization synchronized. That works with any supported media types by Silverlight 2.0/3.0.

The second technique use a custom MediaStreamSource, called WavMediaStreamSource, that loads external wav file and provides raw samples to the MediaElement. This samples are also processed to flow BarVisualization animation.

Here is the result:

fftHere you can see a video demonstration of pre computed method.

Unluckily MediaStreamSource doesn’t allow to get audio raw samples decoded by Silverlight engine, so you can’t apply FFT on MP3/WMA file. You have to decode it using managed code (anyone has a decoder class?).

I hope in the future MS will give this possibility.

Show webcam images into Silverlight

With current Silverlight release or available beta you can't view webcam images from local machine so I thought to a trick to do it using a local winform application distributed using ClickOnce.

Here you are the result (YouTube video)

This sample work using two applications:

  1. a winform application started navigating to the .application file, that runs a DirectShow graph to grab webcam images and send it through a Motion JPEG;
  2. a silverlight application that uses socket connection to the local winform application to receive each frame from the webcam.

The winform application also implements policy server to trust socket connection from Silverlight to local application. From Silverlight prospective, it receive each jpeg frame and show it through the BitmapImage.SetSource method giving a fluid animation. It's a simple game and it allow only to capture and save webcam frames.

You can download full source code here. Enjoy!

MetadataDiffViewer updated to .NET Framework 4.0 beta1

I have updated my MetadataDiffViewer to the recent .NET Framework 4.0 beta1 so you can see differences by 3.5 SP1.

You can note some interesting changes:

  • System.Web.Routing and System.Web.Abstractions are empties because their classes were included into System.Web. The attributes TypeForwardedToAttribute and TypeForwaredFromAttribute tell to CLR, compilers and serializer to remap to new location so old builds based on 3.5 can work;
  • new assemblies System.Web.DataVisualization and System.Windows.Forms.DataVisualization containing new charting controls for ASP.NET and WinForms application;
  • some new nice classes into System.Core: lots of Action<T,..Tn> and Func<T,..Tn>, a new ExpressionVisitor to navigate into expression tree, and some new static methods for Expression class allowing to create more complex expressions containing try/catch, switch, loop, goto, ecc;
  • new assembly System.ComponentModel.Composition containing Managed Extensibility Framework;
  • new namespace System.Diagnostics.Contracts containing the class Contract with usefull methods for compilation and runtime checks;
  • new namespace System.Collections.Concurrent with ParallelFx collections: Queue, Stack, Dictionary and Partitioner;
  • new classes Tuple<T,..Tn> used by F# but that we can use for fast values storage.

In sum, there are so many new features to study :-)

Search

Go

This Blog

Sponsors





Syndication