Oscilloscope using RX and C# Async CTP

In my last blog post I described the implementation of a simple ‘oscilloscope app’ in F#, as I wanted to see how the code would be structured using only F# idioms (http://taumuon-jabuka.blogspot.com/2012/01/visualising-sound.html )

My natural instinct would have been to implement it using the Reactive Extensions for .NET (RX Framework), but I first wanted to investigate a pure F# solution. This post describes an alternate RX implementation.

Similar to my last post, I’ll describe the code inside-out.

Creating the Observable

/blog/2012-01-18-oscilloscope-using-rx-and-c-async-ctp/images/clip_image00325255B525255D.png
clip_image002
/blog/2012-01-18-oscilloscope-using-rx-and-c-async-ctp/images/clip_image00425255B625255D.png
clip_image003
/blog/2012-01-18-oscilloscope-using-rx-and-c-async-ctp/images/clip_image00525255B525255D.png
clip_image004
/blog/2012-01-18-oscilloscope-using-rx-and-c-async-ctp/images/clip_image00625255B525255D.png
clip_image005
/blog/2012-01-18-oscilloscope-using-rx-and-c-async-ctp/images/clip_image00725255B625255D.png
clip_image006
/blog/2012-01-18-oscilloscope-using-rx-and-c-async-ctp/images/clip_image00825255B525255D.png
clip_image007
/blog/2012-01-18-oscilloscope-using-rx-and-c-async-ctp/images/clip_image00925255B625255D.png
clip_image008
http://www.taumuon.co.uk/wp-content/uploads/2012/01/clip_image009_thumb25255B325255D.png?imgmax=800
clip_image009

Comparing implementations

For me, the RX solution is cleaner than the F# solution, and easier to follow. I did implement my F# solution in quite an imperative way though, and should have perhaps used AsyncSeq or mailbox processors, but as reading from the microphone is a push-based activity, none of those solutions would be as clean as RX (of course I haven’t covered using RX in F#). The F# version is much faster, and I’ll take a big more of a dig into performance in an upcoming blog post.